From 20ea528ffeb504c8e4ee09edd65f78313df66804 Mon Sep 17 00:00:00 2001 From: Sumner Evans Date: Mon, 30 Oct 2023 14:44:12 -0600 Subject: [PATCH] db: fix startup with clean db Closes #16 Signed-off-by: Sumner Evans --- database/v02_migrate_to_mautrix_store.sql | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/database/v02_migrate_to_mautrix_store.sql b/database/v02_migrate_to_mautrix_store.sql index cd8f6a9..2b6cc59 100644 --- a/database/v02_migrate_to_mautrix_store.sql +++ b/database/v02_migrate_to_mautrix_store.sql @@ -33,16 +33,39 @@ INSERT INTO mx_version (version) VALUES (4); -- Migrate the existing data to the new crypto store DROP TABLE user_filter_ids; +CREATE TABLE IF NOT EXISTS crypto_account ( + account_id TEXT PRIMARY KEY, + device_id TEXT NOT NULL, + shared BOOLEAN NOT NULL, + sync_token TEXT NOT NULL, + account bytea NOT NULL +); + UPDATE crypto_account SET sync_token = ( SELECT next_batch_token FROM user_batch_tokens ); DROP TABLE user_batch_tokens; +CREATE TABLE IF NOT EXISTS mx_room_state ( + room_id TEXT PRIMARY KEY, + power_levels jsonb, + encryption jsonb +); + INSERT INTO mx_room_state (room_id, encryption) SELECT room_id, encryption_event::jsonb FROM rooms; +CREATE TABLE IF NOT EXISTS mx_user_profile ( + room_id TEXT, + user_id TEXT, + membership membership NOT NULL, + displayname TEXT NOT NULL DEFAULT '', + avatar_url TEXT NOT NULL DEFAULT '', + PRIMARY KEY (room_id, user_id) +); + INSERT INTO mx_user_profile (room_id, user_id, membership) SELECT room_id, user_id, 'join' FROM room_members;