-- ============================================================
-- 表7：system_causal_chains（Layer 1 · 因果链表）
-- 用途：存储从冰朔原话到工程落点的完整推导链
-- 每条决策都有从冰朔原话到工程落点的完整因果链条
-- ============================================================

CREATE TABLE IF NOT EXISTS system_causal_chains (
  chain_id          VARCHAR(32)   PRIMARY KEY,
  title             VARCHAR(256)  NOT NULL,
  description       TEXT,
  ice_original      TEXT          NOT NULL,      -- 冰朔原话
  engineering_path  TEXT          NOT NULL,      -- 工程落点
  verification      TEXT,                         -- 验证方式
  status            VARCHAR(16)   NOT NULL DEFAULT 'active'
                    CHECK (status IN ('active', 'deprecated')),
  version           VARCHAR(16)   NOT NULL,
  created_at        TIMESTAMP     NOT NULL DEFAULT CURRENT_TIMESTAMP,
  updated_at        TIMESTAMP     NOT NULL DEFAULT CURRENT_TIMESTAMP
);

CREATE INDEX IF NOT EXISTS idx_scc_status ON system_causal_chains(status);
CREATE INDEX IF NOT EXISTS idx_scc_version ON system_causal_chains(version);
