Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3492111
D4152.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
5 KB
Referenced Files
None
Subscribers
None
D4152.diff
View Options
diff --git a/keyserver/src/database/migration-config.js b/keyserver/src/database/migration-config.js
new file mode 100644
--- /dev/null
+++ b/keyserver/src/database/migration-config.js
@@ -0,0 +1,85 @@
+// @flow
+
+import fs from 'fs';
+
+const migrations: $ReadOnlyMap<number, () => Promise<void>> = new Map([
+ [
+ 0,
+ async () => {
+ await makeSureBaseRoutePathExists('facts/commapp_url.json');
+ await makeSureBaseRoutePathExists('facts/squadcal_url.json');
+ },
+ ],
+ [
+ 1,
+ async () => {
+ try {
+ await fs.promises.unlink('facts/url.json');
+ } catch {}
+ },
+ ],
+ [
+ 2,
+ async () => {
+ await fixBaseRoutePathForLocalhost('facts/commapp_url.json');
+ await fixBaseRoutePathForLocalhost('facts/squadcal_url.json');
+ },
+ ],
+]);
+
+async function makeSureBaseRoutePathExists(filePath: string): Promise<void> {
+ let readFile, json;
+ try {
+ readFile = await fs.promises.open(filePath, 'r');
+ const contents = await readFile.readFile('utf8');
+ json = JSON.parse(contents);
+ } catch {
+ return;
+ } finally {
+ if (readFile) {
+ await readFile.close();
+ }
+ }
+ if (json.baseRoutePath) {
+ return;
+ }
+ let baseRoutePath;
+ if (json.baseDomain === 'http://localhost') {
+ baseRoutePath = json.basePath;
+ } else if (filePath.endsWith('commapp_url.json')) {
+ baseRoutePath = '/commweb/';
+ } else {
+ baseRoutePath = '/';
+ }
+ const newJSON = { ...json, baseRoutePath };
+ console.warn(`updating ${filePath} to ${JSON.stringify(newJSON)}`);
+ const writeFile = await fs.promises.open(filePath, 'w');
+ await writeFile.writeFile(JSON.stringify(newJSON, null, ' '), 'utf8');
+ await writeFile.close();
+}
+
+async function fixBaseRoutePathForLocalhost(filePath: string): Promise<void> {
+ let readFile, json;
+ try {
+ readFile = await fs.promises.open(filePath, 'r');
+ const contents = await readFile.readFile('utf8');
+ json = JSON.parse(contents);
+ } catch {
+ return;
+ } finally {
+ if (readFile) {
+ await readFile.close();
+ }
+ }
+ if (json.baseDomain !== 'http://localhost') {
+ return;
+ }
+ const baseRoutePath = '/';
+ json = { ...json, baseRoutePath };
+ console.warn(`updating ${filePath} to ${JSON.stringify(json)}`);
+ const writeFile = await fs.promises.open(filePath, 'w');
+ await writeFile.writeFile(JSON.stringify(json, null, ' '), 'utf8');
+ await writeFile.close();
+}
+
+export { migrations };
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
@@ -1,93 +1,13 @@
// @flow
-import fs from 'fs';
import type { QueryResults } from 'mysql';
import { getMessageForException } from 'lib/utils/errors';
import { dbQuery, SQL } from './database';
+import { migrations } from './migration-config';
import { setupDB } from './setup-db';
-async function makeSureBaseRoutePathExists(filePath: string): Promise<void> {
- let readFile, json;
- try {
- readFile = await fs.promises.open(filePath, 'r');
- const contents = await readFile.readFile('utf8');
- json = JSON.parse(contents);
- } catch {
- return;
- } finally {
- if (readFile) {
- await readFile.close();
- }
- }
- if (json.baseRoutePath) {
- return;
- }
- let baseRoutePath;
- if (json.baseDomain === 'http://localhost') {
- baseRoutePath = json.basePath;
- } else if (filePath.endsWith('commapp_url.json')) {
- baseRoutePath = '/commweb/';
- } else {
- baseRoutePath = '/';
- }
- const newJSON = { ...json, baseRoutePath };
- console.warn(`updating ${filePath} to ${JSON.stringify(newJSON)}`);
- const writeFile = await fs.promises.open(filePath, 'w');
- await writeFile.writeFile(JSON.stringify(newJSON, null, ' '), 'utf8');
- await writeFile.close();
-}
-
-async function fixBaseRoutePathForLocalhost(filePath: string): Promise<void> {
- let readFile, json;
- try {
- readFile = await fs.promises.open(filePath, 'r');
- const contents = await readFile.readFile('utf8');
- json = JSON.parse(contents);
- } catch {
- return;
- } finally {
- if (readFile) {
- await readFile.close();
- }
- }
- if (json.baseDomain !== 'http://localhost') {
- return;
- }
- const baseRoutePath = '/';
- json = { ...json, baseRoutePath };
- console.warn(`updating ${filePath} to ${JSON.stringify(json)}`);
- const writeFile = await fs.promises.open(filePath, 'w');
- await writeFile.writeFile(JSON.stringify(json, null, ' '), 'utf8');
- await writeFile.close();
-}
-
-const migrations: $ReadOnlyMap<number, () => Promise<void>> = new Map([
- [
- 0,
- async () => {
- await makeSureBaseRoutePathExists('facts/commapp_url.json');
- await makeSureBaseRoutePathExists('facts/squadcal_url.json');
- },
- ],
- [
- 1,
- async () => {
- try {
- await fs.promises.unlink('facts/url.json');
- } catch {}
- },
- ],
- [
- 2,
- async () => {
- await fixBaseRoutePathForLocalhost('facts/commapp_url.json');
- await fixBaseRoutePathForLocalhost('facts/squadcal_url.json');
- },
- ],
-]);
-
async function migrate(): Promise<boolean> {
let dbVersion = null;
try {
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Thu, Dec 19, 10:14 PM (19 h, 33 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2679009
Default Alt Text
D4152.diff (5 KB)
Attached To
Mode
D4152: [keyserver] Extract migration config to separate file
Attached
Detach File
Event Timeline
Log In to Comment