summaryrefslogtreecommitdiff
path: root/makima/migrations/20260203100000_chain_definitions.sql
blob: 9b472794826e34b5e6b19c4083eeea97cdf66d9e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
-- Chain contract definitions - stores contract specs before actual contracts are created
-- This enables on-demand contract creation when dependencies are met
CREATE TABLE IF NOT EXISTS chain_contract_definitions (
    id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
    chain_id UUID NOT NULL REFERENCES chains(id) ON DELETE CASCADE,
    name VARCHAR(255) NOT NULL,
    description TEXT,
    contract_type VARCHAR(32) NOT NULL DEFAULT 'simple',  -- simple/specification/execute
    initial_phase VARCHAR(32) DEFAULT 'plan',
    -- Dependencies by name (resolved to IDs when contract is created)
    depends_on_names TEXT[] DEFAULT '{}',
    -- Task definitions as JSON array: [{name, plan}, ...]
    tasks JSONB DEFAULT '[]',
    -- Deliverable definitions as JSON array: [{id, name, priority}, ...]
    deliverables JSONB DEFAULT '[]',
    -- Position for GUI editor
    editor_x FLOAT DEFAULT 0,
    editor_y FLOAT DEFAULT 0,
    -- Order for display/processing
    order_index INTEGER NOT NULL DEFAULT 0,
    created_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
);

CREATE INDEX idx_chain_contract_definitions_chain_id ON chain_contract_definitions(chain_id);

-- Add supervisor and retry control to chains
ALTER TABLE chains ADD COLUMN IF NOT EXISTS supervisor_task_id UUID REFERENCES tasks(id) ON DELETE SET NULL;
ALTER TABLE chains ADD COLUMN IF NOT EXISTS max_retries INTEGER NOT NULL DEFAULT 3;

-- Add definition link and retry tracking to chain_contracts
ALTER TABLE chain_contracts ADD COLUMN IF NOT EXISTS definition_id UUID REFERENCES chain_contract_definitions(id) ON DELETE SET NULL;
ALTER TABLE chain_contracts ADD COLUMN IF NOT EXISTS retry_count INTEGER NOT NULL DEFAULT 0;