Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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,
}
`;

Expand Down Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
1 change: 1 addition & 0 deletions packages/metaschema-modules/pgpm.plan
Original file line number Diff line number Diff line change
Expand Up @@ -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 <devin@cognition.ai> # 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 <devin@cognition.ai> # 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 <devin@cognition.ai> # add graph_execution_module config table for partitioned execution state + merkle tree time-travel debugging
Original file line number Diff line number Diff line change
@@ -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;
Original file line number Diff line number Diff line change
@@ -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;
Loading