18 lines
655 B
SQL
18 lines
655 B
SQL
CREATE TABLE branches (
|
|
id INTEGER PRIMARY KEY,
|
|
name TEXT NOT NULL UNIQUE,
|
|
origin_event_id INTEGER NOT NULL,
|
|
head_event_id INTEGER NOT NULL,
|
|
chat_id TEXT,
|
|
created_at TEXT NOT NULL DEFAULT (datetime('now')),
|
|
is_active INTEGER NOT NULL DEFAULT 0
|
|
);
|
|
|
|
-- Exactly one row may have is_active = 1 at any time.
|
|
CREATE UNIQUE INDEX branches_active_idx ON branches(is_active) WHERE is_active = 1;
|
|
|
|
-- Bootstrap the main branch. origin_event_id=0 + head_event_id=0 are
|
|
-- placeholder seeds; the orchestrator updates head as new events land.
|
|
INSERT INTO branches (name, origin_event_id, head_event_id, is_active)
|
|
VALUES ('main', 0, 0, 1);
|