@workflow/world-postgres 5.0.0-beta.20 → 5.0.0-beta.21
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/dist/drizzle/schema.d.ts +1 -1
- package/dist/drizzle/schema.d.ts.map +1 -1
- package/dist/drizzle/schema.js +6 -6
- package/dist/storage.d.ts.map +1 -1
- package/dist/storage.js +154 -137
- package/package.json +7 -7
- package/src/drizzle/migrations/0015_move_enums_to_workflow_schema.sql +75 -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": "5.0.0-beta.
|
|
3
|
+
"version": "5.0.0-beta.21",
|
|
4
4
|
"description": "A reference World implementation based on PostgreSQL",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -46,10 +46,10 @@
|
|
|
46
46
|
"pg": "8.20.0",
|
|
47
47
|
"ulid": "~3.0.1",
|
|
48
48
|
"zod": "~4.3.6",
|
|
49
|
-
"@workflow/errors": "5.0.0-beta.
|
|
50
|
-
"@workflow/utils": "5.0.0-beta.
|
|
51
|
-
"@workflow/world": "5.0.0-beta.
|
|
52
|
-
"@workflow/world-local": "5.0.0-beta.
|
|
49
|
+
"@workflow/errors": "5.0.0-beta.9",
|
|
50
|
+
"@workflow/utils": "5.0.0-beta.5",
|
|
51
|
+
"@workflow/world": "5.0.0-beta.15",
|
|
52
|
+
"@workflow/world-local": "5.0.0-beta.23"
|
|
53
53
|
},
|
|
54
54
|
"devDependencies": {
|
|
55
55
|
"@testcontainers/postgresql": "11.12.0",
|
|
@@ -57,9 +57,9 @@
|
|
|
57
57
|
"@types/pg": "8.20.0",
|
|
58
58
|
"drizzle-kit": "0.31.9",
|
|
59
59
|
"vitest": "^4.0.18",
|
|
60
|
-
"@workflow/errors": "5.0.0-beta.
|
|
60
|
+
"@workflow/errors": "5.0.0-beta.9",
|
|
61
61
|
"@workflow/tsconfig": "5.0.0-beta.0",
|
|
62
|
-
"@workflow/world-testing": "5.0.0-beta.
|
|
62
|
+
"@workflow/world-testing": "5.0.0-beta.27"
|
|
63
63
|
},
|
|
64
64
|
"keywords": [],
|
|
65
65
|
"author": "",
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
DO $$
|
|
2
|
+
DECLARE
|
|
3
|
+
enum_name text;
|
|
4
|
+
public_enum regtype;
|
|
5
|
+
workflow_enum regtype;
|
|
6
|
+
is_used_by_workflow_columns boolean;
|
|
7
|
+
has_dependents_outside_workflow_tables boolean;
|
|
8
|
+
BEGIN
|
|
9
|
+
FOREACH enum_name IN ARRAY ARRAY['status', 'step_status', 'wait_status'] LOOP
|
|
10
|
+
public_enum := to_regtype(format('public.%I', enum_name));
|
|
11
|
+
workflow_enum := to_regtype(format('workflow.%I', enum_name));
|
|
12
|
+
|
|
13
|
+
-- Nothing to migrate when the legacy public enum does not exist, or when
|
|
14
|
+
-- the enum has already been moved to the workflow schema.
|
|
15
|
+
IF public_enum IS NULL OR workflow_enum IS NOT NULL THEN
|
|
16
|
+
CONTINUE;
|
|
17
|
+
END IF;
|
|
18
|
+
|
|
19
|
+
-- Only move enums that are actually used by workflow table columns.
|
|
20
|
+
-- pg_depend has an index on referenced objects, so this lookup is based
|
|
21
|
+
-- on the enum type OID instead of scanning user data or workflow rows.
|
|
22
|
+
SELECT EXISTS (
|
|
23
|
+
SELECT 1
|
|
24
|
+
FROM pg_depend dependency
|
|
25
|
+
JOIN pg_class dependent_table
|
|
26
|
+
ON dependency.classid = 'pg_class'::regclass AND dependency.objid = dependent_table.oid
|
|
27
|
+
JOIN pg_namespace dependent_table_schema
|
|
28
|
+
ON dependent_table_schema.oid = dependent_table.relnamespace
|
|
29
|
+
WHERE dependency.refclassid = 'pg_type'::regclass
|
|
30
|
+
AND dependency.refobjid = public_enum::oid
|
|
31
|
+
AND dependency.objsubid > 0
|
|
32
|
+
AND dependency.deptype != 'i'
|
|
33
|
+
AND dependent_table_schema.nspname = 'workflow'
|
|
34
|
+
) INTO is_used_by_workflow_columns;
|
|
35
|
+
|
|
36
|
+
IF NOT is_used_by_workflow_columns THEN
|
|
37
|
+
CONTINUE;
|
|
38
|
+
END IF;
|
|
39
|
+
|
|
40
|
+
/*
|
|
41
|
+
pg_depend is Postgres' dependency graph.
|
|
42
|
+
|
|
43
|
+
We use it here as a safety check before moving the enum object itself.
|
|
44
|
+
A normal workflow-owned enum has only workflow table-column dependents,
|
|
45
|
+
so ALTER TYPE ... SET SCHEMA is a fast metadata change.
|
|
46
|
+
|
|
47
|
+
If anything outside workflow tables also depends on this enum, moving it
|
|
48
|
+
would silently rename that user's public enum to workflow.<enum_name>.
|
|
49
|
+
In that case, leave the enum in public, warn, and continue so this cleanup
|
|
50
|
+
migration does not block later migrations.
|
|
51
|
+
*/
|
|
52
|
+
SELECT EXISTS (
|
|
53
|
+
SELECT 1
|
|
54
|
+
FROM pg_depend dependency
|
|
55
|
+
LEFT JOIN pg_class dependent_table
|
|
56
|
+
ON dependency.classid = 'pg_class'::regclass AND dependency.objid = dependent_table.oid
|
|
57
|
+
LEFT JOIN pg_namespace dependent_table_schema
|
|
58
|
+
ON dependent_table_schema.oid = dependent_table.relnamespace
|
|
59
|
+
WHERE dependency.refclassid = 'pg_type'::regclass
|
|
60
|
+
AND dependency.refobjid = public_enum::oid
|
|
61
|
+
AND dependency.deptype != 'i'
|
|
62
|
+
AND NOT (
|
|
63
|
+
dependency.classid = 'pg_class'::regclass
|
|
64
|
+
AND dependent_table_schema.nspname = 'workflow'
|
|
65
|
+
)
|
|
66
|
+
) INTO has_dependents_outside_workflow_tables;
|
|
67
|
+
|
|
68
|
+
IF has_dependents_outside_workflow_tables THEN
|
|
69
|
+
RAISE WARNING 'Skipping move of public.% to workflow schema because objects outside workflow tables depend on it', enum_name;
|
|
70
|
+
CONTINUE;
|
|
71
|
+
END IF;
|
|
72
|
+
|
|
73
|
+
EXECUTE format('ALTER TYPE public.%I SET SCHEMA workflow', enum_name);
|
|
74
|
+
END LOOP;
|
|
75
|
+
END $$;
|
|
@@ -106,6 +106,13 @@
|
|
|
106
106
|
"when": 1780185600000,
|
|
107
107
|
"tag": "0014_add_attr_set_event_unique_index",
|
|
108
108
|
"breakpoints": true
|
|
109
|
+
},
|
|
110
|
+
{
|
|
111
|
+
"idx": 15,
|
|
112
|
+
"version": "7",
|
|
113
|
+
"when": 1782691200000,
|
|
114
|
+
"tag": "0015_move_enums_to_workflow_schema",
|
|
115
|
+
"breakpoints": true
|
|
109
116
|
}
|
|
110
117
|
]
|
|
111
118
|
}
|