Simplify database migrations
This commit is contained in:
parent
46d5b06bfc
commit
e6809c95db
106 changed files with 4661 additions and 6814 deletions
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue