feat: persist messenger data and sessions in PostgreSQL

This commit is contained in:
Artem
2026-12-04 20:56:56 +03:00
parent 65003b6119
commit 4abfcf2cd9
25 changed files with 1632 additions and 0 deletions
+7
View File
@@ -0,0 +1,7 @@
CREATE TABLE IF NOT EXISTS users(id uuid PRIMARY KEY DEFAULT gen_random_uuid(),username text UNIQUE NOT NULL,display_name text NOT NULL,salt text NOT NULL,hash text NOT NULL,created_at timestamptz(3) NOT NULL DEFAULT clock_timestamp());
CREATE TABLE IF NOT EXISTS sessions(token_hash text PRIMARY KEY,user_id uuid NOT NULL REFERENCES users,expires_at timestamptz NOT NULL);
CREATE TABLE IF NOT EXISTS chats(id uuid PRIMARY KEY DEFAULT gen_random_uuid(),title text NOT NULL,created_at timestamptz(3) NOT NULL DEFAULT clock_timestamp());
CREATE TABLE IF NOT EXISTS members(chat_id uuid REFERENCES chats,user_id uuid REFERENCES users,PRIMARY KEY(chat_id,user_id));
CREATE INDEX IF NOT EXISTS members_by_user ON members(user_id,chat_id);
CREATE TABLE IF NOT EXISTS messages(id uuid PRIMARY KEY DEFAULT gen_random_uuid(),chat_id uuid NOT NULL REFERENCES chats,sender_id uuid NOT NULL REFERENCES users,text text NOT NULL,created_at timestamptz(3) NOT NULL DEFAULT clock_timestamp());
CREATE INDEX IF NOT EXISTS history_key ON messages(chat_id,created_at,id);