b25c09fc53
* Move sessions to user_login metadata, as that data rarely changes after login. * Merge user and channel access hashes. Those IDs don't conflict. * Split usernames into a new table to allow better `ON CONFLICT` updates (when a username moves to another entity, we want the old row to be replaced). Usernames also don't need to be scoped to a login.
44 lines
1003 B
SQL
44 lines
1003 B
SQL
-- v0 -> v1: Latest revision
|
|
|
|
CREATE TABLE telegram_user_state (
|
|
user_id BIGINT NOT NULL PRIMARY KEY,
|
|
pts BIGINT NOT NULL,
|
|
qts BIGINT NOT NULL,
|
|
date BIGINT NOT NULL,
|
|
seq BIGINT NOT NULL
|
|
);
|
|
|
|
CREATE TABLE telegram_channel_state (
|
|
user_id BIGINT NOT NULL,
|
|
channel_id BIGINT NOT NULL,
|
|
pts BIGINT NOT NULL,
|
|
|
|
PRIMARY KEY (user_id, channel_id)
|
|
);
|
|
|
|
CREATE INDEX telegram_channel_state_user_id_idx ON telegram_channel_state (user_id);
|
|
|
|
CREATE TABLE telegram_access_hash (
|
|
user_id BIGINT NOT NULL,
|
|
entity_id BIGINT NOT NULL,
|
|
access_hash BIGINT NOT NULL,
|
|
|
|
PRIMARY KEY (user_id, entity_id)
|
|
);
|
|
|
|
CREATE TABLE telegram_username (
|
|
username TEXT NOT NULL,
|
|
entity_id BIGINT NOT NULL,
|
|
|
|
PRIMARY KEY (username)
|
|
);
|
|
|
|
CREATE INDEX telegram_username_entity_idx ON telegram_username (entity_id);
|
|
|
|
CREATE TABLE telegram_file (
|
|
id TEXT PRIMARY KEY,
|
|
mxc TEXT NOT NULL,
|
|
mime_type TEXT,
|
|
size BIGINT
|
|
);
|