feat(db): add attachment content type and status enums

This commit is contained in:
kk10
2026-11-02 21:50:29 +03:00
parent 983bbaa55e
commit 42ddd2cad9
5 changed files with 108 additions and 15 deletions
+7 -2
View File
@@ -1,14 +1,17 @@
-- +goose Up
CREATE TYPE attachment_content_type AS ENUM ('image/png', 'image/jpeg');
CREATE TYPE attachment_status AS ENUM ('queued', 'processing', 'ready', 'failed');
CREATE TABLE attachments (
id uuid PRIMARY KEY,
chat_id uuid NOT NULL REFERENCES chats (id) ON DELETE CASCADE,
owner_id uuid NOT NULL REFERENCES users (id) ON DELETE RESTRICT,
s3_key text NOT NULL UNIQUE,
filename text NOT NULL,
content_type text NOT NULL CHECK (content_type IN ('image/png', 'image/jpeg')),
content_type attachment_content_type NOT NULL,
size_bytes int NOT NULL CHECK (size_bytes > 0 AND size_bytes <= 10485760),
sha256 text NOT NULL CHECK (sha256 ~ '^[a-f0-9]{64}$'),
status text NOT NULL DEFAULT 'ready' CHECK (status = 'ready'),
status attachment_status NOT NULL DEFAULT 'ready',
error_code text,
created_at timestamptz NOT NULL DEFAULT now(),
updated_at timestamptz NOT NULL DEFAULT now()
@@ -30,3 +33,5 @@ CREATE INDEX idx_message_attachments_attachment_id ON message_attachments (attac
-- +goose Down
DROP TABLE message_attachments;
DROP TABLE attachments;
DROP TYPE attachment_status;
DROP TYPE attachment_content_type;
+2 -2
View File
@@ -17,10 +17,10 @@ SELECT
sqlc.arg(owner_id)::uuid,
sqlc.arg(s3_key)::text,
sqlc.arg(filename)::text,
sqlc.arg(content_type)::text,
sqlc.arg(content_type)::attachment_content_type,
sqlc.arg(size_bytes)::int,
sqlc.arg(sha256)::text,
sqlc.arg(status)::text,
sqlc.arg(status)::attachment_status,
sqlc.arg(error_code)::text
WHERE EXISTS (
SELECT 1 FROM chat_members