-- Intake sessions CREATE TABLE IF NOT EXISTS intake_sessions ( id INTEGER PRIMARY KEY AUTOINCREMENT, current_phase INTEGER DEFAULT 0, is_complete BOOLEAN DEFAULT 0, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ); -- Intake answers (one per phase per session) CREATE TABLE IF NOT EXISTS intake_answers ( id INTEGER PRIMARY KEY AUTOINCREMENT, session_id INTEGER NOT NULL, phase INTEGER NOT NULL, fields_json TEXT, -- JSON: {field_name: value} nested_items_json TEXT, -- JSON: [{field1: val1, field2: val2}, ...] submitted_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, FOREIGN KEY (session_id) REFERENCES intake_sessions(id), UNIQUE(session_id, phase) ); CREATE INDEX IF NOT EXISTS idx_intake_answers_session_id ON intake_answers(session_id);