Simplify database migrations
This commit is contained in:
parent
46d5b06bfc
commit
e6809c95db
106 changed files with 4661 additions and 6814 deletions
|
|
@ -3,40 +3,24 @@
|
|||
|
||||
import type { Database } from '@signalapp/sqlcipher';
|
||||
|
||||
import type { LoggerType } from '../../types/Logging';
|
||||
export default function updateToSchemaVersion85(db: Database): void {
|
||||
db.exec(
|
||||
`CREATE TABLE kyberPreKeys(
|
||||
id STRING PRIMARY KEY NOT NULL,
|
||||
json TEXT NOT NULL,
|
||||
ourUuid STRING
|
||||
GENERATED ALWAYS AS (json_extract(json, '$.ourUuid'))
|
||||
);`
|
||||
);
|
||||
|
||||
export default function updateToSchemaVersion85(
|
||||
currentVersion: number,
|
||||
db: Database,
|
||||
logger: LoggerType
|
||||
): void {
|
||||
if (currentVersion >= 85) {
|
||||
return;
|
||||
}
|
||||
// To manage our ACI or PNI keys quickly
|
||||
db.exec('CREATE INDEX kyberPreKeys_ourUuid ON kyberPreKeys (ourUuid);');
|
||||
|
||||
db.transaction(() => {
|
||||
db.exec(
|
||||
`CREATE TABLE kyberPreKeys(
|
||||
id STRING PRIMARY KEY NOT NULL,
|
||||
json TEXT NOT NULL,
|
||||
ourUuid STRING
|
||||
GENERATED ALWAYS AS (json_extract(json, '$.ourUuid'))
|
||||
);`
|
||||
);
|
||||
|
||||
// To manage our ACI or PNI keys quickly
|
||||
db.exec('CREATE INDEX kyberPreKeys_ourUuid ON kyberPreKeys (ourUuid);');
|
||||
|
||||
// Add time to all existing preKeys to allow us to expire them
|
||||
const now = Date.now();
|
||||
db.exec(
|
||||
`UPDATE preKeys SET
|
||||
json = json_set(json, '$.createdAt', ${now});
|
||||
`
|
||||
);
|
||||
|
||||
db.pragma('user_version = 85');
|
||||
})();
|
||||
|
||||
logger.info('updateToSchemaVersion85: success!');
|
||||
// Add time to all existing preKeys to allow us to expire them
|
||||
const now = Date.now();
|
||||
db.exec(
|
||||
`UPDATE preKeys SET
|
||||
json = json_set(json, '$.createdAt', ${now});
|
||||
`
|
||||
);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue