Changeset View
Changeset View
Standalone View
Standalone View
keyserver/src/database/migration-config.js
// @flow | // @flow | ||||
import fs from 'fs'; | import fs from 'fs'; | ||||
import { policyTypes } from 'lib/facts/policies.js'; | import { policyTypes } from 'lib/facts/policies.js'; | ||||
import { messageTypes } from 'lib/types/message-types-enum.js'; | import { messageTypes } from 'lib/types/message-types-enum.js'; | ||||
import { dbQuery, SQL } from '../database/database.js'; | import { dbQuery, SQL } from '../database/database.js'; | ||||
import { processMessagesInDBForSearch } from '../database/search-utils.js'; | import { processMessagesInDBForSearch } from '../database/search-utils.js'; | ||||
import { updateRolesAndPermissionsForAllThreads } from '../updaters/thread-permission-updaters.js'; | import { updateRolesAndPermissionsForAllThreads } from '../updaters/thread-permission-updaters.js'; | ||||
import { createPickledOlmAccount } from '../utils/olm-utils.js'; | |||||
const migrations: $ReadOnlyMap<number, () => Promise<void>> = new Map([ | const migrations: $ReadOnlyMap<number, () => Promise<void>> = new Map([ | ||||
[ | [ | ||||
0, | 0, | ||||
async () => { | async () => { | ||||
await makeSureBaseRoutePathExists('facts/commapp_url.json'); | await makeSureBaseRoutePathExists('facts/commapp_url.json'); | ||||
await makeSureBaseRoutePathExists('facts/squadcal_url.json'); | await makeSureBaseRoutePathExists('facts/squadcal_url.json'); | ||||
}, | }, | ||||
▲ Show 20 Lines • Show All 380 Lines • ▼ Show 20 Lines | async () => { | ||||
ALTER TABLE olm_accounts | ALTER TABLE olm_accounts | ||||
ADD PRIMARY KEY (is_content); | ADD PRIMARY KEY (is_content); | ||||
`, | `, | ||||
{ multipleStatements: true }, | { multipleStatements: true }, | ||||
); | ); | ||||
}, | }, | ||||
], | ], | ||||
[ | |||||
35, | |||||
async () => { | |||||
const [pickledContentAccount, pickledNotificationsAccount] = | |||||
await Promise.all([ | |||||
createPickledOlmAccount(), | |||||
createPickledOlmAccount(), | |||||
]); | |||||
await dbQuery( | |||||
SQL` | |||||
INSERT INTO olm_accounts (is_content, version, | |||||
pickling_key, pickled_olm_account) | |||||
VALUES | |||||
( | |||||
TRUE, | |||||
0, | |||||
${pickledContentAccount.picklingKey}, | |||||
${pickledContentAccount.pickledAccount} | |||||
), | |||||
( | |||||
FALSE, | |||||
0, | |||||
${pickledNotificationsAccount.picklingKey}, | |||||
${pickledNotificationsAccount.pickledAccount} | |||||
); | |||||
`, | |||||
); | |||||
}, | |||||
], | |||||
]); | ]); | ||||
const newDatabaseVersion: number = Math.max(...migrations.keys()); | const newDatabaseVersion: number = Math.max(...migrations.keys()); | ||||
async function writeJSONToFile(data: any, filePath: string): Promise<void> { | async function writeJSONToFile(data: any, filePath: string): Promise<void> { | ||||
console.warn(`updating ${filePath} to ${JSON.stringify(data)}`); | console.warn(`updating ${filePath} to ${JSON.stringify(data)}`); | ||||
const fileHandle = await fs.promises.open(filePath, 'w'); | const fileHandle = await fs.promises.open(filePath, 'w'); | ||||
await fileHandle.writeFile(JSON.stringify(data, null, ' '), 'utf8'); | await fileHandle.writeFile(JSON.stringify(data, null, ' '), 'utf8'); | ||||
await fileHandle.close(); | await fileHandle.close(); | ||||
▲ Show 20 Lines • Show All 89 Lines • Show Last 20 Lines |