Skip to content

Commit

Permalink
db: fix startup with clean db
Browse files Browse the repository at this point in the history
Closes #16

Signed-off-by: Sumner Evans <[email protected]>
  • Loading branch information
sumnerevans committed Oct 30, 2023
1 parent 8fde370 commit 20ea528
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions database/v02_migrate_to_mautrix_store.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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;

0 comments on commit 20ea528

Please sign in to comment.