feat(db): lab5 drop pending status from attachments constraints
This commit is contained in:
@@ -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
|
||||||
Reference in New Issue
Block a user