Files
mtusi2026lab2/src/main/resources/db/migration/V1__schema.sql
T
afanasefff_aandCursor 6300cfc6e0
Application / application (pull_request) Canceled after 0s
Skeleton contracts / contracts (pull_request) Canceled after 0s
Добавить мессенджер на Java с PostgreSQL и сессиями в Redis.
Данные и действующий токен переживают рестарт, сессии хранятся в Redis с AOF.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-10-14 20:52:39 +03:00

44 lines
1.1 KiB
SQL

CREATE TABLE users (
id uuid PRIMARY KEY,
username text NOT NULL,
display_name text NOT NULL,
password_hash text NOT NULL,
created_at timestamptz NOT NULL,
CONSTRAINT users_username_key UNIQUE (username)
);
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 TABLE messages (
id uuid PRIMARY KEY,
chat_id uuid NOT NULL REFERENCES chats (id),
sender_id uuid NOT NULL REFERENCES users (id),
body text NOT NULL,
created_at timestamptz NOT NULL
);
CREATE INDEX messages_history_idx ON messages (chat_id, created_at, id);
CREATE INDEX chat_members_user_idx ON chat_members (user_id, chat_id);
CREATE INDEX chats_order_idx ON chats (created_at, id);
CREATE TABLE app_clock (
id integer PRIMARY KEY,
millis bigint NOT NULL,
CONSTRAINT app_clock_one CHECK (id = 1)
);
INSERT INTO app_clock (id, millis) VALUES (1, 0);