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:
@@ -50,6 +50,19 @@ func TestSQLiteMigrateUpDown(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// 2b. idx_subs_user_exp survives the 000024 subscriptions table rebuild
|
||||
// (SQLite table-rebuild migrations silently drop indexes unless recreated;
|
||||
// this guards against that regression — see 000024_invite_rewards.{up,down}.sql).
|
||||
var idxCount int
|
||||
if err := db.QueryRow(
|
||||
`SELECT COUNT(*) FROM sqlite_master WHERE type='index' AND name='idx_subs_user_exp'`,
|
||||
).Scan(&idxCount); err != nil {
|
||||
t.Fatalf("query idx_subs_user_exp: %v", err)
|
||||
}
|
||||
if idxCount != 1 {
|
||||
t.Errorf("idx_subs_user_exp count = %d, want 1 (index lost on subscriptions rebuild?)", idxCount)
|
||||
}
|
||||
|
||||
// 3. Seed: 3 plans + directory_version singleton.
|
||||
var plans int
|
||||
if err := db.QueryRow(`SELECT COUNT(*) FROM plans`).Scan(&plans); err != nil {
|
||||
|
||||
Reference in New Issue
Block a user