forked from mtusi2026/mtusi2026lab4
refactor(db): use int for attachment size and add lookup query
This commit is contained in:
@@ -6,7 +6,7 @@ CREATE TABLE attachments (
|
||||
s3_key text NOT NULL UNIQUE,
|
||||
filename text NOT NULL,
|
||||
content_type text NOT NULL CHECK (content_type IN ('image/png', 'image/jpeg')),
|
||||
size_bytes bigint NOT NULL CHECK (size_bytes > 0 AND size_bytes <= 10485760),
|
||||
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'),
|
||||
error_code text,
|
||||
|
||||
@@ -18,7 +18,7 @@ SELECT
|
||||
sqlc.arg(s3_key)::text,
|
||||
sqlc.arg(filename)::text,
|
||||
sqlc.arg(content_type)::text,
|
||||
sqlc.arg(size_bytes)::bigint,
|
||||
sqlc.arg(size_bytes)::int,
|
||||
sqlc.arg(sha256)::text,
|
||||
sqlc.arg(status)::text,
|
||||
sqlc.arg(error_code)::text
|
||||
@@ -40,6 +40,10 @@ INSERT INTO message_attachments (
|
||||
sqlc.arg(position)
|
||||
);
|
||||
|
||||
-- name: GetAttachmentByID :one
|
||||
SELECT * FROM attachments
|
||||
WHERE id = $1::uuid;
|
||||
|
||||
-- name: ListAttachmentsByIDs :many
|
||||
SELECT status
|
||||
FROM attachments
|
||||
|
||||
Reference in New Issue
Block a user