Skip to content

Commit 50d7a91

Browse files
authored
[codex] Cut storage over to FumaDB (#817)
* Cut storage over to FumaDB * Move DB setup out of core SDK * Tighten plugin FumaDB table typing * Move table collection into createExecutor * Remove FumaDB helper casts * Use FumaDB directly in plugin stores * Restore cloud database scripts * Restore cloud migration history * Restore OpenAPI OAuth coverage * Restore connection SDK coverage * Restore SDK credential behavior coverage * Split cloud database layers * Use socket-backed cloud test database * Fix FumaDB build and worker test resolution * Remove obsolete local migration embedding * Restore OpenAPI source query coverage * Move plugin storage onto FumaDB * Add FumaDB table policy interceptors * Harden scoped FumaDB policy tests * Keep FumaDB query context off SDK surface * Move FumaDB policy test into FumaDB package * Update FumaDB cutover migration handling * Use cloud migrations for PGlite setup * Restore FumaDB cutover coverage * Build vendored FumaDB for package previews
1 parent 2846e8c commit 50d7a91

281 files changed

Lines changed: 24023 additions & 13663 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.oxfmtrc.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@
77
"dist",
88
"integrationsdotsh",
99
"node_modules",
10+
"packages/core/fumadb",
1011
"bun.lock",
1112
"*.tsbuildinfo",
1213
"executor-*.tgz",
13-
"**/routeTree.gen.ts"
14+
"**/routeTree.gen.ts",
15+
"apps/cloud/src/services/executor-schema.ts"
1416
]
1517
}

.oxlintrc.jsonc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@
118118
"dist/",
119119
"integrationsdotsh/",
120120
"node_modules/",
121+
"packages/core/fumadb/",
121122
"bun.lock",
122123
"*.tsbuildinfo",
123124
"executor-*.tgz",

apps/cloud/drizzle.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { defineConfig } from "drizzle-kit";
44
// migrate) ignores it. Default to the local PGlite socket started by
55
// `bun run dev:db`; override via `DATABASE_URL` for prod studio sessions.
66
// drizzle-kit uses node-postgres (`pg`) for studio and the `ssl` option in
7-
// dbCredentials doesn't reliably reach the pool append `sslmode=require`
7+
// dbCredentials doesn't reliably reach the pool - append `sslmode=require`
88
// directly to the URL instead, which `pg` honours.
99
const DEFAULT_DEV_URL = "postgresql://postgres:postgres@127.0.0.1:5433/postgres";
1010

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
CREATE TABLE IF NOT EXISTS "private_executor_cloud_settings" (
2+
"id" varchar(255) PRIMARY KEY NOT NULL,
3+
"version" varchar(255) DEFAULT '1.0.0' NOT NULL
4+
);
5+
--> statement-breakpoint
6+
INSERT INTO "private_executor_cloud_settings" ("id", "version")
7+
VALUES ('default', '1.0.0')
8+
ON CONFLICT ("id") DO UPDATE SET "version" = excluded."version";
9+
--> statement-breakpoint
10+
ALTER TABLE "credential_binding" ADD COLUMN IF NOT EXISTS "secret_scope_id" text;
11+
--> statement-breakpoint
12+
ALTER TABLE "blob" ADD COLUMN IF NOT EXISTS "row_id" varchar(255);
13+
--> statement-breakpoint
14+
ALTER TABLE "blob" ADD COLUMN IF NOT EXISTS "id" varchar(255);
15+
--> statement-breakpoint
16+
UPDATE "blob"
17+
SET
18+
"id" = COALESCE("id", '[' || to_json("namespace")::text || ',' || to_json("key")::text || ']'),
19+
"row_id" = COALESCE("row_id", 'legacy_' || md5("namespace" || chr(31) || "key"))
20+
WHERE "id" IS NULL OR "row_id" IS NULL;
21+
--> statement-breakpoint
22+
ALTER TABLE "blob" ALTER COLUMN "id" SET NOT NULL;
23+
--> statement-breakpoint
24+
ALTER TABLE "blob" ALTER COLUMN "row_id" SET NOT NULL;
25+
--> statement-breakpoint
26+
DO $$
27+
BEGIN
28+
IF EXISTS (
29+
SELECT 1 FROM pg_constraint
30+
WHERE conrelid = 'public.blob'::regclass
31+
AND conname = 'blob_namespace_key_pk'
32+
) THEN
33+
ALTER TABLE "blob" DROP CONSTRAINT "blob_namespace_key_pk";
34+
END IF;
35+
36+
IF NOT EXISTS (
37+
SELECT 1 FROM pg_constraint
38+
WHERE conrelid = 'public.blob'::regclass
39+
AND conname = 'blob_pkey'
40+
) THEN
41+
ALTER TABLE "blob" ADD CONSTRAINT "blob_pkey" PRIMARY KEY ("row_id");
42+
END IF;
43+
END $$;
44+
--> statement-breakpoint
45+
CREATE UNIQUE INDEX IF NOT EXISTS "blob_id_uidx" ON "blob" USING btree ("id");
46+
--> statement-breakpoint
47+
DO $$
48+
DECLARE
49+
table_name text;
50+
legacy_pk_name text;
51+
new_pk_name text;
52+
new_unique_name text;
53+
BEGIN
54+
FOREACH table_name IN ARRAY ARRAY[
55+
'connection',
56+
'credential_binding',
57+
'definition',
58+
'graphql_operation',
59+
'graphql_source',
60+
'graphql_source_header',
61+
'graphql_source_query_param',
62+
'mcp_binding',
63+
'mcp_source',
64+
'mcp_source_header',
65+
'mcp_source_query_param',
66+
'oauth2_session',
67+
'openapi_operation',
68+
'openapi_source',
69+
'openapi_source_header',
70+
'openapi_source_query_param',
71+
'openapi_source_spec_fetch_header',
72+
'openapi_source_spec_fetch_query_param',
73+
'secret',
74+
'source',
75+
'tool',
76+
'tool_policy',
77+
'workos_vault_metadata'
78+
]
79+
LOOP
80+
legacy_pk_name := table_name || '_scope_id_id_pk';
81+
new_pk_name := table_name || '_pkey';
82+
new_unique_name := table_name || '_scope_id_id_uidx';
83+
84+
EXECUTE format('ALTER TABLE %I ADD COLUMN IF NOT EXISTS "row_id" varchar(255)', table_name);
85+
EXECUTE format(
86+
'UPDATE %I SET "row_id" = COALESCE("row_id", %L || md5("scope_id" || chr(31) || "id")) WHERE "row_id" IS NULL',
87+
table_name,
88+
'legacy_'
89+
);
90+
EXECUTE format('ALTER TABLE %I ALTER COLUMN "row_id" SET NOT NULL', table_name);
91+
92+
IF EXISTS (
93+
SELECT 1 FROM pg_constraint
94+
WHERE conrelid = format('public.%I', table_name)::regclass
95+
AND conname = legacy_pk_name
96+
) THEN
97+
EXECUTE format('ALTER TABLE %I DROP CONSTRAINT %I', table_name, legacy_pk_name);
98+
END IF;
99+
100+
IF NOT EXISTS (
101+
SELECT 1 FROM pg_constraint
102+
WHERE conrelid = format('public.%I', table_name)::regclass
103+
AND conname = new_pk_name
104+
) THEN
105+
EXECUTE format('ALTER TABLE %I ADD CONSTRAINT %I PRIMARY KEY ("row_id")', table_name, new_pk_name);
106+
END IF;
107+
108+
EXECUTE format(
109+
'CREATE UNIQUE INDEX IF NOT EXISTS %I ON %I USING btree ("scope_id", "id")',
110+
new_unique_name,
111+
table_name
112+
);
113+
END LOOP;
114+
END $$;

0 commit comments

Comments
 (0)