* A failed CONCURRENTLY build leaves an INVALID index that `IF NOT EXISTS` * silently skips forever — surface it (warn only; the migration committed).
()
| 213 | * silently skips forever — surface it (warn only; the migration committed). |
| 214 | */ |
| 215 | async function warnOnInvalidIndexes(): Promise<void> { |
| 216 | try { |
| 217 | const rows = await client` |
| 218 | SELECT n.nspname AS schema, c.relname AS index |
| 219 | FROM pg_index i |
| 220 | JOIN pg_class c ON c.oid = i.indexrelid |
| 221 | JOIN pg_namespace n ON n.oid = c.relnamespace |
| 222 | WHERE NOT i.indisvalid |
| 223 | ` |
| 224 | for (const row of rows) { |
| 225 | console.warn( |
| 226 | `WARN: invalid index ${row.schema}.${row.index} — a CONCURRENTLY build failed partway. ` + |
| 227 | 'Drop and rebuild it; IF NOT EXISTS will keep skipping it.' |
| 228 | ) |
| 229 | } |
| 230 | } catch (checkError) { |
| 231 | console.warn('WARN: could not check for invalid indexes.', checkError) |
| 232 | } |
| 233 | } |
| 234 | |
| 235 | /** |
| 236 | * Unlock errors are swallowed: the session lock auto-releases on disconnect, |