mirror of
https://github.com/signalapp/Signal-Desktop.git
synced 2026-05-03 06:41:19 +01:00
Simplify database migrations
This commit is contained in:
@@ -1,38 +1,21 @@
|
||||
// Copyright 2025 Signal Messenger, LLC
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
import type { LoggerType } from '../../types/Logging';
|
||||
import { sql } from '../util';
|
||||
import type { WritableDB } from '../Interface';
|
||||
|
||||
export const version = 1320;
|
||||
export default function updateToSchemaVersion1320(db: WritableDB): void {
|
||||
const [query] = sql`
|
||||
DROP INDEX unprocessed_timestamp;
|
||||
|
||||
export function updateToSchemaVersion1320(
|
||||
currentVersion: number,
|
||||
db: WritableDB,
|
||||
logger: LoggerType
|
||||
): void {
|
||||
if (currentVersion >= 1320) {
|
||||
return;
|
||||
}
|
||||
ALTER TABLE unprocessed
|
||||
ADD COLUMN receivedAtDate INTEGER DEFAULT 0 NOT NULL;
|
||||
|
||||
db.transaction(() => {
|
||||
const [query] = sql`
|
||||
DROP INDEX unprocessed_timestamp;
|
||||
UPDATE unprocessed
|
||||
SET receivedAtDate = timestamp;
|
||||
|
||||
ALTER TABLE unprocessed
|
||||
ADD COLUMN receivedAtDate INTEGER DEFAULT 0 NOT NULL;
|
||||
|
||||
UPDATE unprocessed
|
||||
SET receivedAtDate = timestamp;
|
||||
|
||||
CREATE INDEX unprocessed_byReceivedAtDate ON unprocessed
|
||||
(receivedAtDate);
|
||||
`;
|
||||
db.exec(query);
|
||||
|
||||
db.pragma('user_version = 1320');
|
||||
})();
|
||||
|
||||
logger.info('updateToSchemaVersion1320: success!');
|
||||
CREATE INDEX unprocessed_byReceivedAtDate ON unprocessed
|
||||
(receivedAtDate);
|
||||
`;
|
||||
db.exec(query);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user