From 0302b4596e14210884df5d645df9a179d8f0c1c6 Mon Sep 17 00:00:00 2001
From: soryu <soryu@soryu.co>
Date: Thu, 5 Feb 2026 00:48:38 +0000
Subject: Add multi-repository support for chains

Chains can now have multiple repositories attached, with one marked as
primary. Repositories are used by contracts created from chain definitions.

Backend changes:
- Add chain_repositories table migration
- Add ChainRepository model with CRUD operations
- Add API endpoints for listing, adding, deleting repositories
- Add endpoint to set a repository as primary
- Update Chain and ChainEditorData models to use repositories
- Update chain parser to support repositories in YAML format
- Remove deprecated repository_url/local_path from Chain

Frontend changes:
- Add ChainRepository interface and API functions
- Add repository section to ChainEditor showing attached repos
- Add modal for adding new repositories (remote or local)
- Support setting primary repository and removing repositories

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
---
 .../20260205000000_chain_repositories.sql          | 27 ++++++++++++++++++++++
 1 file changed, 27 insertions(+)
 create mode 100644 makima/migrations/20260205000000_chain_repositories.sql

(limited to 'makima/migrations/20260205000000_chain_repositories.sql')

diff --git a/makima/migrations/20260205000000_chain_repositories.sql b/makima/migrations/20260205000000_chain_repositories.sql
new file mode 100644
index 0000000..5be8cf2
--- /dev/null
+++ b/makima/migrations/20260205000000_chain_repositories.sql
@@ -0,0 +1,27 @@
+-- Chain repositories - allow chains to have multiple repositories
+-- Similar to contract_repositories but for chains
+CREATE TABLE IF NOT EXISTS chain_repositories (
+    id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
+    chain_id UUID NOT NULL REFERENCES chains(id) ON DELETE CASCADE,
+    name VARCHAR(255) NOT NULL,                     -- display name / repo name
+    repository_url VARCHAR(512),                    -- NULL for local repos
+    local_path VARCHAR(512),                        -- local filesystem path (for local repos)
+    source_type VARCHAR(32) NOT NULL DEFAULT 'remote', -- remote/local/managed
+    status VARCHAR(32) NOT NULL DEFAULT 'ready',    -- ready/pending/creating/failed
+    is_primary BOOLEAN NOT NULL DEFAULT false,      -- primary repo for contract defaults
+    created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
+    updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
+);
+
+-- source_type values:
+--   'remote'  = existing remote repo (GitHub, GitLab, etc) - has repository_url
+--   'local'   = existing local repo - has local_path
+--   'managed' = new repo created/managed by Makima daemon - gets repository_url after creation
+
+CREATE INDEX idx_chain_repositories_chain_id ON chain_repositories(chain_id);
+-- Only one primary per chain
+CREATE UNIQUE INDEX idx_chain_repositories_primary ON chain_repositories(chain_id) WHERE is_primary = true;
+
+-- Remove the old single repository fields from chains table (they're now in chain_repositories)
+ALTER TABLE chains DROP COLUMN IF EXISTS repository_url;
+ALTER TABLE chains DROP COLUMN IF EXISTS local_path;
-- 
cgit v1.2.3

