ЛР 6: observability OpenTelemetry/Grafana

This commit is contained in:
2026-11-17 17:13:25 +03:00
parent 470d9d6f1e
commit 7a57ae41f4
45 changed files with 3300 additions and 33 deletions
+44
View File
@@ -0,0 +1,44 @@
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
);
CREATE UNIQUE INDEX users_username_uidx ON users (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),
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
);
CREATE INDEX messages_chat_created_id_idx ON messages (chat_id, created_at, id);
CREATE TABLE sessions (
token_hash TEXT PRIMARY KEY,
user_id UUID NOT NULL REFERENCES users (id),
expires_at TIMESTAMPTZ NOT NULL,
revoked_at TIMESTAMPTZ,
created_at TIMESTAMPTZ NOT NULL
);
CREATE INDEX sessions_user_idx ON sessions (user_id);
CREATE INDEX sessions_expires_idx ON sessions (expires_at);
+9
View File
@@ -0,0 +1,9 @@
CREATE TABLE idempotency_records (
scope_key TEXT PRIMARY KEY,
request_hash TEXT NOT NULL,
message_id UUID NOT NULL REFERENCES messages (id),
created_at TIMESTAMPTZ NOT NULL,
expires_at TIMESTAMPTZ NOT NULL
);
CREATE INDEX idempotency_records_expires_idx ON idempotency_records (expires_at);
+25
View File
@@ -0,0 +1,25 @@
CREATE TABLE attachments (
id UUID PRIMARY KEY,
chat_id UUID NOT NULL REFERENCES chats (id),
owner_id UUID NOT NULL REFERENCES users (id),
filename TEXT NOT NULL,
content_type TEXT NOT NULL,
size_bytes BIGINT NOT NULL,
sha256 TEXT NOT NULL,
object_key TEXT NOT NULL UNIQUE,
status TEXT NOT NULL,
error_code TEXT,
created_at TIMESTAMPTZ NOT NULL,
updated_at TIMESTAMPTZ NOT NULL
);
CREATE INDEX attachments_chat_id_idx ON attachments (chat_id);
CREATE TABLE message_attachments (
message_id UUID NOT NULL REFERENCES messages (id),
attachment_id UUID NOT NULL REFERENCES attachments (id),
position INT NOT NULL,
PRIMARY KEY (message_id, attachment_id)
);
CREATE INDEX message_attachments_attachment_id_idx ON message_attachments (attachment_id);
+32
View File
@@ -0,0 +1,32 @@
ALTER TABLE attachments
ADD COLUMN staging_object_key TEXT;
UPDATE attachments
SET staging_object_key = object_key
WHERE staging_object_key IS NULL;
ALTER TABLE attachments
ALTER COLUMN staging_object_key SET NOT NULL;
CREATE TABLE attachment_variants (
attachment_id UUID NOT NULL REFERENCES attachments (id),
name TEXT NOT NULL,
content_type TEXT NOT NULL,
size_bytes BIGINT NOT NULL,
width INT NOT NULL,
height INT NOT NULL,
sha256 TEXT NOT NULL,
object_key TEXT NOT NULL UNIQUE,
PRIMARY KEY (attachment_id, name)
);
CREATE TABLE attachment_jobs (
job_id UUID PRIMARY KEY,
attachment_id UUID NOT NULL UNIQUE REFERENCES attachments (id),
pipeline_version INT NOT NULL,
attempt INT NOT NULL,
max_attempts INT NOT NULL,
created_at TIMESTAMPTZ NOT NULL
);
CREATE INDEX attachment_jobs_attachment_id_idx ON attachment_jobs (attachment_id);