@workflow/world-postgres 5.0.0-beta.32 → 5.0.0-beta.33

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.0-beta.32",
3
+ "version": "5.0.0-beta.33",
4
4
  "description": "A reference World implementation based on PostgreSQL",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -48,8 +48,8 @@
48
48
  "zod": "~4.3.6",
49
49
  "@workflow/errors": "5.0.0-beta.16",
50
50
  "@workflow/utils": "5.0.0-beta.8",
51
- "@workflow/world": "5.0.0-beta.25",
52
- "@workflow/world-local": "5.0.0-beta.34"
51
+ "@workflow/world": "5.0.0-beta.26",
52
+ "@workflow/world-local": "5.0.0-beta.35"
53
53
  },
54
54
  "devDependencies": {
55
55
  "@testcontainers/postgresql": "11.12.0",
@@ -60,7 +60,7 @@
60
60
  "vitest": "^4.1.10",
61
61
  "@workflow/errors": "5.0.0-beta.16",
62
62
  "@workflow/tsconfig": "5.0.0-beta.0",
63
- "@workflow/world-testing": "5.0.0-beta.40"
63
+ "@workflow/world-testing": "5.0.0-beta.41"
64
64
  },
65
65
  "keywords": [],
66
66
  "author": "",
@@ -0,0 +1,74 @@
1
+ -- Event ids become per-run slot positions (`evnt_` + a zero-padded decimal),
2
+ -- so an id is only unique together with its run. Runs created before this keep
3
+ -- their globally-unique ULIDs, which the composite key also admits.
4
+ --
5
+ -- LOCKING. Replacing a primary key takes ACCESS EXCLUSIVE on
6
+ -- `workflow.workflow_events`, which blocks reads as well as writes, and the
7
+ -- migrator runs every pending migration in one transaction, so the lock is held
8
+ -- until all of them commit. Building the new key's index under that lock is the
9
+ -- part that grows with the table. On an empty or modest table this is
10
+ -- instantaneous and needs no thought.
11
+ --
12
+ -- On a large existing table, build the index first, outside the migrator, and
13
+ -- this migration adopts it instead of building its own:
14
+ --
15
+ -- CREATE UNIQUE INDEX CONCURRENTLY "workflow_events_run_id_id_idx"
16
+ -- ON "workflow"."workflow_events" ("run_id", "id");
17
+ --
18
+ -- `CONCURRENTLY` cannot appear in this file: Postgres rejects it inside a
19
+ -- transaction block. Run it by hand, confirm the index came out valid, then
20
+ -- migrate. The branch below picks it up, and the exclusive lock then covers
21
+ -- only a catalog update rather than a full build. Adopting an index renames it
22
+ -- to the constraint's name, so it ends up as `workflow_events_run_id_id_pk`
23
+ -- either way and the two paths leave the same schema behind.
24
+ -- Bound the wait for that lock. A pending ACCESS EXCLUSIVE queues ahead of
25
+ -- every lock request that arrives after it, so waiting on one long-running
26
+ -- reader stalls all traffic to the table for as long as the wait lasts. Ten
27
+ -- seconds of that is a blip; an unbounded wait is an outage. Failing instead
28
+ -- leaves the migration unapplied and retryable. Raise it by hand for a
29
+ -- maintenance window.
30
+ --
31
+ -- `SET LOCAL` lasts for the transaction, and the migrator runs every pending
32
+ -- migration in one, so a migration that follows this one in the same batch
33
+ -- inherits the timeout.
34
+ SET LOCAL lock_timeout = '10s';--> statement-breakpoint
35
+ ALTER TABLE "workflow"."workflow_events" DROP CONSTRAINT "workflow_events_pkey";--> statement-breakpoint
36
+ DO $$
37
+ BEGIN
38
+ IF EXISTS (
39
+ SELECT 1
40
+ FROM pg_class c
41
+ JOIN pg_namespace n ON n.oid = c.relnamespace
42
+ JOIN pg_index i ON i.indexrelid = c.oid
43
+ WHERE n.nspname = 'workflow'
44
+ AND c.relname = 'workflow_events_run_id_id_idx'
45
+ AND c.relkind = 'i'
46
+ AND i.indisunique
47
+ AND i.indisvalid
48
+ ) THEN
49
+ ALTER TABLE "workflow"."workflow_events"
50
+ ADD CONSTRAINT "workflow_events_run_id_id_pk"
51
+ PRIMARY KEY USING INDEX "workflow_events_run_id_id_idx";
52
+ ELSE
53
+ -- A `CREATE UNIQUE INDEX CONCURRENTLY` that failed leaves an index of this
54
+ -- name behind marked invalid. The branch above rejects it, and the key
55
+ -- built here is a different index under a different name, so without this
56
+ -- the invalid one would survive the migration: never used by a plan, still
57
+ -- maintained on every insert. Dropping it also makes a second attempt at
58
+ -- the concurrent build possible without a manual cleanup first.
59
+ DROP INDEX IF EXISTS "workflow"."workflow_events_run_id_id_idx";
60
+ ALTER TABLE "workflow"."workflow_events"
61
+ ADD CONSTRAINT "workflow_events_run_id_id_pk" PRIMARY KEY ("run_id","id");
62
+ END IF;
63
+ END $$;--> statement-breakpoint
64
+ -- Redundant once the primary key leads with `run_id`: that index serves every
65
+ -- by-run lookup and range scan this one did, so keeping it only costs a second
66
+ -- write per event on the table's hottest path.
67
+ DROP INDEX IF EXISTS "workflow"."workflow_events_run_id_index";--> statement-breakpoint
68
+ -- One row per slot-numbered run. Its absence is the "this run predates slots"
69
+ -- signal, so no backfill: existing runs stay on ULIDs for the rest of their
70
+ -- lives. A marker only: positions are allocated by the insert that occupies
71
+ -- them, read from the event log itself.
72
+ CREATE TABLE IF NOT EXISTS "workflow"."workflow_event_slots" (
73
+ "run_id" varchar PRIMARY KEY NOT NULL
74
+ );
@@ -134,6 +134,13 @@
134
134
  "when": 1785619990000,
135
135
  "tag": "0018_add_hook_token_retention",
136
136
  "breakpoints": true
137
+ },
138
+ {
139
+ "idx": 19,
140
+ "version": "7",
141
+ "when": 1786060800000,
142
+ "tag": "0019_add_event_slots",
143
+ "breakpoints": true
137
144
  }
138
145
  ]
139
146
  }