Files
OverCooked-Installer/s-migrations/000049_telegram_group_cleanup.up.sql
T

22 lines
713 B
SQL

CREATE TABLE telegram_group_members (
chat_id bigint NOT NULL,
telegram_user_id bigint NOT NULL,
username text NOT NULL DEFAULT '',
first_seen_at timestamptz NOT NULL DEFAULT now(),
last_seen_at timestamptz NOT NULL DEFAULT now(),
PRIMARY KEY (chat_id, telegram_user_id)
);
CREATE TABLE telegram_group_cleanup_flows (
token_hash text PRIMARY KEY,
actor_user_id uuid NOT NULL REFERENCES users(id) ON DELETE CASCADE,
chat_id bigint NOT NULL,
expires_at timestamptz NOT NULL,
consumed_at timestamptz,
created_at timestamptz NOT NULL DEFAULT now()
);
CREATE INDEX telegram_group_cleanup_flows_active_idx
ON telegram_group_cleanup_flows(actor_user_id, chat_id)
WHERE consumed_at IS NULL;