Skip to content

Commit cd94242

Browse files
committed
chore: update database schema and data for new constraints and attributes
- Added 'task_index' attribute to 'step_task_record' type - Prepared existing data by setting 'remaining_tasks' to NULL where 'status' is 'created' - Modified 'step_states' table by dropping constraints and adding new ones for data consistency - Altered 'remaining_tasks' column to allow nulls and removed default - Added 'initial_tasks' column to 'step_states' table
1 parent 020cb85 commit cd94242

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

pkgs/core/supabase/migrations/20251006073122_pgflow_add_map_step_type.sql

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
-- Modify "step_task_record" composite type
22
ALTER TYPE "pgflow"."step_task_record" ADD ATTRIBUTE "task_index" integer;
3+
-- MANUAL DATA MIGRATION: Prepare existing data for new constraint
4+
-- This UPDATE must run BEFORE the new constraint is added to avoid failures
5+
-- The new constraint "remaining_tasks_state_consistency" requires that
6+
-- remaining_tasks is NULL when status = 'created'
7+
UPDATE "pgflow"."step_states"
8+
SET "remaining_tasks" = NULL
9+
WHERE "status" = 'created';
310
-- Modify "step_states" table
411
ALTER TABLE "pgflow"."step_states" DROP CONSTRAINT "step_states_remaining_tasks_check", ADD CONSTRAINT "initial_tasks_known_when_started" CHECK ((status <> 'started'::text) OR (initial_tasks IS NOT NULL)), ADD CONSTRAINT "remaining_tasks_state_consistency" CHECK ((remaining_tasks IS NULL) OR (status <> 'created'::text)), ADD CONSTRAINT "step_states_initial_tasks_check" CHECK ((initial_tasks IS NULL) OR (initial_tasks >= 0)), ALTER COLUMN "remaining_tasks" DROP NOT NULL, ALTER COLUMN "remaining_tasks" DROP DEFAULT, ADD COLUMN "initial_tasks" integer NULL;
512
-- Modify "step_tasks" table

0 commit comments

Comments
 (0)