ЛР 3 — БПИ2303 — Лазарев — на 3

This commit is contained in:
2026-10-29 16:27:29 +03:00
parent 0ab3a341aa
commit 094039ba95
52 changed files with 8192 additions and 20 deletions
+40
View File
@@ -0,0 +1,40 @@
-- Lab2: начальная схема. Источник истины — PostgreSQL.
CREATE TABLE users (
id uuid PRIMARY KEY,
username text NOT NULL UNIQUE,
display_name text NOT NULL,
password_hash text NOT NULL,
created_at timestamptz NOT NULL
);
CREATE TABLE chats (
id uuid PRIMARY KEY,
title text NOT NULL,
created_at timestamptz NOT NULL
);
CREATE TABLE chat_members (
chat_id uuid NOT NULL REFERENCES chats(id),
user_id uuid NOT NULL REFERENCES users(id),
position integer NOT NULL, -- порядок участников как в запросе
PRIMARY KEY (chat_id, user_id)
);
CREATE INDEX chat_members_user_idx ON chat_members (user_id);
CREATE TABLE messages (
id uuid PRIMARY KEY,
chat_id uuid NOT NULL REFERENCES chats(id),
sender_id uuid NOT NULL REFERENCES users(id),
text text NOT NULL,
created_at timestamptz NOT NULL
);
-- Индекс под keyset-пагинацию истории: (created_at, id) внутри чата.
CREATE INDEX messages_chat_order_idx ON messages (chat_id, created_at, id);
CREATE TABLE sessions (
token_hash bytea PRIMARY KEY, -- SHA-256 от токена; сам токен не хранится
user_id uuid NOT NULL REFERENCES users(id),
created_at timestamptz NOT NULL,
expires_at timestamptz NOT NULL,
revoked_at timestamptz
);