fix(server/migrate): 000024 sqlite 重建 subscriptions 后补回 idx_subs_user_exp 索引 + 回归断言

000024 迁移重建 subscriptions 表(source CHECK 扩容)时未重新创建
idx_subs_user_exp(user_id, expires_at)索引,导致 SQLite(生产 pangolin1
实际驱动)上订阅按 user_id/expires_at 查询退化为全表扫描。up/down 均补回
CREATE INDEX,并在 TestSQLiteMigrateUpDown 里加断言防止再次静默丢失。

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
wangjia
2026-07-13 07:08:26 +08:00
parent 9b858c5224
commit 52b5e90d92
3 changed files with 15 additions and 0 deletions
@@ -13,6 +13,7 @@ INSERT INTO subscriptions_old SELECT id,user_id,plan_id,expires_at,source,create
FROM subscriptions WHERE source IN ('trial','code','pay');
DROP TABLE subscriptions;
ALTER TABLE subscriptions_old RENAME TO subscriptions;
CREATE INDEX idx_subs_user_exp ON subscriptions (user_id, expires_at);
DROP TABLE reward_claims;
DROP TABLE referrals;
@@ -47,3 +47,4 @@ INSERT INTO subscriptions_new (id,user_id,plan_id,expires_at,source,created_at)
SELECT id,user_id,plan_id,expires_at,source,created_at FROM subscriptions;
DROP TABLE subscriptions;
ALTER TABLE subscriptions_new RENAME TO subscriptions;
CREATE INDEX idx_subs_user_exp ON subscriptions (user_id, expires_at);