

-- 创建配置变更历史表
CREATE TABLE IF NOT EXISTS config_history (
    id TEXT PRIMARY KEY,
    config_id TEXT NOT NULL,
    config_key TEXT NOT NULL,
    old_value TEXT,
    new_value TEXT,
    action TEXT NOT NULL CHECK (action IN ('CREATE', 'UPDATE', 'DELETE')),
    changed_at TEXT NOT NULL DEFAULT (datetime('now')),
    changed_by TEXT
);

-- 创建配置历史索引
CREATE INDEX IF NOT EXISTS idx_config_history_config_key ON config_history(config_key);
CREATE INDEX IF NOT EXISTS idx_config_history_changed_at ON config_history(changed_at);
END;
END;
END;
