-- 手工上线后的数据库校验脚本
-- 用途：确认 schema 版本、核心基础数据、敏感配置是否已正确导入

SELECT version, dirty
FROM schema_migrations;

SELECT 'tb_permission' AS table_name, COUNT(*) AS row_count FROM tb_permission
UNION ALL
SELECT 'tb_role', COUNT(*) FROM tb_role
UNION ALL
SELECT 'tb_role_permission', COUNT(*) FROM tb_role_permission
UNION ALL
SELECT 'tb_carrier', COUNT(*) FROM tb_carrier
UNION ALL
SELECT 'tb_commission_withdrawal_setting', COUNT(*) FROM tb_commission_withdrawal_setting
UNION ALL
SELECT 'tb_polling_config', COUNT(*) FROM tb_polling_config
UNION ALL
SELECT 'tb_polling_concurrency_config', COUNT(*) FROM tb_polling_concurrency_config
UNION ALL
SELECT 'tb_polling_alert_rule', COUNT(*) FROM tb_polling_alert_rule
UNION ALL
SELECT 'tb_data_cleanup_config', COUNT(*) FROM tb_data_cleanup_config
UNION ALL
SELECT 'tb_wechat_config', COUNT(*) FROM tb_wechat_config;

SELECT table_name
FROM information_schema.tables
WHERE table_schema = 'public'
  AND table_name IN ('tb_data_usage_record', 'tb_card_replacement_record_legacy')
ORDER BY table_name;

SELECT COUNT(*) AS super_admin_count
FROM tb_account
WHERE user_type = 1;
