2022-06-28 15:22:10 +02:00
|
|
|
-- v0 -> v51: Latest revision
|
2022-05-22 00:06:30 +02:00
|
|
|
|
|
|
|
CREATE TABLE "user" (
|
|
|
|
mxid TEXT PRIMARY KEY,
|
|
|
|
username TEXT UNIQUE,
|
2022-05-23 19:00:08 +02:00
|
|
|
agent SMALLINT,
|
|
|
|
device SMALLINT,
|
2022-05-22 00:06:30 +02:00
|
|
|
|
|
|
|
management_room TEXT,
|
|
|
|
space_room TEXT,
|
|
|
|
|
|
|
|
phone_last_seen BIGINT,
|
|
|
|
phone_last_pinged BIGINT,
|
|
|
|
|
|
|
|
timezone TEXT
|
|
|
|
);
|
|
|
|
|
|
|
|
CREATE TABLE portal (
|
|
|
|
jid TEXT,
|
|
|
|
receiver TEXT,
|
|
|
|
mxid TEXT UNIQUE,
|
2022-06-28 13:37:49 +02:00
|
|
|
name TEXT NOT NULL,
|
|
|
|
name_set BOOLEAN NOT NULL DEFAULT false,
|
|
|
|
topic TEXT NOT NULL,
|
|
|
|
topic_set BOOLEAN NOT NULL DEFAULT false,
|
|
|
|
avatar TEXT NOT NULL,
|
2022-05-22 00:06:30 +02:00
|
|
|
avatar_url TEXT,
|
2022-06-28 13:37:49 +02:00
|
|
|
avatar_set BOOLEAN NOT NULL DEFAULT false,
|
2022-05-22 00:06:30 +02:00
|
|
|
encrypted BOOLEAN NOT NULL DEFAULT false,
|
2022-06-28 15:22:10 +02:00
|
|
|
last_sync BIGINT NOT NULL DEFAULT 0,
|
2022-05-22 00:06:30 +02:00
|
|
|
|
|
|
|
first_event_id TEXT,
|
|
|
|
next_batch_id TEXT,
|
|
|
|
relay_user_id TEXT,
|
2022-05-26 10:23:15 +02:00
|
|
|
expiration_time BIGINT NOT NULL DEFAULT 0 CHECK (expiration_time >= 0 AND expiration_time < 4294967296),
|
2022-05-22 00:06:30 +02:00
|
|
|
|
2022-05-23 19:00:08 +02:00
|
|
|
PRIMARY KEY (jid, receiver)
|
2022-05-22 00:06:30 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
CREATE TABLE puppet (
|
|
|
|
username TEXT PRIMARY KEY,
|
|
|
|
displayname TEXT,
|
2022-05-23 19:00:08 +02:00
|
|
|
name_quality SMALLINT,
|
|
|
|
avatar TEXT,
|
|
|
|
avatar_url TEXT,
|
2022-06-28 13:37:49 +02:00
|
|
|
name_set BOOLEAN NOT NULL DEFAULT false,
|
|
|
|
avatar_set BOOLEAN NOT NULL DEFAULT false,
|
|
|
|
last_sync BIGINT NOT NULL DEFAULT 0,
|
2022-05-22 00:06:30 +02:00
|
|
|
|
|
|
|
custom_mxid TEXT,
|
|
|
|
access_token TEXT,
|
|
|
|
next_batch TEXT,
|
|
|
|
|
2022-05-23 19:00:08 +02:00
|
|
|
enable_presence BOOLEAN NOT NULL DEFAULT true,
|
|
|
|
enable_receipts BOOLEAN NOT NULL DEFAULT true
|
2022-05-22 00:06:30 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
-- only: postgres
|
|
|
|
CREATE TYPE error_type AS ENUM ('', 'decryption_failed', 'media_not_found');
|
|
|
|
|
|
|
|
CREATE TABLE message (
|
|
|
|
chat_jid TEXT,
|
|
|
|
chat_receiver TEXT,
|
|
|
|
jid TEXT,
|
|
|
|
mxid TEXT UNIQUE,
|
|
|
|
sender TEXT,
|
|
|
|
timestamp BIGINT,
|
|
|
|
sent BOOLEAN,
|
2022-05-23 19:00:08 +02:00
|
|
|
error error_type,
|
|
|
|
type TEXT,
|
2022-05-22 00:06:30 +02:00
|
|
|
|
|
|
|
broadcast_list_jid TEXT,
|
|
|
|
|
2022-05-23 19:00:08 +02:00
|
|
|
PRIMARY KEY (chat_jid, chat_receiver, jid),
|
|
|
|
FOREIGN KEY (chat_jid, chat_receiver) REFERENCES portal(jid, receiver) ON DELETE CASCADE
|
2022-05-22 00:06:30 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
CREATE TABLE reaction (
|
2022-05-23 19:00:08 +02:00
|
|
|
chat_jid TEXT,
|
|
|
|
chat_receiver TEXT,
|
|
|
|
target_jid TEXT,
|
|
|
|
sender TEXT,
|
2022-05-22 00:06:30 +02:00
|
|
|
|
2022-05-23 19:00:08 +02:00
|
|
|
mxid TEXT NOT NULL,
|
|
|
|
jid TEXT NOT NULL,
|
2022-05-22 00:06:30 +02:00
|
|
|
|
2022-05-23 19:00:08 +02:00
|
|
|
PRIMARY KEY (chat_jid, chat_receiver, target_jid, sender),
|
|
|
|
FOREIGN KEY (chat_jid, chat_receiver, target_jid) REFERENCES message(chat_jid, chat_receiver, jid)
|
|
|
|
ON DELETE CASCADE ON UPDATE CASCADE
|
2022-05-22 00:06:30 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
CREATE TABLE disappearing_message (
|
2022-05-23 19:00:08 +02:00
|
|
|
room_id TEXT,
|
|
|
|
event_id TEXT,
|
|
|
|
expire_in BIGINT NOT NULL,
|
|
|
|
expire_at BIGINT,
|
|
|
|
PRIMARY KEY (room_id, event_id)
|
2022-05-22 00:06:30 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
CREATE TABLE user_portal (
|
|
|
|
user_mxid TEXT,
|
|
|
|
portal_jid TEXT,
|
|
|
|
portal_receiver TEXT,
|
|
|
|
last_read_ts BIGINT NOT NULL DEFAULT 0,
|
|
|
|
in_space BOOLEAN NOT NULL DEFAULT false,
|
|
|
|
PRIMARY KEY (user_mxid, portal_jid, portal_receiver),
|
|
|
|
FOREIGN KEY (user_mxid) REFERENCES "user"(mxid) ON UPDATE CASCADE ON DELETE CASCADE,
|
|
|
|
FOREIGN KEY (portal_jid, portal_receiver) REFERENCES portal(jid, receiver) ON UPDATE CASCADE ON DELETE CASCADE
|
|
|
|
);
|
|
|
|
|
|
|
|
CREATE TABLE backfill_queue (
|
2022-05-23 19:00:08 +02:00
|
|
|
queue_id INTEGER PRIMARY KEY
|
|
|
|
-- only: postgres
|
|
|
|
GENERATED ALWAYS AS IDENTITY
|
|
|
|
,
|
|
|
|
user_mxid TEXT,
|
|
|
|
type INTEGER NOT NULL,
|
|
|
|
priority INTEGER NOT NULL,
|
|
|
|
portal_jid TEXT,
|
|
|
|
portal_receiver TEXT,
|
|
|
|
time_start TIMESTAMP,
|
|
|
|
dispatch_time TIMESTAMP,
|
|
|
|
completed_at TIMESTAMP,
|
|
|
|
batch_delay INTEGER,
|
|
|
|
max_batch_events INTEGER NOT NULL,
|
|
|
|
max_total_events INTEGER,
|
|
|
|
|
2022-05-26 10:23:15 +02:00
|
|
|
FOREIGN KEY (user_mxid) REFERENCES "user" (mxid) ON DELETE CASCADE ON UPDATE CASCADE,
|
|
|
|
FOREIGN KEY (portal_jid, portal_receiver) REFERENCES portal(jid, receiver) ON DELETE CASCADE
|
2022-05-22 00:06:30 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
CREATE TABLE backfill_state (
|
2022-05-23 19:00:08 +02:00
|
|
|
user_mxid TEXT,
|
|
|
|
portal_jid TEXT,
|
|
|
|
portal_receiver TEXT,
|
|
|
|
processing_batch BOOLEAN,
|
|
|
|
backfill_complete BOOLEAN,
|
2022-05-25 22:48:38 +02:00
|
|
|
first_expected_ts BIGINT,
|
2022-05-23 19:00:08 +02:00
|
|
|
PRIMARY KEY (user_mxid, portal_jid, portal_receiver),
|
|
|
|
FOREIGN KEY (user_mxid) REFERENCES "user" (mxid) ON DELETE CASCADE ON UPDATE CASCADE,
|
|
|
|
FOREIGN KEY (portal_jid, portal_receiver) REFERENCES portal (jid, receiver) ON DELETE CASCADE
|
2022-05-22 00:06:30 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
CREATE TABLE media_backfill_requests (
|
2022-05-23 19:00:08 +02:00
|
|
|
user_mxid TEXT,
|
|
|
|
portal_jid TEXT,
|
|
|
|
portal_receiver TEXT,
|
|
|
|
event_id TEXT,
|
|
|
|
media_key bytea,
|
|
|
|
status INTEGER,
|
|
|
|
error TEXT,
|
|
|
|
PRIMARY KEY (user_mxid, portal_jid, portal_receiver, event_id),
|
|
|
|
FOREIGN KEY (user_mxid) REFERENCES "user"(mxid) ON UPDATE CASCADE ON DELETE CASCADE,
|
|
|
|
FOREIGN KEY (portal_jid, portal_receiver) REFERENCES portal(jid, receiver) ON UPDATE CASCADE ON DELETE CASCADE
|
2022-05-22 00:06:30 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
CREATE TABLE history_sync_conversation (
|
2022-05-23 19:00:08 +02:00
|
|
|
user_mxid TEXT,
|
|
|
|
conversation_id TEXT,
|
|
|
|
portal_jid TEXT,
|
|
|
|
portal_receiver TEXT,
|
|
|
|
|
|
|
|
last_message_timestamp TIMESTAMP,
|
|
|
|
archived BOOLEAN,
|
|
|
|
pinned INTEGER,
|
|
|
|
mute_end_time TIMESTAMP,
|
|
|
|
disappearing_mode INTEGER,
|
|
|
|
end_of_history_transfer_type INTEGER,
|
|
|
|
ephemeral_Expiration INTEGER,
|
|
|
|
marked_as_unread BOOLEAN,
|
|
|
|
unread_count INTEGER,
|
|
|
|
|
|
|
|
PRIMARY KEY (user_mxid, conversation_id),
|
|
|
|
FOREIGN KEY (user_mxid) REFERENCES "user"(mxid) ON UPDATE CASCADE ON DELETE CASCADE,
|
|
|
|
FOREIGN KEY (portal_jid, portal_receiver) REFERENCES portal(jid, receiver) ON UPDATE CASCADE ON DELETE CASCADE
|
2022-05-22 00:06:30 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
CREATE TABLE history_sync_message (
|
2022-05-23 19:00:08 +02:00
|
|
|
user_mxid TEXT,
|
|
|
|
conversation_id TEXT,
|
|
|
|
message_id TEXT,
|
|
|
|
timestamp TIMESTAMP,
|
|
|
|
data bytea,
|
|
|
|
inserted_time TIMESTAMP,
|
|
|
|
|
|
|
|
PRIMARY KEY (user_mxid, conversation_id, message_id),
|
|
|
|
FOREIGN KEY (user_mxid) REFERENCES "user"(mxid) ON UPDATE CASCADE ON DELETE CASCADE,
|
|
|
|
FOREIGN KEY (user_mxid, conversation_id) REFERENCES history_sync_conversation(user_mxid, conversation_id) ON DELETE CASCADE
|
2022-05-22 00:06:30 +02:00
|
|
|
);
|