-- 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.