diff --git a/supabase/migrations/20260123000000_add_characters_variables_to_flowchart_data.sql b/supabase/migrations/20260123000000_add_characters_variables_to_flowchart_data.sql new file mode 100644 index 0000000..2a0642c --- /dev/null +++ b/supabase/migrations/20260123000000_add_characters_variables_to_flowchart_data.sql @@ -0,0 +1,45 @@ +-- Migration: Add characters and variables arrays to flowchart_data JSONB default +-- Part of Character/Variable Management feature (US-055) +-- +-- The characters and variables arrays are stored within the flowchart_data JSONB column. +-- This migration updates the default value for new projects to include empty arrays. +-- Existing projects without these fields are handled at the application layer, +-- which defaults missing characters/variables to empty arrays on read. + +-- ============================================================================= +-- UPDATE DEFAULT VALUE FOR flowchart_data +-- ============================================================================= +-- Update the default to include characters and variables arrays +ALTER TABLE projects + ALTER COLUMN flowchart_data + SET DEFAULT '{"nodes": [], "edges": [], "characters": [], "variables": []}'::jsonb; + +-- ============================================================================= +-- DOCUMENTATION: JSONB Structure +-- ============================================================================= +-- The flowchart_data column now expects the following top-level structure: +-- +-- { +-- "nodes": [...], -- Array of flowchart nodes +-- "edges": [...], -- Array of flowchart edges +-- "characters": [ -- Array of character definitions +-- { +-- "id": "string", -- Unique identifier (nanoid) +-- "name": "string", -- Character name (required, unique per project) +-- "color": "string", -- Hex color code (e.g., "#FF5733") +-- "description": "string" -- Optional description +-- } +-- ], +-- "variables": [ -- Array of variable definitions +-- { +-- "id": "string", -- Unique identifier (nanoid) +-- "name": "string", -- Variable name (required, unique per project) +-- "type": "string", -- One of: 'numeric', 'string', 'boolean' +-- "initialValue": "any", -- Initial value matching the type +-- "description": "string" -- Optional description +-- } +-- ] +-- } +-- +-- Note: Existing projects that do not have characters/variables fields +-- are handled at the application layer, which defaults them to empty arrays.