From bdd548e0227bfe2a3d03268e6bd50b76714004a5 Mon Sep 17 00:00:00 2001 From: Sumner Evans Date: Wed, 3 Jul 2024 14:54:02 -0600 Subject: [PATCH] db: fix upgrades when creating from scratch Signed-off-by: Sumner Evans --- database/00-latest-revision.sql | 40 +++++++++++++++++++ ...itial_tables.sql => 01-initial-tables.sql} | 0 ...re.sql => 02-migrate-to-mautrix-store.sql} | 0 3 files changed, 40 insertions(+) create mode 100644 database/00-latest-revision.sql rename database/{v01_initial_tables.sql => 01-initial-tables.sql} (100%) rename database/{v02_migrate_to_mautrix_store.sql => 02-migrate-to-mautrix-store.sql} (100%) diff --git a/database/00-latest-revision.sql b/database/00-latest-revision.sql new file mode 100644 index 0000000..bb125be --- /dev/null +++ b/database/00-latest-revision.sql @@ -0,0 +1,40 @@ +-- v0 -> v2: Latest revision + +CREATE TABLE IF NOT EXISTS user_filter_ids ( + user_id VARCHAR(255) PRIMARY KEY, + filter_id VARCHAR(255) +); + +CREATE TABLE IF NOT EXISTS user_batch_tokens ( + user_id VARCHAR(255) PRIMARY KEY, + next_batch_token VARCHAR(255) +); + +CREATE TABLE IF NOT EXISTS rooms ( + room_id VARCHAR(255) PRIMARY KEY, + encryption_event VARCHAR(65535) NULL +); + +CREATE TABLE IF NOT EXISTS room_members ( + room_id VARCHAR(255), + user_id VARCHAR(255), + PRIMARY KEY (room_id, user_id) +); + +CREATE TABLE IF NOT EXISTS chatwoot_conversation_to_matrix_room ( + matrix_room_id VARCHAR(255) UNIQUE, + chatwoot_conversation_id INTEGER UNIQUE, + PRIMARY KEY (matrix_room_id, chatwoot_conversation_id) +); + +CREATE TABLE IF NOT EXISTS chatwoot_message_to_matrix_event ( + matrix_event_id VARCHAR(255) UNIQUE, + chatwoot_message_id INTEGER, + PRIMARY KEY (matrix_event_id, chatwoot_message_id) +); + +ALTER TABLE chatwoot_conversation_to_matrix_room +ADD COLUMN IF NOT EXISTS most_recent_event_id VARCHAR(255); + +ALTER TABLE chatwoot_message_to_matrix_event +DROP CONSTRAINT IF EXISTS chatwoot_message_to_matrix_event_matrix_event_id_key; diff --git a/database/v01_initial_tables.sql b/database/01-initial-tables.sql similarity index 100% rename from database/v01_initial_tables.sql rename to database/01-initial-tables.sql diff --git a/database/v02_migrate_to_mautrix_store.sql b/database/02-migrate-to-mautrix-store.sql similarity index 100% rename from database/v02_migrate_to_mautrix_store.sql rename to database/02-migrate-to-mautrix-store.sql