From 283c96a97e9c35eefa8858484aa9ad7e8524b054 Mon Sep 17 00:00:00 2001 From: Dan Lynch Date: Tue, 16 Jun 2026 07:34:56 +0000 Subject: [PATCH 1/2] feat: add graph_execution_module config table Adds the graph_execution_module table to metaschema-modules, matching constructive-db's pgpm-modules/metaschema-modules. This table stores config for partitioned graph execution state tables (executions, outputs, node_states) that are generated by the graph_execution_module generator at provision time. --- .../tables/graph_execution_module/table.sql | 83 +++++++++++++++++++ packages/metaschema-modules/pgpm.plan | 1 + .../tables/graph_execution_module/table.sql | 7 ++ .../tables/graph_execution_module/table.sql | 7 ++ 4 files changed, 98 insertions(+) create mode 100644 packages/metaschema-modules/deploy/schemas/metaschema_modules_public/tables/graph_execution_module/table.sql create mode 100644 packages/metaschema-modules/revert/schemas/metaschema_modules_public/tables/graph_execution_module/table.sql create mode 100644 packages/metaschema-modules/verify/schemas/metaschema_modules_public/tables/graph_execution_module/table.sql diff --git a/packages/metaschema-modules/deploy/schemas/metaschema_modules_public/tables/graph_execution_module/table.sql b/packages/metaschema-modules/deploy/schemas/metaschema_modules_public/tables/graph_execution_module/table.sql new file mode 100644 index 00000000..6d25ccf1 --- /dev/null +++ b/packages/metaschema-modules/deploy/schemas/metaschema_modules_public/tables/graph_execution_module/table.sql @@ -0,0 +1,83 @@ +-- Deploy schemas/metaschema_modules_public/tables/graph_execution_module/table to pg + +-- requires: schemas/metaschema_modules_public/schema +-- requires: schemas/metaschema_modules_public/tables/graph_module/table + +BEGIN; + +CREATE TABLE metaschema_modules_public.graph_execution_module ( + id uuid PRIMARY KEY DEFAULT uuidv7(), + database_id uuid NOT NULL, + + -- Schema references (if uuid_nil, resolved from schema name or default) + schema_id uuid NOT NULL DEFAULT uuid_nil(), + private_schema_id uuid NOT NULL DEFAULT uuid_nil(), + + -- Optional schema name overrides (used when schema IDs are not provided) + public_schema_name text, + private_schema_name text, + + -- Reference to the graph module this execution module operates against. + -- The execution module resolves definition tables (graphs, merkle store) + -- from the linked graph_module at provision time. + graph_module_id uuid NOT NULL, + + -- Scope: determines the security level for this module instance. + -- Can differ from graph_module scope (e.g., platform definitions + entity executions). + scope text NOT NULL DEFAULT 'app', + + -- Table name prefix. Auto-derived from scope by the trigger when empty. + prefix text NOT NULL DEFAULT '', + + -- Generated table IDs (populated by BEFORE INSERT trigger) + -- Execution state tables (partitioned by time) + executions_table_id uuid NOT NULL DEFAULT uuid_nil(), + outputs_table_id uuid NOT NULL DEFAULT uuid_nil(), + node_states_table_id uuid NOT NULL DEFAULT uuid_nil(), + + + -- Configurable table names (bare names without scope prefix). + -- The trigger prepends the scope prefix automatically. + executions_table_name text NOT NULL DEFAULT 'function_graph_executions', + outputs_table_name text NOT NULL DEFAULT 'function_graph_execution_outputs', + node_states_table_name text NOT NULL DEFAULT 'function_graph_execution_node_states', + + -- API routing (get-or-create: if set, schema is added to this API; if NULL, no API is added) + api_name text, + private_api_name text, + + -- Entity table for RLS and billing attribution. + -- When set, executions are scoped to the entity (org, app) for billing/metering. + entity_table_id uuid NULL, + + -- Configurable security policies (NULL = use defaults based on scope). + policies jsonb NULL, + + -- Per-table provisions overrides from blueprint config. + -- Keys are table keys (executions, outputs, node_states). + provisions jsonb NULL, + + -- Default permissions: permission names auto-granted to new members. + default_permissions text[] DEFAULT NULL, + + -- Timestamps + created_at timestamptz NOT NULL DEFAULT now(), + + -- Constraints + CONSTRAINT graph_execution_module_db_fkey FOREIGN KEY (database_id) REFERENCES metaschema_public.database (id) ON DELETE CASCADE, + CONSTRAINT graph_execution_module_schema_fkey FOREIGN KEY (schema_id) REFERENCES metaschema_public.schema (id) ON DELETE CASCADE, + CONSTRAINT graph_execution_module_private_schema_fkey FOREIGN KEY (private_schema_id) REFERENCES metaschema_public.schema (id) ON DELETE CASCADE, + CONSTRAINT graph_execution_module_graph_module_fkey FOREIGN KEY (graph_module_id) REFERENCES metaschema_modules_public.graph_module (id) ON DELETE CASCADE, + CONSTRAINT graph_execution_module_executions_table_fkey FOREIGN KEY (executions_table_id) REFERENCES metaschema_public.table (id) ON DELETE CASCADE, + CONSTRAINT graph_execution_module_outputs_table_fkey FOREIGN KEY (outputs_table_id) REFERENCES metaschema_public.table (id) ON DELETE CASCADE, + CONSTRAINT graph_execution_module_node_states_table_fkey FOREIGN KEY (node_states_table_id) REFERENCES metaschema_public.table (id) ON DELETE CASCADE, + + CONSTRAINT graph_execution_module_entity_table_fkey FOREIGN KEY (entity_table_id) REFERENCES metaschema_public.table (id) ON DELETE CASCADE +); + +CREATE INDEX graph_execution_module_database_id_idx ON metaschema_modules_public.graph_execution_module ( database_id ); + +-- One execution module per (database, scope, prefix). +CREATE UNIQUE INDEX graph_execution_module_unique_scope ON metaschema_modules_public.graph_execution_module ( database_id, scope, prefix ); + +COMMIT; diff --git a/packages/metaschema-modules/pgpm.plan b/packages/metaschema-modules/pgpm.plan index 7ca82d0d..cd4e3b61 100644 --- a/packages/metaschema-modules/pgpm.plan +++ b/packages/metaschema-modules/pgpm.plan @@ -66,3 +66,4 @@ schemas/metaschema_modules_public/tables/user_credentials_module/table [schemas/ schemas/metaschema_modules_public/tables/user_settings_module/table [schemas/metaschema_modules_public/schema] 2026-05-28T00:00:00Z devin # add user_settings_module for extensible per-user preferences (1:1 with users) schemas/metaschema_modules_public/tables/i18n_module/table [schemas/metaschema_modules_public/schema] 2026-05-28T00:00:00Z devin # add i18n_module config table for internationalization settings +schemas/metaschema_modules_public/tables/graph_execution_module/table [schemas/metaschema_modules_public/schema schemas/metaschema_modules_public/tables/graph_module/table] 2026-06-12T00:00:00Z devin # add graph_execution_module config table for partitioned execution state + merkle tree time-travel debugging diff --git a/packages/metaschema-modules/revert/schemas/metaschema_modules_public/tables/graph_execution_module/table.sql b/packages/metaschema-modules/revert/schemas/metaschema_modules_public/tables/graph_execution_module/table.sql new file mode 100644 index 00000000..676b8c92 --- /dev/null +++ b/packages/metaschema-modules/revert/schemas/metaschema_modules_public/tables/graph_execution_module/table.sql @@ -0,0 +1,7 @@ +-- Revert schemas/metaschema_modules_public/tables/graph_execution_module/table from pg + +BEGIN; + +DROP TABLE metaschema_modules_public.graph_execution_module; + +COMMIT; diff --git a/packages/metaschema-modules/verify/schemas/metaschema_modules_public/tables/graph_execution_module/table.sql b/packages/metaschema-modules/verify/schemas/metaschema_modules_public/tables/graph_execution_module/table.sql new file mode 100644 index 00000000..c50a56e2 --- /dev/null +++ b/packages/metaschema-modules/verify/schemas/metaschema_modules_public/tables/graph_execution_module/table.sql @@ -0,0 +1,7 @@ +-- Verify schemas/metaschema_modules_public/tables/graph_execution_module/table on pg + +BEGIN; + +SELECT verify_table ('metaschema_modules_public.graph_execution_module'); + +ROLLBACK; From 4211535febc4c15ba5727dc2c5733babd4cc57a5 Mon Sep 17 00:00:00 2001 From: Dan Lynch Date: Tue, 16 Jun 2026 08:00:33 +0000 Subject: [PATCH 2/2] test: update snapshots for graph_execution_module --- .../__tests__/__snapshots__/modules.test.ts.snap | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/packages/metaschema-modules/__tests__/__snapshots__/modules.test.ts.snap b/packages/metaschema-modules/__tests__/__snapshots__/modules.test.ts.snap index fb44006a..5b92fe11 100644 --- a/packages/metaschema-modules/__tests__/__snapshots__/modules.test.ts.snap +++ b/packages/metaschema-modules/__tests__/__snapshots__/modules.test.ts.snap @@ -20,6 +20,7 @@ exports[`db_meta_modules should have all expected module tables 1`] = ` "events_module", "function_invocation_module", "function_module", + "graph_execution_module", "graph_module", "hierarchy_module", "i18n_module", @@ -58,8 +59,8 @@ exports[`db_meta_modules should have all expected module tables 1`] = ` exports[`db_meta_modules should verify all module tables exist in metaschema_modules_public schema 1`] = ` { - "moduleTablesCount": 49, - "totalTables": 56, + "moduleTablesCount": 50, + "totalTables": 57, } `; @@ -126,16 +127,17 @@ exports[`db_meta_modules should verify emails_module table structure 1`] = ` exports[`db_meta_modules should verify module table structures have database_id foreign keys 1`] = ` { - "constraintCount": 303414, + "constraintCount": 303415, } `; exports[`db_meta_modules should verify module tables have proper foreign key relationships 1`] = ` { - "constraintCount": 452630, + "constraintCount": 452638, "foreignTables": [ "database", "field", + "graph_module", "merkle_store_module", "schema", "table",