You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/sysdb_migrations/internal/migrations.ts
+81Lines changed: 81 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -6,6 +6,7 @@ export function allMigrations(
6
6
): ReadonlyArray<DBMigration>{
7
7
constuseListenNotify=opts?.useListenNotify??true;
8
8
constisCockroach=opts?.isCockroach??false;
9
+
constc=isCockroach ? '' : 'CONCURRENTLY';
9
10
return[
10
11
{
11
12
name: '20240123182943_schema',
@@ -432,5 +433,85 @@ export function allMigrations(
432
433
)`,
433
434
],
434
435
},
436
+
// Migrations below replace broad indexes on workflow_status with partial
437
+
// indexes targeted at individual query patterns (recovery, troubleshooting,
438
+
// dequeue, rate-limit count). Each index DDL runs CONCURRENTLY on Postgres
439
+
// for safe online deployment; CockroachDB ignores the keyword.
440
+
{
441
+
online: true,
442
+
pg: [`DROP INDEX ${c} IF EXISTS "${schemaName}"."idx_workflow_status_forked_from"`],
443
+
},
444
+
{
445
+
online: true,
446
+
pg: [
447
+
`CREATE INDEX ${c} IF NOT EXISTS "idx_workflow_status_forked_from" ON "${schemaName}"."workflow_status" ("forked_from") WHERE "forked_from" IS NOT NULL`,
448
+
],
449
+
},
450
+
{
451
+
online: true,
452
+
pg: [`DROP INDEX ${c} IF EXISTS "${schemaName}"."idx_workflow_status_parent_workflow_id"`],
453
+
},
454
+
{
455
+
online: true,
456
+
pg: [
457
+
`CREATE INDEX ${c} IF NOT EXISTS "idx_workflow_status_parent_workflow_id" ON "${schemaName}"."workflow_status" ("parent_workflow_id") WHERE "parent_workflow_id" IS NOT NULL`,
458
+
],
459
+
},
460
+
{
461
+
online: true,
462
+
pg: [`DROP INDEX ${c} IF EXISTS "${schemaName}"."workflow_status_executor_id_index"`],
463
+
},
464
+
{
465
+
online: true,
466
+
pg: [
467
+
`CREATE UNIQUE INDEX ${c} IF NOT EXISTS "uq_workflow_status_dedup_id" ON "${schemaName}"."workflow_status" ("queue_name", "deduplication_id") WHERE "deduplication_id" IS NOT NULL`,
468
+
],
469
+
},
470
+
{
471
+
// CockroachDB stores `UNIQUE (...)` constraints as unique indexes, so
472
+
// they must be dropped with DROP INDEX rather than ALTER TABLE DROP CONSTRAINT.
473
+
pg: isCockroach
474
+
? [`DROP INDEX IF EXISTS "${schemaName}"."uq_workflow_status_queue_name_dedup_id" CASCADE`]
475
+
: [
476
+
`ALTER TABLE "${schemaName}"."workflow_status" DROP CONSTRAINT IF EXISTS "uq_workflow_status_queue_name_dedup_id"`,
477
+
],
478
+
},
479
+
{
480
+
online: true,
481
+
pg: [
482
+
`CREATE INDEX ${c} IF NOT EXISTS "idx_workflow_status_pending" ON "${schemaName}"."workflow_status" ("created_at") WHERE "status" = 'PENDING'`,
483
+
],
484
+
},
485
+
{
486
+
online: true,
487
+
pg: [
488
+
`CREATE INDEX ${c} IF NOT EXISTS "idx_workflow_status_failed" ON "${schemaName}"."workflow_status" ("status", "created_at") WHERE "status" IN ('ERROR', 'CANCELLED', 'MAX_RECOVERY_ATTEMPTS_EXCEEDED')`,
489
+
],
490
+
},
491
+
{
492
+
online: true,
493
+
pg: [`DROP INDEX ${c} IF EXISTS "${schemaName}"."workflow_status_status_index"`],
494
+
},
495
+
{
496
+
online: true,
497
+
pg: [
498
+
`CREATE INDEX ${c} IF NOT EXISTS "idx_workflow_status_in_flight" ON "${schemaName}"."workflow_status" ("queue_name", "status", "priority", "created_at") WHERE "status" IN ('ENQUEUED', 'PENDING')`,
499
+
],
500
+
},
501
+
{
502
+
pg: [
503
+
`ALTER TABLE "${schemaName}"."workflow_status" ADD COLUMN IF NOT EXISTS "rate_limited" BOOLEAN NOT NULL DEFAULT FALSE`,
504
+
],
505
+
},
506
+
{
507
+
online: true,
508
+
pg: [
509
+
`CREATE INDEX ${c} IF NOT EXISTS "idx_workflow_status_rate_limited" ON "${schemaName}"."workflow_status" ("queue_name", "started_at_epoch_ms") WHERE "rate_limited" = TRUE`,
510
+
],
511
+
},
512
+
{
513
+
online: true,
514
+
pg: [`DROP INDEX ${c} IF EXISTS "${schemaName}"."idx_workflow_status_queue_status_started"`],
0 commit comments