diff --git a/server/internal/store/sqlite_migrate_test.go b/server/internal/store/sqlite_migrate_test.go index 7f37920..0323a91 100644 --- a/server/internal/store/sqlite_migrate_test.go +++ b/server/internal/store/sqlite_migrate_test.go @@ -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 { diff --git a/server/migrations/sqlite/000024_invite_rewards.down.sql b/server/migrations/sqlite/000024_invite_rewards.down.sql index bc06792..b644e9c 100644 --- a/server/migrations/sqlite/000024_invite_rewards.down.sql +++ b/server/migrations/sqlite/000024_invite_rewards.down.sql @@ -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; diff --git a/server/migrations/sqlite/000024_invite_rewards.up.sql b/server/migrations/sqlite/000024_invite_rewards.up.sql index 3088246..b66e5a6 100644 --- a/server/migrations/sqlite/000024_invite_rewards.up.sql +++ b/server/migrations/sqlite/000024_invite_rewards.up.sql @@ -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);