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;