Centralize durable schema migration ownership

This commit is contained in:
ms2k 2026-07-19 01:20:18 +09:00
commit 069f3813ae

View file

@ -0,0 +1,35 @@
ALTER TABLE attempts
DROP CONSTRAINT attempts_state_check,
DROP CONSTRAINT attempts_state_timestamps_check,
ADD COLUMN stopped_at TIMESTAMPTZ,
ADD COLUMN committed_at TIMESTAMPTZ,
ADD COLUMN failure JSONB,
ADD CONSTRAINT attempts_state_check CHECK (
state IN ('authorized', 'executing', 'reaped', 'stopped', 'committed')
),
ADD CONSTRAINT attempts_state_timestamps_check CHECK (
(state = 'authorized' AND executing_at IS NULL AND reaped_at IS NULL
AND stopped_at IS NULL AND committed_at IS NULL)
OR (state = 'executing' AND executing_at IS NOT NULL AND reaped_at IS NULL
AND stopped_at IS NULL AND committed_at IS NULL)
OR (state = 'reaped' AND executing_at IS NULL AND reaped_at IS NOT NULL
AND stopped_at IS NULL AND committed_at IS NULL)
OR (state = 'stopped' AND executing_at IS NOT NULL AND reaped_at IS NULL
AND stopped_at IS NOT NULL AND committed_at IS NULL)
OR (state = 'committed' AND executing_at IS NOT NULL AND reaped_at IS NULL
AND stopped_at IS NULL AND committed_at IS NOT NULL)
);
ALTER TABLE jobs
ADD COLUMN cancel_requested BOOLEAN NOT NULL DEFAULT FALSE,
ADD COLUMN resolved_source JSONB,
ADD COLUMN checkpoint JSONB,
ADD COLUMN committed_result JSONB,
ADD COLUMN failure JSONB,
ADD COLUMN terminal_at TIMESTAMPTZ,
ADD CONSTRAINT jobs_terminal_projection_check CHECK (
((phase = 'succeeded') = (committed_result IS NOT NULL))
AND ((phase = 'failed') = (failure IS NOT NULL))
AND ((phase IN ('succeeded', 'failed', 'cancelled')) = (terminal_at IS NOT NULL))
AND (committed_result IS NULL OR failure IS NULL)
);