-- 057: 一次性修复所有数据库表缺少的字段
-- 对比 Python 模型与 SQL 初始化脚本的差异

-- ============================================
-- 1. audio_synthesis 表：添加审核相关字段
-- ============================================
ALTER TABLE aigcspace.audio_synthesis
ADD COLUMN IF NOT EXISTS review_status VARCHAR(20) DEFAULT 'pending',
ADD COLUMN IF NOT EXISTS reviewed_by INTEGER,
ADD COLUMN IF NOT EXISTS reviewed_at TIMESTAMP,
ADD COLUMN IF NOT EXISTS reject_reason VARCHAR(500);

COMMENT ON COLUMN aigcspace.audio_synthesis.review_status IS '审核状态: pending/approved/rejected';
COMMENT ON COLUMN aigcspace.audio_synthesis.reviewed_by IS '审核人ID';
COMMENT ON COLUMN aigcspace.audio_synthesis.reviewed_at IS '审核时间';
COMMENT ON COLUMN aigcspace.audio_synthesis.reject_reason IS '拒绝原因';

-- ============================================
-- 2. user_local_model_permission 表：对齐 Python 模型
--    Python 模型用 has_access/created_at/updated_at
--    SQL 用 granted_at/granted_by
--    保留旧字段，添加新字段
-- ============================================
ALTER TABLE aigcspace.user_local_model_permission
ADD COLUMN IF NOT EXISTS has_access BOOLEAN DEFAULT FALSE,
ADD COLUMN IF NOT EXISTS created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
ADD COLUMN IF NOT EXISTS updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP;
