-- 迁移：删除 ODS 层 settlement_records / recharge_settlements 的 settlelist jsonb 列
-- 原因：settlelist 与 payload 列数据重复（payload 存储完整 API 响应 JSON，已包含 settleList 对象）
-- 日期：2026-02-14
-- Prompt-ID: P20260214-023000
--
-- 前置条件：确认 DWD 加载逻辑已修改为从 payload 提取 settleList（而非直接读 settlelist 列）
-- 回滚：见文件末尾 ROLLBACK 部分

-- CHANGE: intent=删除冗余 settlelist 列，减少存储浪费
--         assumptions=payload 列已包含完整 settleList 数据，DWD 加载已改为从 payload 提取
--         edge_cases=历史数据中 payload 为 NULL 的行将丢失 settleList 信息
--         prompt=P20260214-023000

-- 1) settlement_records
ALTER TABLE billiards_ods.settlement_records DROP COLUMN IF EXISTS settlelist;

-- 2) recharge_settlements
ALTER TABLE billiards_ods.recharge_settlements DROP COLUMN IF EXISTS settlelist;

-- 验证 SQL
-- SELECT column_name FROM information_schema.columns
-- WHERE table_schema = 'billiards_ods'
--   AND table_name IN ('settlement_records', 'recharge_settlements')
--   AND column_name = 'settlelist';
-- 预期结果：0 行

-- ============================================================
-- ROLLBACK（回滚）
-- ============================================================
-- ALTER TABLE billiards_ods.settlement_records ADD COLUMN settlelist jsonb;
-- ALTER TABLE billiards_ods.recharge_settlements ADD COLUMN settlelist jsonb;
-- 注意：回滚后列数据为 NULL，需从 payload 中重新提取：
-- UPDATE billiards_ods.settlement_records SET settlelist = payload->'settleList' WHERE payload IS NOT NULL;
-- UPDATE billiards_ods.recharge_settlements SET settlelist = payload->'settleList' WHERE payload IS NOT NULL;
