Skip to content

Commit 0f5eb41

Browse files
authored
Add New Migrations (#326)
Also updated the variable names to follow Java naming conventions
1 parent 6bbf842 commit 0f5eb41

1 file changed

Lines changed: 61 additions & 28 deletions

File tree

transact/src/main/java/dev/dbos/transact/migrations/MigrationManager.java

Lines changed: 61 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -216,24 +216,29 @@ public static List<String> getMigrations(String schema) {
216216
Objects.requireNonNull(schema);
217217
var migrations =
218218
List.of(
219-
migration1,
220-
migration2,
221-
migration3,
222-
migration4,
223-
migration5,
224-
migration6,
225-
migration7,
226-
migration8,
227-
migration9,
228-
migration10,
229-
migration11,
230-
migration12,
231-
migration13,
232-
migration14);
219+
MIGRATION_1,
220+
MIGRATION_2,
221+
MIGRATION_3,
222+
MIGRATION_4,
223+
MIGRATION_5,
224+
MIGRATION_6,
225+
MIGRATION_7,
226+
MIGRATION_8,
227+
MIGRATION_9,
228+
MIGRATION_10,
229+
MIGRATION_11,
230+
MIGRATION_12,
231+
MIGRATION_13,
232+
MIGRATION_14,
233+
MIGRATION_15,
234+
MIGRATION_16,
235+
MIGRATION_17,
236+
MIGRATION_18,
237+
MIGRATION_19);
233238
return migrations.stream().map(m -> m.formatted(schema)).toList();
234239
}
235240

236-
static final String migration1 =
241+
static final String MIGRATION_1 =
237242
"""
238243
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
239244
@@ -355,28 +360,28 @@ PRIMARY KEY (service_name, workflow_fn_name, key)
355360
);
356361
""";
357362

358-
static final String migration2 =
363+
static final String MIGRATION_2 =
359364
"""
360365
ALTER TABLE "%1$s".workflow_status ADD COLUMN queue_partition_key TEXT;
361366
""";
362367

363-
static final String migration3 =
368+
static final String MIGRATION_3 =
364369
"""
365370
create index "idx_workflow_status_queue_status_started" on "%1$s"."workflow_status" ("queue_name", "status", "started_at_epoch_ms")
366371
""";
367372

368-
static final String migration4 =
373+
static final String MIGRATION_4 =
369374
"""
370375
ALTER TABLE "%1$s".workflow_status ADD COLUMN forked_from TEXT;
371376
CREATE INDEX "idx_workflow_status_forked_from" ON "%1$s"."workflow_status" ("forked_from");
372377
""";
373378

374-
static final String migration5 =
379+
static final String MIGRATION_5 =
375380
"""
376381
ALTER TABLE "%1$s".operation_outputs ADD COLUMN started_at_epoch_ms BIGINT, ADD COLUMN completed_at_epoch_ms BIGINT;
377382
""";
378383

379-
static final String migration6 =
384+
static final String MIGRATION_6 =
380385
"""
381386
CREATE TABLE "%1$s".workflow_events_history (
382387
workflow_uuid TEXT NOT NULL,
@@ -390,18 +395,18 @@ FOREIGN KEY (workflow_uuid) REFERENCES "%1$s".workflow_status(workflow_uuid)
390395
ALTER TABLE "%1$s".streams ADD COLUMN function_id INT4 NOT NULL DEFAULT 0;
391396
""";
392397

393-
static final String migration7 =
398+
static final String MIGRATION_7 =
394399
"""
395400
ALTER TABLE "%1$s"."workflow_status" ADD COLUMN "owner_xid" VARCHAR(40) DEFAULT NULL
396401
""";
397402

398-
static final String migration8 =
403+
static final String MIGRATION_8 =
399404
"""
400405
ALTER TABLE "%1$s"."workflow_status" ADD COLUMN "parent_workflow_id" TEXT DEFAULT NULL;
401406
CREATE INDEX "idx_workflow_status_parent_workflow_id" ON "%1$s"."workflow_status" ("parent_workflow_id");
402407
""";
403408

404-
static final String migration9 =
409+
static final String MIGRATION_9 =
405410
"""
406411
CREATE TABLE "%1$s".workflow_schedules (
407412
schedule_id TEXT PRIMARY KEY,
@@ -414,7 +419,7 @@ FOREIGN KEY (workflow_uuid) REFERENCES "%1$s".workflow_status(workflow_uuid)
414419
);
415420
""";
416421

417-
static final String migration10 =
422+
static final String MIGRATION_10 =
418423
"""
419424
DO $$
420425
BEGIN
@@ -429,7 +434,7 @@ IF NOT EXISTS (
429434
END $$;
430435
""";
431436

432-
static final String migration11 =
437+
static final String MIGRATION_11 =
433438
"""
434439
ALTER TABLE "%1$s"."workflow_status" ADD COLUMN "serialization" TEXT DEFAULT NULL;
435440
ALTER TABLE "%1$s"."notifications" ADD COLUMN "serialization" TEXT DEFAULT NULL;
@@ -439,13 +444,13 @@ IF NOT EXISTS (
439444
ALTER TABLE "%1$s"."streams" ADD COLUMN "serialization" TEXT DEFAULT NULL;
440445
""";
441446

442-
static final String migration12 =
447+
static final String MIGRATION_12 =
443448
"""
444449
ALTER TABLE "%1$s"."notifications" ADD COLUMN "consumed" BOOLEAN NOT NULL DEFAULT FALSE;
445450
CREATE INDEX "idx_notifications" ON "%1$s"."notifications" ("destination_uuid", "topic");
446451
""";
447452

448-
static final String migration13 =
453+
static final String MIGRATION_13 =
449454
"""
450455
CREATE TABLE "%1$s".application_versions (
451456
version_id TEXT NOT NULL PRIMARY KEY,
@@ -455,7 +460,7 @@ created_at BIGINT NOT NULL DEFAULT (EXTRACT(epoch FROM now()) * 1000.0)::bigint
455460
);
456461
""";
457462

458-
static final String migration14 =
463+
static final String MIGRATION_14 =
459464
"""
460465
CREATE FUNCTION "%1$s".enqueue_workflow(
461466
workflow_name TEXT,
@@ -559,4 +564,32 @@ ON CONFLICT (workflow_uuid)
559564
END;
560565
$$ LANGUAGE plpgsql;
561566
""";
567+
568+
static final String MIGRATION_15 =
569+
"""
570+
ALTER TABLE "%1$s".workflow_schedules ADD COLUMN "last_fired_at" TEXT DEFAULT NULL;
571+
ALTER TABLE "%1$s".workflow_schedules ADD COLUMN "automatic_backfill" BOOLEAN NOT NULL DEFAULT FALSE;
572+
ALTER TABLE "%1$s".workflow_schedules ADD COLUMN "cron_timezone" TEXT DEFAULT NULL;
573+
""";
574+
575+
static final String MIGRATION_16 =
576+
"""
577+
ALTER TABLE "%1$s"."workflow_status" ADD COLUMN "delay_until_epoch_ms" BIGINT DEFAULT NULL;
578+
CREATE INDEX "idx_workflow_status_delayed" ON "%1$s"."workflow_status" ("delay_until_epoch_ms") WHERE status = 'DELAYED';
579+
""";
580+
581+
static final String MIGRATION_17 =
582+
"""
583+
ALTER TABLE "%1$s".workflow_schedules ADD COLUMN "queue_name" TEXT DEFAULT NULL;
584+
""";
585+
586+
static final String MIGRATION_18 =
587+
"""
588+
ALTER TABLE "%1$s"."workflow_status" ADD COLUMN "was_forked_from" BOOLEAN NOT NULL DEFAULT FALSE;
589+
""";
590+
591+
static final String MIGRATION_19 =
592+
"""
593+
CREATE INDEX "idx_operation_outputs_completed_at_function_name" ON "%1$s"."operation_outputs" ("completed_at_epoch_ms", "function_name");
594+
""";
562595
}

0 commit comments

Comments
 (0)