Simplify database migrations
This commit is contained in:
parent
46d5b06bfc
commit
e6809c95db
106 changed files with 4661 additions and 6814 deletions
|
@ -3,54 +3,36 @@
|
|||
|
||||
import type { Database } from '@signalapp/sqlcipher';
|
||||
|
||||
import type { LoggerType } from '../../types/Logging';
|
||||
|
||||
export const version = 1060;
|
||||
|
||||
export function updateToSchemaVersion1060(
|
||||
currentVersion: number,
|
||||
db: Database,
|
||||
logger: LoggerType
|
||||
): void {
|
||||
if (currentVersion >= 1060) {
|
||||
return;
|
||||
}
|
||||
|
||||
db.transaction(() => {
|
||||
db.exec(`
|
||||
ALTER TABLE messages
|
||||
ADD COLUMN isAddressableMessage INTEGER
|
||||
GENERATED ALWAYS AS (
|
||||
type IS NULL
|
||||
OR
|
||||
type IN (
|
||||
'incoming',
|
||||
'outgoing'
|
||||
)
|
||||
);
|
||||
|
||||
CREATE INDEX messages_by_date_addressable
|
||||
ON messages (
|
||||
conversationId, isAddressableMessage, received_at, sent_at
|
||||
export default function updateToSchemaVersion1060(db: Database): void {
|
||||
db.exec(`
|
||||
ALTER TABLE messages
|
||||
ADD COLUMN isAddressableMessage INTEGER
|
||||
GENERATED ALWAYS AS (
|
||||
type IS NULL
|
||||
OR
|
||||
type IN (
|
||||
'incoming',
|
||||
'outgoing'
|
||||
)
|
||||
);
|
||||
|
||||
CREATE TABLE syncTasks(
|
||||
id TEXT PRIMARY KEY NOT NULL,
|
||||
attempts INTEGER NOT NULL,
|
||||
createdAt INTEGER NOT NULL,
|
||||
data TEXT NOT NULL,
|
||||
envelopeId TEXT NOT NULL,
|
||||
sentAt INTEGER NOT NULL,
|
||||
type TEXT NOT NULL
|
||||
) STRICT;
|
||||
CREATE INDEX messages_by_date_addressable
|
||||
ON messages (
|
||||
conversationId, isAddressableMessage, received_at, sent_at
|
||||
);
|
||||
|
||||
CREATE INDEX syncTasks_order ON syncTasks (
|
||||
createdAt, sentAt, id
|
||||
)
|
||||
`);
|
||||
CREATE TABLE syncTasks(
|
||||
id TEXT PRIMARY KEY NOT NULL,
|
||||
attempts INTEGER NOT NULL,
|
||||
createdAt INTEGER NOT NULL,
|
||||
data TEXT NOT NULL,
|
||||
envelopeId TEXT NOT NULL,
|
||||
sentAt INTEGER NOT NULL,
|
||||
type TEXT NOT NULL
|
||||
) STRICT;
|
||||
|
||||
db.pragma('user_version = 1060');
|
||||
})();
|
||||
|
||||
logger.info('updateToSchemaVersion1060: success!');
|
||||
CREATE INDEX syncTasks_order ON syncTasks (
|
||||
createdAt, sentAt, id
|
||||
)
|
||||
`);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue