diff options
| author | soryu <soryu@soryu.co> | 2026-02-03 23:19:40 +0000 |
|---|---|---|
| committer | soryu <soryu@soryu.co> | 2026-02-03 23:19:40 +0000 |
| commit | bfa3af9ef16fd5e255bdb606a99a5ebb535ba7cc (patch) | |
| tree | 53da855b4ca61a5c0856fc15112daa7a3748c637 /makima/migrations/20260203000000_create_chains.sql | |
| parent | 1ce281adb89683a5fccfd153706383b14b944f32 (diff) | |
| parent | dcbf8c834626870a43b633b099f409d69d4f9b87 (diff) | |
| download | soryu-makima/discuss-contract-feature.tar.gz soryu-makima/discuss-contract-feature.zip | |
fix: Resolve merge conflict in server/mod.rsmakima/discuss-contract-feature
Combine imports from both branches - include both chains and contract_discuss handlers.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Diffstat (limited to 'makima/migrations/20260203000000_create_chains.sql')
| -rw-r--r-- | makima/migrations/20260203000000_create_chains.sql | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/makima/migrations/20260203000000_create_chains.sql b/makima/migrations/20260203000000_create_chains.sql new file mode 100644 index 0000000..7811a45 --- /dev/null +++ b/makima/migrations/20260203000000_create_chains.sql @@ -0,0 +1,60 @@ +-- Chains table - DAG of contracts for multi-contract orchestration +-- Fits Makima's control theme - she controls through invisible chains +CREATE TABLE IF NOT EXISTS chains ( + id UUID PRIMARY KEY DEFAULT gen_random_uuid(), + owner_id UUID NOT NULL REFERENCES owners(id) ON DELETE CASCADE, + name VARCHAR(255) NOT NULL, + description TEXT, + status VARCHAR(32) NOT NULL DEFAULT 'active', -- active/completed/archived + -- Loop control for iterative execution + loop_enabled BOOLEAN NOT NULL DEFAULT false, + loop_max_iterations INTEGER DEFAULT 10, + loop_current_iteration INTEGER DEFAULT 0, + loop_progress_check TEXT, -- Prompt/criteria for evaluating progress + -- Repository reference (optional - contracts may have their own repos) + repository_url VARCHAR(512), + local_path VARCHAR(512), + -- Versioning for optimistic locking + version INTEGER NOT NULL DEFAULT 1, + created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(), + updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW() +); + +CREATE INDEX idx_chains_owner_id ON chains(owner_id); +CREATE INDEX idx_chains_status ON chains(status); + +-- Chain contracts - links contracts to chains with DAG dependency info +-- The depends_on array forms the DAG edges (directed acyclic graph) +CREATE TABLE IF NOT EXISTS chain_contracts ( + id UUID PRIMARY KEY DEFAULT gen_random_uuid(), + chain_id UUID NOT NULL REFERENCES chains(id) ON DELETE CASCADE, + contract_id UUID NOT NULL REFERENCES contracts(id) ON DELETE CASCADE, + -- DAG edges: contract IDs this contract depends on (must complete before this starts) + depends_on UUID[] DEFAULT '{}', + -- Order for display/processing (topological sort order) + order_index INTEGER NOT NULL DEFAULT 0, + -- Position for GUI editor + editor_x FLOAT DEFAULT 0, + editor_y FLOAT DEFAULT 0, + created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(), + UNIQUE(chain_id, contract_id) +); + +CREATE INDEX idx_chain_contracts_chain_id ON chain_contracts(chain_id); +CREATE INDEX idx_chain_contracts_contract_id ON chain_contracts(contract_id); + +-- Add chain_id to contracts table for reverse lookup +ALTER TABLE contracts ADD COLUMN IF NOT EXISTS chain_id UUID REFERENCES chains(id) ON DELETE SET NULL; +CREATE INDEX IF NOT EXISTS idx_contracts_chain_id ON contracts(chain_id); + +-- Chain events for audit trail +CREATE TABLE IF NOT EXISTS chain_events ( + id UUID PRIMARY KEY DEFAULT gen_random_uuid(), + chain_id UUID NOT NULL REFERENCES chains(id) ON DELETE CASCADE, + event_type VARCHAR(64) NOT NULL, -- created, contract_added, contract_completed, loop_iteration, completed + contract_id UUID REFERENCES contracts(id) ON DELETE SET NULL, + event_data JSONB, + created_at TIMESTAMPTZ NOT NULL DEFAULT NOW() +); + +CREATE INDEX idx_chain_events_chain_id ON chain_events(chain_id); |
