-- v0 -> v8 (compatible with v1+): Xessenger history move (QA-289) -- One row per old room a move took on: where it went, how far it got and what it wrote. Counts, -- IDs and hashes only; nothing here is message content. CREATE TABLE xessenger_migrate_room ( bridge_id TEXT NOT NULL, old_room_id TEXT NOT NULL, -- '' until the new room exists. new_room_id TEXT NOT NULL DEFAULT '', user_mxid TEXT NOT NULL, -- 'portal' (a room of the bridge's) or 'xessenger' (two Xessenger users' room, in the mail bridge). kind TEXT NOT NULL, portal_id TEXT NOT NULL DEFAULT '', portal_receiver TEXT NOT NULL DEFAULT '', -- JSON array of the other Xessenger identities put into the new room. members TEXT NOT NULL DEFAULT '[]', -- The ghosts in the new room when it was made, sealed: the others leave once their history is in. sealed_present TEXT NOT NULL DEFAULT '', -- moving, moved, running, done, failed state TEXT NOT NULL, error TEXT NOT NULL DEFAULT '', -- The seq being written when the bridge stopped: it may have reached the room. attempt_seq BIGINT NOT NULL DEFAULT 0, total BIGINT NOT NULL DEFAULT 0, source_messages BIGINT NOT NULL DEFAULT 0, source_reactions BIGINT NOT NULL DEFAULT 0, source_files BIGINT NOT NULL DEFAULT 0, undigestable BIGINT NOT NULL DEFAULT 0, missing_files BIGINT NOT NULL DEFAULT 0, events BIGINT NOT NULL DEFAULT 0, files BIGINT NOT NULL DEFAULT 0, digest TEXT NOT NULL DEFAULT '', last_event_id TEXT NOT NULL DEFAULT '', -- Whether no written event points at the body of a mail sent from the app (mail.json) left in the -- old room: worked out from the events' marks when the move finishes. mail_compose BOOLEAN NOT NULL DEFAULT false, -- The room's digest key, sealed: every marker of the room carries it, and the digest is keyed with -- it. '' until the history is first written. sealed_key TEXT NOT NULL DEFAULT '', -- Whether the portal's name was looked at since its move (fillMovedNames): a group without one gets -- its old room's name once. Not one of the columns a run writes (roomColumns). name_checked BOOLEAN NOT NULL DEFAULT false, created_at BIGINT NOT NULL, updated_at BIGINT NOT NULL, PRIMARY KEY (bridge_id, old_room_id) ); -- Each written event: what it was moved from, the event it became and its content hash, sealed (a -- hash of a short message gives the message away). CREATE TABLE xessenger_migrate_event ( bridge_id TEXT NOT NULL, old_room_id TEXT NOT NULL, seq BIGINT NOT NULL, old_event_id TEXT NOT NULL, new_event_id TEXT NOT NULL, old_ts BIGINT NOT NULL, sealed_hash TEXT NOT NULL, -- JSON array of the encrypted files' mxc URIs in the written content. file_urls TEXT NOT NULL DEFAULT '[]', -- Whether the written event points at no mail body left in the old room: set by a move that copies -- those bodies (copyCompose), false for an event an older bridge recorded. mail_compose BOOLEAN NOT NULL DEFAULT false, -- Whether the written event was deleted in the new room since, as the homeserver showed when the API -- named it (handleRedacted): the app cannot read it any more, and it is left out of what the app -- checks the move against. redacted BOOLEAN NOT NULL DEFAULT false, PRIMARY KEY (bridge_id, old_room_id, seq) ); CREATE INDEX xessenger_migrate_event_old ON xessenger_migrate_event (bridge_id, old_room_id, old_event_id); -- Each file copied into the new room, once per old file: its encrypted copy and the copy's keys, -- sealed. new_mxc is '' when the old file was gone. CREATE TABLE xessenger_migrate_media ( bridge_id TEXT NOT NULL, old_room_id TEXT NOT NULL, old_mxc TEXT NOT NULL, new_mxc TEXT NOT NULL, -- Hex SHA-256 of the uploaded ciphertext, which the API checks against the server's copy. sha256 TEXT NOT NULL DEFAULT '', sealed_file TEXT NOT NULL DEFAULT '', -- JSON array of the copies this copy lists inside it: a mail body's (mail.json) attachments. listed TEXT NOT NULL DEFAULT '[]', PRIMARY KEY (bridge_id, old_room_id, old_mxc) ); -- The copies a history wrote before its room's user was in the new room, deleted once it is written -- again: until then they name the files the history written again shows too. CREATE TABLE xessenger_migrate_stale ( bridge_id TEXT NOT NULL, old_room_id TEXT NOT NULL, new_event_id TEXT NOT NULL, old_event_id TEXT NOT NULL, -- Whether the copy was deleted in the new room before the history was set to be written again: the -- message it moved was taken back, and its copy written again goes too. deleted BOOLEAN NOT NULL DEFAULT false, PRIMARY KEY (bridge_id, old_room_id, new_event_id) );