Перенесите реализацию lab3 и сохраните серии нагрузочных экспериментов
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
-- +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);
|
||||
|
||||
-- The key is (chat_id, id) and serves the history query directly:
|
||||
-- WHERE chat_id = $1 AND id > $2 ORDER BY id LIMIT $3. Nothing looks a
|
||||
-- message up by id alone, and a separate index on id would only cost writes
|
||||
-- and tempt the planner into scanning every chat's messages in id order.
|
||||
CREATE TABLE messages (
|
||||
chat_id uuid NOT NULL REFERENCES chats (id),
|
||||
id uuid NOT NULL,
|
||||
sender_id uuid NOT NULL REFERENCES users (id),
|
||||
text text NOT NULL,
|
||||
created_at timestamptz NOT NULL,
|
||||
PRIMARY KEY (chat_id, id)
|
||||
);
|
||||
|
||||
-- +goose Down
|
||||
DROP TABLE messages;
|
||||
DROP TABLE chat_members;
|
||||
DROP TABLE chats;
|
||||
DROP TABLE users;
|
||||
@@ -0,0 +1,17 @@
|
||||
-- +goose Up
|
||||
-- Keys of POST /chats/{chat_id}/messages: the contract scope user + method +
|
||||
-- chat path + key is (user_id, chat_id, key), as no other endpoint takes keys.
|
||||
CREATE TABLE message_idempotency_keys (
|
||||
user_id uuid NOT NULL,
|
||||
chat_id uuid NOT NULL,
|
||||
key text NOT NULL,
|
||||
message_id uuid NOT NULL,
|
||||
created_at timestamptz NOT NULL DEFAULT now(),
|
||||
PRIMARY KEY (user_id, chat_id, key),
|
||||
FOREIGN KEY (chat_id, message_id) REFERENCES messages (chat_id, id)
|
||||
);
|
||||
|
||||
CREATE INDEX message_idempotency_keys_created_at_idx ON message_idempotency_keys (created_at);
|
||||
|
||||
-- +goose Down
|
||||
DROP TABLE message_idempotency_keys;
|
||||
@@ -0,0 +1,8 @@
|
||||
// Package migrations embeds the versioned SQL schema, so the server binary
|
||||
// always carries the schema it was built against.
|
||||
package migrations
|
||||
|
||||
import "embed"
|
||||
|
||||
//go:embed *.sql
|
||||
var FS embed.FS
|
||||
Reference in New Issue
Block a user