@workflow/world-postgres 4.3.10 → 4.3.11
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/README.md +73 -1
- package/dist/connection-errors.d.ts +23 -0
- package/dist/connection-errors.d.ts.map +1 -0
- package/dist/connection-errors.js +45 -0
- package/dist/drizzle/schema.d.ts +102 -68
- package/dist/drizzle/schema.d.ts.map +1 -1
- package/dist/drizzle/schema.js +45 -22
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +26 -7
- package/dist/storage.d.ts.map +1 -1
- package/dist/storage.js +371 -315
- package/package.json +3 -3
- package/src/drizzle/migrations/0027_timestamps_with_time_zone.sql +131 -0
- package/src/drizzle/migrations/meta/_journal.json +7 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@workflow/world-postgres",
|
|
3
|
-
"version": "4.3.
|
|
3
|
+
"version": "4.3.11",
|
|
4
4
|
"description": "A reference World implementation based on PostgreSQL",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
"@workflow/errors": "4.2.2",
|
|
50
50
|
"@workflow/utils": "4.1.4",
|
|
51
51
|
"@workflow/world": "4.5.1",
|
|
52
|
-
"@workflow/world-local": "4.4.
|
|
52
|
+
"@workflow/world-local": "4.4.4"
|
|
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": "4.2.2",
|
|
62
62
|
"@workflow/tsconfig": "4.0.1",
|
|
63
|
-
"@workflow/world-testing": "4.1.
|
|
63
|
+
"@workflow/world-testing": "4.1.29"
|
|
64
64
|
},
|
|
65
65
|
"keywords": [],
|
|
66
66
|
"author": "",
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
-- Store every timestamp as `timestamp with time zone`.
|
|
2
|
+
--
|
|
3
|
+
-- These columns were `timestamp without time zone`. Values written from
|
|
4
|
+
-- JavaScript (`started_at`, `completed_at`, `retry_after`, `resume_at`,
|
|
5
|
+
-- `expired_at`, and `updated_at` once a row is updated) arrive as ISO strings
|
|
6
|
+
-- whose `Z` Postgres ignored, so they hold UTC wall times. Values from
|
|
7
|
+
-- `DEFAULT now()` (every `created_at`, `updated_at` until the row's first
|
|
8
|
+
-- update) were cast to the session's TimeZone, so they hold local wall times.
|
|
9
|
+
-- The World reads every value as UTC, so on a server outside UTC `createdAt`
|
|
10
|
+
-- was off by the server's offset.
|
|
11
|
+
--
|
|
12
|
+
-- 1. With the session in UTC, convert every column. Postgres 12+ does not
|
|
13
|
+
-- rewrite a table for this change while TimeZone is UTC, and each stored
|
|
14
|
+
-- value is taken as UTC, which is already right for every column written
|
|
15
|
+
-- from JavaScript.
|
|
16
|
+
-- 2. When the zone the defaults were written in is not UTC, move each value
|
|
17
|
+
-- that came from `now()` from that zone's wall time to the instant it
|
|
18
|
+
-- recorded. That zone is the session's TimeZone, or
|
|
19
|
+
-- `workflow.legacy_timezone` when set (for example
|
|
20
|
+
-- `options=-c workflow.legacy_timezone=Europe/Berlin` in the connection
|
|
21
|
+
-- string, or `ALTER DATABASE ... SET workflow.legacy_timezone = ...`), for
|
|
22
|
+
-- apps whose pool ran in a different session time zone than this migration.
|
|
23
|
+
-- Each value is moved by the offset that zone had on its own date, so rows
|
|
24
|
+
-- from winter and summer both come out right. The one exception is the hour
|
|
25
|
+
-- repeated when clocks go back (01:00-02:00 on the first Sunday of November
|
|
26
|
+
-- in America/Los_Angeles): a naive value from it is ambiguous and is taken
|
|
27
|
+
-- as standard time, so a row written in the first pass lands an hour late.
|
|
28
|
+
-- This rewrites every row it moves, about one rewrite of each table.
|
|
29
|
+
--
|
|
30
|
+
-- The repair must run once: applied again it would move the repaired values
|
|
31
|
+
-- by the offset a second time. The drizzle migrator takes no lock, so two
|
|
32
|
+
-- `bootstrap` processes started together can both apply this migration. Lock
|
|
33
|
+
-- the tables first, then skip everything if the columns are already converted.
|
|
34
|
+
-- Waiting for the locks queues every other query on these tables behind this
|
|
35
|
+
-- one, so give up after 10 seconds (unless the session set its own
|
|
36
|
+
-- `lock_timeout`) and let `bootstrap` fail rather than stall the World.
|
|
37
|
+
DO $$
|
|
38
|
+
DECLARE
|
|
39
|
+
session_zone text := current_setting('TimeZone');
|
|
40
|
+
session_lock_timeout text := current_setting('lock_timeout');
|
|
41
|
+
legacy_zone text := coalesce(
|
|
42
|
+
nullif(current_setting('workflow.legacy_timezone', true), ''),
|
|
43
|
+
current_setting('TimeZone')
|
|
44
|
+
);
|
|
45
|
+
BEGIN
|
|
46
|
+
IF session_lock_timeout = '0' THEN
|
|
47
|
+
PERFORM set_config('lock_timeout', '10s', true);
|
|
48
|
+
END IF;
|
|
49
|
+
LOCK TABLE
|
|
50
|
+
"workflow"."workflow_runs",
|
|
51
|
+
"workflow"."workflow_events",
|
|
52
|
+
"workflow"."workflow_steps",
|
|
53
|
+
"workflow"."workflow_hooks",
|
|
54
|
+
"workflow"."workflow_waits",
|
|
55
|
+
"workflow"."workflow_stream_chunks"
|
|
56
|
+
IN ACCESS EXCLUSIVE MODE;
|
|
57
|
+
PERFORM set_config('lock_timeout', session_lock_timeout, true);
|
|
58
|
+
IF (
|
|
59
|
+
SELECT atttypid FROM pg_attribute
|
|
60
|
+
WHERE attrelid = '"workflow"."workflow_runs"'::regclass
|
|
61
|
+
AND attname = 'created_at'
|
|
62
|
+
) = 'timestamptz'::regtype THEN
|
|
63
|
+
RETURN;
|
|
64
|
+
END IF;
|
|
65
|
+
|
|
66
|
+
PERFORM set_config('TimeZone', 'UTC', true);
|
|
67
|
+
|
|
68
|
+
ALTER TABLE "workflow"."workflow_runs"
|
|
69
|
+
ALTER COLUMN "created_at" TYPE timestamp with time zone,
|
|
70
|
+
ALTER COLUMN "updated_at" TYPE timestamp with time zone,
|
|
71
|
+
ALTER COLUMN "completed_at" TYPE timestamp with time zone,
|
|
72
|
+
ALTER COLUMN "started_at" TYPE timestamp with time zone,
|
|
73
|
+
ALTER COLUMN "expired_at" TYPE timestamp with time zone;
|
|
74
|
+
ALTER TABLE "workflow"."workflow_events"
|
|
75
|
+
ALTER COLUMN "created_at" TYPE timestamp with time zone;
|
|
76
|
+
ALTER TABLE "workflow"."workflow_steps"
|
|
77
|
+
ALTER COLUMN "started_at" TYPE timestamp with time zone,
|
|
78
|
+
ALTER COLUMN "completed_at" TYPE timestamp with time zone,
|
|
79
|
+
ALTER COLUMN "created_at" TYPE timestamp with time zone,
|
|
80
|
+
ALTER COLUMN "updated_at" TYPE timestamp with time zone,
|
|
81
|
+
ALTER COLUMN "retry_after" TYPE timestamp with time zone;
|
|
82
|
+
ALTER TABLE "workflow"."workflow_hooks"
|
|
83
|
+
ALTER COLUMN "created_at" TYPE timestamp with time zone;
|
|
84
|
+
ALTER TABLE "workflow"."workflow_waits"
|
|
85
|
+
ALTER COLUMN "resume_at" TYPE timestamp with time zone,
|
|
86
|
+
ALTER COLUMN "completed_at" TYPE timestamp with time zone,
|
|
87
|
+
ALTER COLUMN "created_at" TYPE timestamp with time zone,
|
|
88
|
+
ALTER COLUMN "updated_at" TYPE timestamp with time zone;
|
|
89
|
+
ALTER TABLE "workflow"."workflow_stream_chunks"
|
|
90
|
+
ALTER COLUMN "created_at" TYPE timestamp with time zone;
|
|
91
|
+
|
|
92
|
+
-- Only a shortcut: in any zone with no offset the `WHERE` clauses below
|
|
93
|
+
-- match no rows, so a UTC alias missing from this list is still correct.
|
|
94
|
+
IF lower(legacy_zone) NOT IN (
|
|
95
|
+
'utc', 'etc/utc', 'uct', 'etc/uct', 'universal', 'etc/universal',
|
|
96
|
+
'zulu', 'etc/zulu', 'gmt', 'etc/gmt', 'gmt0', 'etc/gmt0', 'gmt+0',
|
|
97
|
+
'etc/gmt+0', 'gmt-0', 'etc/gmt-0', 'greenwich', 'etc/greenwich'
|
|
98
|
+
) THEN
|
|
99
|
+
-- An `updated_at` equal to `created_at` came from the same `now()` as it
|
|
100
|
+
-- (the row was never updated). Every other `updated_at` is from JavaScript.
|
|
101
|
+
UPDATE "workflow"."workflow_runs" SET
|
|
102
|
+
"created_at" = timezone(legacy_zone, timezone('UTC', "created_at")),
|
|
103
|
+
"updated_at" = CASE WHEN "updated_at" = "created_at"
|
|
104
|
+
THEN timezone(legacy_zone, timezone('UTC', "updated_at"))
|
|
105
|
+
ELSE "updated_at" END
|
|
106
|
+
WHERE timezone(legacy_zone, timezone('UTC', "created_at")) <> "created_at";
|
|
107
|
+
UPDATE "workflow"."workflow_steps" SET
|
|
108
|
+
"created_at" = timezone(legacy_zone, timezone('UTC', "created_at")),
|
|
109
|
+
"updated_at" = CASE WHEN "updated_at" = "created_at"
|
|
110
|
+
THEN timezone(legacy_zone, timezone('UTC', "updated_at"))
|
|
111
|
+
ELSE "updated_at" END
|
|
112
|
+
WHERE timezone(legacy_zone, timezone('UTC', "created_at")) <> "created_at";
|
|
113
|
+
UPDATE "workflow"."workflow_waits" SET
|
|
114
|
+
"created_at" = timezone(legacy_zone, timezone('UTC', "created_at")),
|
|
115
|
+
"updated_at" = CASE WHEN "updated_at" = "created_at"
|
|
116
|
+
THEN timezone(legacy_zone, timezone('UTC', "updated_at"))
|
|
117
|
+
ELSE "updated_at" END
|
|
118
|
+
WHERE timezone(legacy_zone, timezone('UTC', "created_at")) <> "created_at";
|
|
119
|
+
UPDATE "workflow"."workflow_events" SET
|
|
120
|
+
"created_at" = timezone(legacy_zone, timezone('UTC', "created_at"))
|
|
121
|
+
WHERE timezone(legacy_zone, timezone('UTC', "created_at")) <> "created_at";
|
|
122
|
+
UPDATE "workflow"."workflow_hooks" SET
|
|
123
|
+
"created_at" = timezone(legacy_zone, timezone('UTC', "created_at"))
|
|
124
|
+
WHERE timezone(legacy_zone, timezone('UTC', "created_at")) <> "created_at";
|
|
125
|
+
UPDATE "workflow"."workflow_stream_chunks" SET
|
|
126
|
+
"created_at" = timezone(legacy_zone, timezone('UTC', "created_at"))
|
|
127
|
+
WHERE timezone(legacy_zone, timezone('UTC', "created_at")) <> "created_at";
|
|
128
|
+
END IF;
|
|
129
|
+
|
|
130
|
+
PERFORM set_config('TimeZone', session_zone, true);
|
|
131
|
+
END $$;
|