-- 回滚迁移：删除新增的表和字段

-- 删除索引
DROP INDEX IF EXISTS idx_card_daily_usage_date;
DROP INDEX IF EXISTS idx_card_daily_usage_unique;
DROP INDEX IF EXISTS idx_package_usage_daily_record_date;
DROP INDEX IF EXISTS idx_package_usage_daily_record_unique;
DROP INDEX IF EXISTS idx_package_usage_next_reset_at;
DROP INDEX IF EXISTS idx_package_usage_master_usage_id;
DROP INDEX IF EXISTS idx_package_usage_priority;

-- 删除新表
DROP TABLE IF EXISTS tb_card_daily_usage;
DROP TABLE IF EXISTS tb_package_usage_daily_record;

-- 回滚 Carrier 表扩展
ALTER TABLE tb_carrier
DROP COLUMN IF EXISTS billing_day;

-- 回滚 IotCard 表扩展
ALTER TABLE tb_iot_card
DROP COLUMN IF EXISTS stop_reason,
DROP COLUMN IF EXISTS resumed_at,
DROP COLUMN IF EXISTS stopped_at,
DROP COLUMN IF EXISTS first_realname_at;

-- 回滚 PackageUsage 表扩展
ALTER TABLE tb_package_usage
DROP COLUMN IF EXISTS next_reset_at,
DROP COLUMN IF EXISTS last_reset_at,
DROP COLUMN IF EXISTS data_reset_cycle,
DROP COLUMN IF EXISTS pending_realname_activation,
DROP COLUMN IF EXISTS has_independent_expiry,
DROP COLUMN IF EXISTS master_usage_id,
DROP COLUMN IF EXISTS priority;

-- 回滚 Package 表扩展
ALTER TABLE tb_package
DROP COLUMN IF EXISTS enable_realname_activation,
DROP COLUMN IF EXISTS data_reset_cycle,
DROP COLUMN IF EXISTS duration_days,
DROP COLUMN IF EXISTS calendar_type;
