Simplify database migrations
This commit is contained in:
parent
46d5b06bfc
commit
e6809c95db
106 changed files with 4661 additions and 6814 deletions
|
@ -3,57 +3,41 @@
|
|||
|
||||
import type { Database } from '@signalapp/sqlcipher';
|
||||
|
||||
import type { LoggerType } from '../../types/Logging';
|
||||
export default function updateToSchemaVersion76(db: Database): void {
|
||||
db.exec(
|
||||
`
|
||||
-- Re-created below
|
||||
DROP INDEX IF EXISTS message_expires_at;
|
||||
DROP INDEX IF EXISTS messages_preview;
|
||||
|
||||
export default function updateToSchemaVersion76(
|
||||
currentVersion: number,
|
||||
db: Database,
|
||||
logger: LoggerType
|
||||
): void {
|
||||
if (currentVersion >= 76) {
|
||||
return;
|
||||
}
|
||||
-- Create non-null expiresAt column
|
||||
ALTER TABLE messages
|
||||
DROP COLUMN expiresAt;
|
||||
|
||||
db.transaction(() => {
|
||||
db.exec(
|
||||
`
|
||||
-- Re-created below
|
||||
DROP INDEX IF EXISTS message_expires_at;
|
||||
DROP INDEX IF EXISTS messages_preview;
|
||||
ALTER TABLE messages
|
||||
ADD COLUMN
|
||||
expiresAt INT
|
||||
GENERATED ALWAYS
|
||||
AS (ifnull(
|
||||
expirationStartTimestamp + (expireTimer * 1000),
|
||||
${Number.MAX_SAFE_INTEGER}
|
||||
));
|
||||
|
||||
-- Create non-null expiresAt column
|
||||
ALTER TABLE messages
|
||||
DROP COLUMN expiresAt;
|
||||
|
||||
ALTER TABLE messages
|
||||
ADD COLUMN
|
||||
expiresAt INT
|
||||
GENERATED ALWAYS
|
||||
AS (ifnull(
|
||||
expirationStartTimestamp + (expireTimer * 1000),
|
||||
${Number.MAX_SAFE_INTEGER}
|
||||
));
|
||||
|
||||
-- Re-create indexes
|
||||
-- Note the "s" at the end of "messages"
|
||||
CREATE INDEX messages_expires_at ON messages (
|
||||
expiresAt
|
||||
);
|
||||
|
||||
-- Note that expiresAt is intentionally dropped from the index since
|
||||
-- expiresAt > $now is likely to be true so we just try selecting it
|
||||
-- *after* ordering by received_at/sent_at.
|
||||
CREATE INDEX messages_preview ON messages
|
||||
(conversationId, shouldAffectPreview, isGroupLeaveEventFromOther,
|
||||
received_at, sent_at);
|
||||
CREATE INDEX messages_preview_without_story ON messages
|
||||
(conversationId, shouldAffectPreview, isGroupLeaveEventFromOther,
|
||||
received_at, sent_at) WHERE storyId IS NULL;
|
||||
`
|
||||
-- Re-create indexes
|
||||
-- Note the "s" at the end of "messages"
|
||||
CREATE INDEX messages_expires_at ON messages (
|
||||
expiresAt
|
||||
);
|
||||
|
||||
db.pragma('user_version = 76');
|
||||
})();
|
||||
|
||||
logger.info('updateToSchemaVersion76: success!');
|
||||
-- Note that expiresAt is intentionally dropped from the index since
|
||||
-- expiresAt > $now is likely to be true so we just try selecting it
|
||||
-- *after* ordering by received_at/sent_at.
|
||||
CREATE INDEX messages_preview ON messages
|
||||
(conversationId, shouldAffectPreview, isGroupLeaveEventFromOther,
|
||||
received_at, sent_at);
|
||||
CREATE INDEX messages_preview_without_story ON messages
|
||||
(conversationId, shouldAffectPreview, isGroupLeaveEventFromOther,
|
||||
received_at, sent_at) WHERE storyId IS NULL;
|
||||
`
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue