@workflow/world-postgres 5.0.5 → 5.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@workflow/world-postgres",
3
- "version": "5.0.5",
3
+ "version": "5.1.0",
4
4
  "description": "A reference World implementation based on PostgreSQL",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -38,11 +38,11 @@
38
38
  "./migrations/*.sql": "./src/drizzle/migrations/*.sql"
39
39
  },
40
40
  "dependencies": {
41
- "@vercel/queue": "0.8.0",
42
- "@workflow/errors": "5.0.5",
41
+ "@vercel/queue": "0.10.0",
42
+ "@workflow/errors": "5.1.0",
43
43
  "@workflow/utils": "5.0.2",
44
- "@workflow/world": "5.0.5",
45
- "@workflow/world-local": "5.1.2",
44
+ "@workflow/world": "5.1.0",
45
+ "@workflow/world-local": "5.2.0",
46
46
  "cbor-x": "1.6.0",
47
47
  "dotenv": "17.3.1",
48
48
  "drizzle-orm": "0.45.2",
@@ -55,9 +55,9 @@
55
55
  "@testcontainers/postgresql": "11.12.0",
56
56
  "@types/node": "22.19.0",
57
57
  "@types/pg": "8.20.0",
58
- "@workflow/errors": "5.0.5",
58
+ "@workflow/errors": "5.1.0",
59
59
  "@workflow/tsconfig": "5.0.0",
60
- "@workflow/world-testing": "5.0.6",
60
+ "@workflow/world-testing": "5.0.7",
61
61
  "drizzle-kit": "0.31.9",
62
62
  "typescript": "^6.0.3",
63
63
  "undici": "7.30.0",
@@ -0,0 +1,42 @@
1
+ -- Atomic `start({ hook })` admission: one immutable accept-or-reject decision
2
+ -- per candidate run, written in the transaction that creates an accepted run.
3
+ -- Rows older than a candidate's 24h window are deleted as admissions go.
4
+ --
5
+ -- Required even with start Hooks off: every Hook insert writes `claims_token`.
6
+ -- The column additions and the unique index take locks that queue every
7
+ -- other query on workflow_runs and workflow_hooks behind them, so give up
8
+ -- after 10 seconds (unless the session set its own `lock_timeout`) and leave
9
+ -- the migration unapplied and retryable rather than stall the World. The
10
+ -- setting lasts for the migrator's transaction.
11
+ DO $$
12
+ BEGIN
13
+ IF current_setting('lock_timeout') = '0' THEN
14
+ PERFORM set_config('lock_timeout', '10s', true);
15
+ END IF;
16
+ END $$;
17
+ --> statement-breakpoint
18
+ CREATE TABLE IF NOT EXISTS "workflow"."workflow_start_hook_admissions" (
19
+ "run_id" varchar PRIMARY KEY NOT NULL,
20
+ "token" varchar NOT NULL,
21
+ "decision" varchar NOT NULL,
22
+ "conflicting_run_id" varchar,
23
+ "created_at" timestamp with time zone DEFAULT now() NOT NULL
24
+ );
25
+ --> statement-breakpoint
26
+ CREATE INDEX IF NOT EXISTS "workflow_start_hook_admissions_created_at_index" ON "workflow"."workflow_start_hook_admissions" USING btree ("created_at");
27
+ --> statement-breakpoint
28
+ -- A run's start Hook is an ordinary row in workflow_hooks, written by its
29
+ -- admission. Every Hook row written from here on claims its token, and
30
+ -- claiming rows are unique per token, so two admissions racing for one token,
31
+ -- or an admission and another run's createHook, conflict on the insert. Rows
32
+ -- written before this migration do not claim their token, so the index cannot
33
+ -- fail on existing data.
34
+ ALTER TABLE "workflow"."workflow_hooks" ADD COLUMN IF NOT EXISTS "claims_token" boolean DEFAULT false NOT NULL;
35
+ --> statement-breakpoint
36
+ CREATE UNIQUE INDEX IF NOT EXISTS "workflow_hooks_token_claim_unique" ON "workflow"."workflow_hooks" USING btree ("token") WHERE "claims_token";
37
+ --> statement-breakpoint
38
+ -- The start Hook a run was admitted with (without its metadata), echoed on
39
+ -- the run. Last, so the index build above has scanned workflow_hooks before
40
+ -- this takes workflow_runs' lock.
41
+ ALTER TABLE "workflow"."workflow_runs" ADD COLUMN IF NOT EXISTS "start_hook_cbor" bytea;
42
+
@@ -0,0 +1,4 @@
1
+ -- The `jobPrefix` of the World that created each run, which scopes startup
2
+ -- recovery. `IF NOT EXISTS` because two `bootstrap` processes started together
3
+ -- can both apply a migration.
4
+ ALTER TABLE "workflow"."workflow_runs" ADD COLUMN IF NOT EXISTS "job_prefix" varchar;
@@ -197,6 +197,20 @@
197
197
  "when": 1790035200000,
198
198
  "tag": "0027_timestamps_with_time_zone",
199
199
  "breakpoints": true
200
+ },
201
+ {
202
+ "idx": 28,
203
+ "version": "7",
204
+ "when": 1790121600000,
205
+ "tag": "0028_add_start_hook_admissions",
206
+ "breakpoints": true
207
+ },
208
+ {
209
+ "idx": 29,
210
+ "version": "7",
211
+ "when": 1790208000000,
212
+ "tag": "0029_add_run_job_prefix",
213
+ "breakpoints": true
200
214
  }
201
215
  ]
202
216
  }