From c34db41342423d08173b3d1cb2450c43ef2291be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=93=D0=BE=D0=BB=D0=B8=D0=BA=D0=BE=D0=B2=20Maximillian?= =?UTF-8?q?=20=D0=90=D0=BD=D1=82=D0=BE=D0=BD?= Date: Sat, 7 Nov 2026 10:28:45 +0300 Subject: [PATCH] feat(db): lab5 drop pending status from attachments constraints --- backend/migrations/0007_drop_pending.sql | 42 ++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 backend/migrations/0007_drop_pending.sql diff --git a/backend/migrations/0007_drop_pending.sql b/backend/migrations/0007_drop_pending.sql new file mode 100644 index 0000000..dcc2d57 --- /dev/null +++ b/backend/migrations/0007_drop_pending.sql @@ -0,0 +1,42 @@ +-- +goose Up +-- +goose StatementBegin + +ALTER TABLE attachments DROP CONSTRAINT IF EXISTS attachments_status_chk; +ALTER TABLE attachments ADD CONSTRAINT attachments_status_chk + CHECK (status IN ('queued', 'processing', 'ready', 'failed')); + +ALTER TABLE attachments DROP CONSTRAINT IF EXISTS attachments_error_code_consistency; +ALTER TABLE attachments ADD CONSTRAINT attachments_error_code_consistency + CHECK ( + (status IN ('queued', 'processing', 'ready') AND error_code IS NULL) OR + (status = 'failed' AND error_code IS NOT NULL) + ); + +DROP INDEX IF EXISTS attachments_pending_idx; +CREATE INDEX attachments_active_idx + ON attachments (created_at) + WHERE status IN ('queued', 'processing'); + +-- +goose StatementEnd + + +-- +goose Down +-- +goose StatementBegin + +DROP INDEX IF EXISTS attachments_active_idx; +CREATE INDEX attachments_pending_idx + ON attachments (created_at) + WHERE status = 'pending'; + +ALTER TABLE attachments DROP CONSTRAINT IF EXISTS attachments_error_code_consistency; +ALTER TABLE attachments ADD CONSTRAINT attachments_error_code_consistency + CHECK ( + (status IN ('ready', 'pending') AND error_code IS NULL) OR + (status = 'failed' AND error_code IS NOT NULL) + ); + +ALTER TABLE attachments DROP CONSTRAINT IF EXISTS attachments_status_chk; +ALTER TABLE attachments ADD CONSTRAINT attachments_status_chk + CHECK (status IN ('ready', 'pending', 'failed')); + +-- +goose StatementEnd \ No newline at end of file