signal-desktop/ts/sql/migrations/77-signal-tokenizer.ts

45 lines
1,010 B
TypeScript
Raw Normal View History

2023-01-26 23:53:22 +00:00
// Copyright 2023 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import type { Database } from '@signalapp/better-sqlite3';
import type { LoggerType } from '../../types/Logging';
2023-01-30 19:55:38 +00:00
export default function updateToSchemaVersion77(
2023-01-26 23:53:22 +00:00
currentVersion: number,
db: Database,
logger: LoggerType
): void {
2023-01-30 19:55:38 +00:00
if (currentVersion >= 77) {
2023-01-26 23:53:22 +00:00
return;
}
db.transaction(() => {
db.exec(
`
-- Create FTS table with custom tokenizer from
-- @signalapp/better-sqlite3.
DROP TABLE messages_fts;
CREATE VIRTUAL TABLE messages_fts USING fts5(
body,
tokenize = 'signal_tokenizer'
);
-- Reindex messages
-- Based on messages_on_insert trigger from migrations/45-stories.ts
INSERT INTO messages_fts (rowid, body)
SELECT rowid, body
FROM messages
WHERE isViewOnce IS NOT 1 AND storyId IS NULL;
`
);
2023-01-30 19:55:38 +00:00
db.pragma('user_version = 77');
2023-01-26 23:53:22 +00:00
})();
2023-01-30 19:55:38 +00:00
logger.info('updateToSchemaVersion77: success!');
2023-01-26 23:53:22 +00:00
}