Files
mtusi2026lab2/evidence/schema.txt
T
ArtyomandClaude Opus 5.5 db901d6401 Record level 3 evidence and fill in the report
Evidence comes from the stand started from an empty state and from a
fresh clone: the public smoke, the contract checks, lint and 325 own
tests, the storage layout with an out-of-API comparison of a stored
object against its metadata, failover of each replica under writes, the
upload failover scenario, persistence with StartedAt of every service
including S3, the S3 outage scenario and 22 S3 privacy and bootstrap
checks. The storage evidence script now covers the attachment tables
and the S3 secrets.

REPORT.md follows the lab 4 template: launch from a clean clone,
architecture with the source of truth for each fact, the write order
between PostgreSQL and S3 and what each failure leaves behind, where
each upload limit applies, roles and services, the .env.example
mapping, grade 3 rows and the grade 3 failure table. The design notes
the botocore Expect header that hung uploads behind the port proxy.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-28 22:20:10 +03:00

194 lines
14 KiB
Plaintext

date: 2026-10-28T18:07:53Z commit: 24f9d61
$ psql -c '\d+ users'
Table "public.users"
Column | Type | Collation | Nullable | Default | Storage | Compression | Stats target | Description
---------------+--------------------------+-----------+----------+---------+----------+-------------+--------------+-------------
id | uuid | | not null | | plain | | |
username | text | | not null | | extended | | |
display_name | text | | not null | | extended | | |
password_hash | text | | not null | | extended | | |
created_at | timestamp with time zone | | not null | | plain | | |
Indexes:
"users_pkey" PRIMARY KEY, btree (id)
"users_username_key" UNIQUE CONSTRAINT, btree (username)
Check constraints:
"users_display_name_check" CHECK (char_length(display_name) >= 1 AND char_length(display_name) <= 100)
"users_password_hash_check" CHECK (password_hash ~~ '$argon2id$%'::text)
"users_username_format" CHECK (username ~ '^[a-z0-9_]{3,32}$'::text)
Referenced by:
TABLE "chat_members" CONSTRAINT "chat_members_user_id_fkey" FOREIGN KEY (user_id) REFERENCES users(id)
TABLE "sessions" CONSTRAINT "sessions_user_id_fkey" FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
Access method: heap
$ psql -c '\d+ sessions'
Table "public.sessions"
Column | Type | Collation | Nullable | Default | Storage | Compression | Stats target | Description
------------+--------------------------+-----------+----------+---------+----------+-------------+--------------+-------------
token_hash | bytea | | not null | | extended | | |
user_id | uuid | | not null | | plain | | |
created_at | timestamp with time zone | | not null | | plain | | |
expires_at | timestamp with time zone | | not null | | plain | | |
Indexes:
"sessions_pkey" PRIMARY KEY, btree (token_hash)
"sessions_user_idx" btree (user_id)
Check constraints:
"sessions_check" CHECK (expires_at > created_at)
"sessions_token_hash_check" CHECK (octet_length(token_hash) = 32)
Foreign-key constraints:
"sessions_user_id_fkey" FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
Access method: heap
$ psql -c '\d+ chats'
Table "public.chats"
Column | Type | Collation | Nullable | Default | Storage | Compression | Stats target | Description
-----------------+--------------------------+-----------+----------+---------+----------+-------------+--------------+-------------
id | uuid | | not null | | plain | | |
title | text | | not null | | extended | | |
created_at | timestamp with time zone | | not null | | plain | | |
last_message_at | timestamp with time zone | | | | plain | | |
Indexes:
"chats_pkey" PRIMARY KEY, btree (id)
Check constraints:
"chats_title_check" CHECK (char_length(title) >= 1 AND char_length(title) <= 100)
Referenced by:
TABLE "chat_members" CONSTRAINT "chat_members_chat_id_fkey" FOREIGN KEY (chat_id) REFERENCES chats(id) ON DELETE CASCADE
Access method: heap
$ psql -c '\d+ chat_members'
Table "public.chat_members"
Column | Type | Collation | Nullable | Default | Storage | Compression | Stats target | Description
-----------------+--------------------------+-----------+----------+---------+---------+-------------+--------------+-------------
chat_id | uuid | | not null | | plain | | |
user_id | uuid | | not null | | plain | | |
position | smallint | | not null | | plain | | |
chat_created_at | timestamp with time zone | | not null | | plain | | |
Indexes:
"chat_members_pkey" PRIMARY KEY, btree (chat_id, user_id)
"chat_members_user_idx" btree (user_id, chat_created_at, chat_id)
Check constraints:
"chat_members_position_check" CHECK ("position" >= 1 AND "position" <= 100)
Foreign-key constraints:
"chat_members_chat_id_fkey" FOREIGN KEY (chat_id) REFERENCES chats(id) ON DELETE CASCADE
"chat_members_user_id_fkey" FOREIGN KEY (user_id) REFERENCES users(id)
Referenced by:
TABLE "attachments" CONSTRAINT "attachments_owner_fkey" FOREIGN KEY (chat_id, owner_id) REFERENCES chat_members(chat_id, user_id)
TABLE "idempotency_keys" CONSTRAINT "idempotency_keys_chat_id_user_id_fkey" FOREIGN KEY (chat_id, user_id) REFERENCES chat_members(chat_id, user_id)
TABLE "messages" CONSTRAINT "messages_chat_id_sender_id_fkey" FOREIGN KEY (chat_id, sender_id) REFERENCES chat_members(chat_id, user_id)
Access method: heap
$ psql -c '\d+ messages'
Table "public.messages"
Column | Type | Collation | Nullable | Default | Storage | Compression | Stats target | Description
------------+--------------------------+-----------+----------+---------+----------+-------------+--------------+-------------
id | uuid | | not null | | plain | | |
chat_id | uuid | | not null | | plain | | |
sender_id | uuid | | not null | | plain | | |
text | text | | not null | | extended | | |
created_at | timestamp with time zone | | not null | | plain | | |
Indexes:
"messages_pkey" PRIMARY KEY, btree (id)
"messages_history_idx" btree (chat_id, created_at, id)
Check constraints:
"messages_text_check" CHECK (char_length(text) <= 4000)
Foreign-key constraints:
"messages_chat_id_sender_id_fkey" FOREIGN KEY (chat_id, sender_id) REFERENCES chat_members(chat_id, user_id)
Referenced by:
TABLE "idempotency_keys" CONSTRAINT "idempotency_keys_message_id_fkey" FOREIGN KEY (message_id) REFERENCES messages(id) ON DELETE CASCADE
TABLE "message_attachments" CONSTRAINT "message_attachments_message_id_fkey" FOREIGN KEY (message_id) REFERENCES messages(id) ON DELETE CASCADE
Access method: heap
$ psql -c '\d+ idempotency_keys'
Table "public.idempotency_keys"
Column | Type | Collation | Nullable | Default | Storage | Compression | Stats target | Description
-------------+--------------------------+-----------+----------+---------+----------+-------------+--------------+-------------
chat_id | uuid | | not null | | plain | | |
user_id | uuid | | not null | | plain | | |
key | text | | not null | | extended | | |
fingerprint | bytea | | not null | | extended | | |
message_id | uuid | | not null | | plain | | |
created_at | timestamp with time zone | | not null | | plain | | |
Indexes:
"idempotency_keys_pkey" PRIMARY KEY, btree (chat_id, user_id, key)
Check constraints:
"idempotency_keys_fingerprint_check" CHECK (octet_length(fingerprint) = 32)
"idempotency_keys_key_check" CHECK (key ~ '^[A-Za-z0-9._:-]{1,128}$'::text)
Foreign-key constraints:
"idempotency_keys_chat_id_user_id_fkey" FOREIGN KEY (chat_id, user_id) REFERENCES chat_members(chat_id, user_id)
"idempotency_keys_message_id_fkey" FOREIGN KEY (message_id) REFERENCES messages(id) ON DELETE CASCADE
Access method: heap
$ psql -c '\d+ attachments'
Table "public.attachments"
Column | Type | Collation | Nullable | Default | Storage | Compression | Stats target | Description
--------------+--------------------------+-----------+----------+---------+----------+-------------+--------------+-------------
id | uuid | | not null | | plain | | |
chat_id | uuid | | not null | | plain | | |
owner_id | uuid | | not null | | plain | | |
filename | text | | not null | | extended | | |
content_type | text | | not null | | extended | | |
size_bytes | bigint | | not null | | plain | | |
sha256 | text | | not null | | extended | | |
width | integer | | not null | | plain | | |
height | integer | | not null | | plain | | |
object_key | text | C | not null | | extended | | |
status | text | | not null | | extended | | |
created_at | timestamp with time zone | | not null | | plain | | |
updated_at | timestamp with time zone | | not null | | plain | | |
Indexes:
"attachments_pkey" PRIMARY KEY, btree (id)
"attachments_chat_key" UNIQUE CONSTRAINT, btree (id, chat_id)
"attachments_object_key_key" UNIQUE CONSTRAINT, btree (object_key)
"attachments_pending_idx" btree (created_at) WHERE status = 'pending'::text
Check constraints:
"attachments_content_type_check" CHECK (content_type = ANY (ARRAY['image/png'::text, 'image/jpeg'::text]))
"attachments_filename_check" CHECK (char_length(filename) >= 1 AND char_length(filename) <= 255)
"attachments_height_check" CHECK (height > 0)
"attachments_sha256_check" CHECK (sha256 ~ '^[0-9a-f]{64}$'::text)
"attachments_size_bytes_check" CHECK (size_bytes >= 1 AND size_bytes <= 10485760)
"attachments_status_check" CHECK (status = ANY (ARRAY['pending'::text, 'ready'::text]))
"attachments_width_check" CHECK (width > 0)
Foreign-key constraints:
"attachments_owner_fkey" FOREIGN KEY (chat_id, owner_id) REFERENCES chat_members(chat_id, user_id)
Referenced by:
TABLE "message_attachments" CONSTRAINT "message_attachments_attachment_fkey" FOREIGN KEY (attachment_id, chat_id) REFERENCES attachments(id, chat_id) ON DELETE RESTRICT
Access method: heap
$ psql -c '\d+ message_attachments'
Table "public.message_attachments"
Column | Type | Collation | Nullable | Default | Storage | Compression | Stats target | Description
---------------+----------+-----------+----------+---------+---------+-------------+--------------+-------------
message_id | uuid | | not null | | plain | | |
position | smallint | | not null | | plain | | |
chat_id | uuid | | not null | | plain | | |
attachment_id | uuid | | not null | | plain | | |
Indexes:
"message_attachments_pkey" PRIMARY KEY, btree (message_id, "position")
"message_attachments_attachment_idx" btree (attachment_id)
"message_attachments_message_id_attachment_id_key" UNIQUE CONSTRAINT, btree (message_id, attachment_id)
Check constraints:
"message_attachments_position_check" CHECK ("position" >= 0 AND "position" <= 9)
Foreign-key constraints:
"message_attachments_attachment_fkey" FOREIGN KEY (attachment_id, chat_id) REFERENCES attachments(id, chat_id) ON DELETE RESTRICT
"message_attachments_message_id_fkey" FOREIGN KEY (message_id) REFERENCES messages(id) ON DELETE CASCADE
Access method: heap
$ psql -c '\d+ schema_migrations'
Table "public.schema_migrations"
Column | Type | Collation | Nullable | Default | Storage | Compression | Stats target | Description
------------+--------------------------+-----------+----------+---------+----------+-------------+--------------+-------------
version | text | | not null | | extended | | |
checksum | text | | not null | | extended | | |
applied_at | timestamp with time zone | | not null | now() | plain | | |
Indexes:
"schema_migrations_pkey" PRIMARY KEY, btree (version)
Access method: heap
$ psql -c 'SELECT version, left(checksum, 12), applied_at FROM schema_migrations'
version | checksum | applied_at
-----------------------+--------------+-------------------------------
0001_init | 9a13618f078a | 2026-10-28 17:51:09.25584+00
0002_idempotency_keys | d9159a355532 | 2026-10-28 17:51:09.261879+00
0003_attachments | c4417f560538 | 2026-10-28 17:51:09.263628+00
(3 rows)