Page MenuHomePhabricator

D4151.diff
No OneTemporary

D4151.diff

diff --git a/keyserver/src/database/migrations.js b/keyserver/src/database/migrations.js
--- a/keyserver/src/database/migrations.js
+++ b/keyserver/src/database/migrations.js
@@ -6,6 +6,7 @@
import { getMessageForException } from 'lib/utils/errors';
import { dbQuery, SQL } from './database';
+import { setupDB } from './setup-db';
async function makeSureBaseRoutePathExists(filePath: string): Promise<void> {
let readFile, json;
@@ -90,7 +91,7 @@
async function migrate(): Promise<boolean> {
let dbVersion = null;
try {
- dbVersion = await getDBVersion();
+ dbVersion = await setUpDBAndReturnVersion();
console.log(`(node:${process.pid}) DB version: ${dbVersion}`);
} catch (e) {
const dbVersionExceptionMessage = String(getMessageForException(e));
@@ -120,7 +121,19 @@
return true;
}
-async function getDBVersion(): Promise<number> {
+async function setUpDBAndReturnVersion(): Promise<number> {
+ try {
+ return await fetchDBVersion();
+ } catch (e) {
+ if (e.errno !== 1146) {
+ throw e;
+ }
+ await setupDB();
+ return await fetchDBVersion();
+ }
+}
+
+async function fetchDBVersion(): Promise<number> {
const versionQuery = SQL`
SELECT data
FROM metadata

File Metadata

Mime Type
text/plain
Expires
Sat, Dec 21, 1:11 AM (18 h, 18 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2684404
Default Alt Text
D4151.diff (1 KB)

Event Timeline