forked from mtusi2026/mtusi2026lab2
8 lines
858 B
SQL
8 lines
858 B
SQL
CREATE TABLE IF NOT EXISTS users(id text PRIMARY KEY, username text UNIQUE NOT NULL, password_hash text NOT NULL, doc jsonb NOT NULL);
|
|
CREATE TABLE IF NOT EXISTS sessions(digest text PRIMARY KEY, owner text REFERENCES users, expires timestamptz NOT NULL);
|
|
CREATE TABLE IF NOT EXISTS chats(id text PRIMARY KEY, doc jsonb NOT NULL);
|
|
CREATE TABLE IF NOT EXISTS members(chat text REFERENCES chats, owner text REFERENCES users, PRIMARY KEY(chat,owner));
|
|
CREATE TABLE IF NOT EXISTS messages(id text PRIMARY KEY, chat text REFERENCES chats, sender text REFERENCES users, retry_key text, doc jsonb NOT NULL, UNIQUE(chat,sender,retry_key));
|
|
CREATE INDEX IF NOT EXISTS messages_chat ON messages(chat);
|
|
CREATE TABLE IF NOT EXISTS attachments(id text PRIMARY KEY, chat text REFERENCES chats, owner text REFERENCES users, doc jsonb NOT NULL, attempts integer DEFAULT 0);
|