Simplify database migrations

This commit is contained in:
Fedor Indutny 2025-08-06 10:32:08 -07:00 committed by GitHub
commit e6809c95db
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
106 changed files with 4661 additions and 6814 deletions

View file

@ -3,36 +3,20 @@
import type { Database } from '@signalapp/sqlcipher';
import type { LoggerType } from '../../types/Logging';
export default function updateToSchemaVersion64(db: Database): void {
db.exec(
`
ALTER TABLE preKeys
ADD COLUMN ourUuid STRING
GENERATED ALWAYS AS (json_extract(json, '$.ourUuid'));
export default function updateToSchemaVersion64(
currentVersion: number,
db: Database,
logger: LoggerType
): void {
if (currentVersion >= 64) {
return;
}
CREATE INDEX preKeys_ourUuid ON preKeys (ourUuid);
db.transaction(() => {
db.exec(
`
ALTER TABLE preKeys
ADD COLUMN ourUuid STRING
GENERATED ALWAYS AS (json_extract(json, '$.ourUuid'));
ALTER TABLE signedPreKeys
ADD COLUMN ourUuid STRING
GENERATED ALWAYS AS (json_extract(json, '$.ourUuid'));
CREATE INDEX preKeys_ourUuid ON preKeys (ourUuid);
ALTER TABLE signedPreKeys
ADD COLUMN ourUuid STRING
GENERATED ALWAYS AS (json_extract(json, '$.ourUuid'));
CREATE INDEX signedPreKeys_ourUuid ON signedPreKeys (ourUuid);
`
);
db.pragma('user_version = 64');
})();
logger.info('updateToSchemaVersion64: success!');
CREATE INDEX signedPreKeys_ourUuid ON signedPreKeys (ourUuid);
`
);
}