Files
2026-10-28 22:41:10 +03:00

21 lines
834 B
SQL

-- +goose Up
CREATE TABLE IF NOT EXISTS attachments (
id uuid PRIMARY KEY,
chat_id uuid NOT NULL REFERENCES chats(id),
uploader_id uuid NOT NULL REFERENCES users(id),
filename text NOT NULL,
object_key text NOT NULL UNIQUE,
content_type text NOT NULL CHECK (content_type IN ('image/png','image/jpeg')),
size_bytes bigint NOT NULL CHECK (size_bytes BETWEEN 1 AND 10485760),
sha256 text NOT NULL CHECK (sha256 ~ '^[0-9a-f]{64}$'),
width integer NOT NULL,
height integer NOT NULL,
status text NOT NULL DEFAULT 'ready' CHECK (status IN ('ready','failed')),
error_code text,
created_at timestamptz NOT NULL DEFAULT clock_timestamp(),
CHECK ((status='ready' AND error_code IS NULL) OR (status='failed' AND error_code IS NOT NULL))
);
-- +goose Down
DROP TABLE IF EXISTS attachments;