Добавить схему PostgreSQL, миграции и тестовое окружение

This commit is contained in:
2026-10-06 14:46:31 +03:00
parent 5c3f2bfad0
commit a552f15aa7
9 changed files with 731 additions and 26 deletions
+40
View File
@@ -0,0 +1,40 @@
-- +goose Up
CREATE TABLE users (
id uuid PRIMARY KEY,
username text NOT NULL CONSTRAINT users_username_key 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),
PRIMARY KEY (chat_id, user_id)
);
-- Lists the chats of one user in (created_at, id) order: chat ids are UUIDv7.
CREATE INDEX chat_members_user_chat_idx ON chat_members (user_id, chat_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 pagination of one chat's history: WHERE chat_id = $1 AND id > $2 ORDER BY id.
CREATE INDEX messages_chat_id_idx ON messages (chat_id, id);
-- +goose Down
DROP TABLE messages;
DROP TABLE chat_members;
DROP TABLE chats;
DROP TABLE users;