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

@ -1,36 +1,20 @@
// Copyright 2024 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import type { Database } from '@signalapp/sqlcipher';
import type { LoggerType } from '../../types/Logging';
import { sql, sqlConstant } from '../util';
import { CallDirection, CallStatusValue } from '../../types/CallDisposition';
export const version = 1160;
const CALL_STATUS_MISSED = sqlConstant(CallStatusValue.Missed);
const CALL_DIRECTION_INCOMING = sqlConstant(CallDirection.Incoming);
export function updateToSchemaVersion1160(
currentVersion: number,
db: Database,
logger: LoggerType
): void {
if (currentVersion >= 1160) {
return;
}
export default function updateToSchemaVersion1160(db: Database): void {
const [query] = sql`
DROP INDEX IF EXISTS callsHistory_incoming_missed;
db.transaction(() => {
const [query] = sql`
DROP INDEX IF EXISTS callsHistory_incoming_missed;
CREATE INDEX callsHistory_incoming_missed
ON callsHistory (callId, status, direction)
WHERE status IS ${CALL_STATUS_MISSED}
AND direction IS ${CALL_DIRECTION_INCOMING};
`;
db.exec(query);
db.pragma('user_version = 1160');
})();
logger.info('updateToSchemaVersion1160: success!');
CREATE INDEX callsHistory_incoming_missed
ON callsHistory (callId, status, direction)
WHERE status IS ${CALL_STATUS_MISSED}
AND direction IS ${CALL_DIRECTION_INCOMING};
`;
db.exec(query);
}