this repo has no description
10
fork

Configure Feed

Select the types of activity you want to include in your feed.

fix(db): create profile_takedown index after additive migrations

CREATE INDEX IF NOT EXISTS profile_takedown ON profile(takedown_status)
ran inside SCHEMA_STATEMENTS, before applyAdditiveMigrations had a
chance to ALTER TABLE in the new takedown_status column on existing
databases. The index creation aborted with "no such column:
takedown_status", which short-circuited migrate() entirely and broke
every withDb() caller (visible as a SQL_INPUT_ERROR during login).

Move column-dependent indexes into POST_MIGRATION_INDEX_STATEMENTS,
applied after applyAdditiveMigrations so pre-existing tables gain the
column first.

Made-with: Cursor

+11
+11
lib/db.ts
··· 163 163 )`, 164 164 `CREATE INDEX IF NOT EXISTS report_status_target ON report(status, target_did)`, 165 165 `CREATE INDEX IF NOT EXISTS report_dedup ON report(target_did, reporter_ip_hash, reason, created_at)`, 166 + ]; 167 + 168 + /** 169 + * Indexes that depend on additively-migrated columns. Created AFTER 170 + * `applyAdditiveMigrations` so existing databases that pre-date the 171 + * column have a chance to gain it before the index references it. 172 + */ 173 + const POST_MIGRATION_INDEX_STATEMENTS: string[] = [ 166 174 /** 167 175 * Hot-path index for excluding taken-down profiles from public reads. 168 176 * The vast majority of rows have NULL `takedown_status`, so a partial ··· 272 280 await c.execute(stmt); 273 281 } 274 282 await applyAdditiveMigrations(c); 283 + for (const stmt of POST_MIGRATION_INDEX_STATEMENTS) { 284 + await c.execute(stmt); 285 + } 275 286 _migrated = true; 276 287 })(); 277 288 return _migrationPromise;