|
| 1 | +-- Deploy schemas/metaschema_modules_public/tables/graph_execution_module/table to pg |
| 2 | + |
| 3 | +-- requires: schemas/metaschema_modules_public/schema |
| 4 | +-- requires: schemas/metaschema_modules_public/tables/graph_module/table |
| 5 | + |
| 6 | +BEGIN; |
| 7 | + |
| 8 | +CREATE TABLE metaschema_modules_public.graph_execution_module ( |
| 9 | + id uuid PRIMARY KEY DEFAULT uuidv7(), |
| 10 | + database_id uuid NOT NULL, |
| 11 | + |
| 12 | + -- Schema references (if uuid_nil, resolved from schema name or default) |
| 13 | + schema_id uuid NOT NULL DEFAULT uuid_nil(), |
| 14 | + private_schema_id uuid NOT NULL DEFAULT uuid_nil(), |
| 15 | + |
| 16 | + -- Optional schema name overrides (used when schema IDs are not provided) |
| 17 | + public_schema_name text, |
| 18 | + private_schema_name text, |
| 19 | + |
| 20 | + -- Reference to the graph module this execution module operates against. |
| 21 | + -- The execution module resolves definition tables (graphs, merkle store) |
| 22 | + -- from the linked graph_module at provision time. |
| 23 | + graph_module_id uuid NOT NULL, |
| 24 | + |
| 25 | + -- Scope: determines the security level for this module instance. |
| 26 | + -- Can differ from graph_module scope (e.g., platform definitions + entity executions). |
| 27 | + scope text NOT NULL DEFAULT 'app', |
| 28 | + |
| 29 | + -- Table name prefix. Auto-derived from scope by the trigger when empty. |
| 30 | + prefix text NOT NULL DEFAULT '', |
| 31 | + |
| 32 | + -- Generated table IDs (populated by BEFORE INSERT trigger) |
| 33 | + -- Execution state tables (partitioned by time) |
| 34 | + executions_table_id uuid NOT NULL DEFAULT uuid_nil(), |
| 35 | + outputs_table_id uuid NOT NULL DEFAULT uuid_nil(), |
| 36 | + node_states_table_id uuid NOT NULL DEFAULT uuid_nil(), |
| 37 | + |
| 38 | + |
| 39 | + -- Configurable table names (bare names without scope prefix). |
| 40 | + -- The trigger prepends the scope prefix automatically. |
| 41 | + executions_table_name text NOT NULL DEFAULT 'function_graph_executions', |
| 42 | + outputs_table_name text NOT NULL DEFAULT 'function_graph_execution_outputs', |
| 43 | + node_states_table_name text NOT NULL DEFAULT 'function_graph_execution_node_states', |
| 44 | + |
| 45 | + -- API routing (get-or-create: if set, schema is added to this API; if NULL, no API is added) |
| 46 | + api_name text, |
| 47 | + private_api_name text, |
| 48 | + |
| 49 | + -- Entity table for RLS and billing attribution. |
| 50 | + -- When set, executions are scoped to the entity (org, app) for billing/metering. |
| 51 | + entity_table_id uuid NULL, |
| 52 | + |
| 53 | + -- Configurable security policies (NULL = use defaults based on scope). |
| 54 | + policies jsonb NULL, |
| 55 | + |
| 56 | + -- Per-table provisions overrides from blueprint config. |
| 57 | + -- Keys are table keys (executions, outputs, node_states). |
| 58 | + provisions jsonb NULL, |
| 59 | + |
| 60 | + -- Default permissions: permission names auto-granted to new members. |
| 61 | + default_permissions text[] DEFAULT NULL, |
| 62 | + |
| 63 | + -- Timestamps |
| 64 | + created_at timestamptz NOT NULL DEFAULT now(), |
| 65 | + |
| 66 | + -- Constraints |
| 67 | + CONSTRAINT graph_execution_module_db_fkey FOREIGN KEY (database_id) REFERENCES metaschema_public.database (id) ON DELETE CASCADE, |
| 68 | + CONSTRAINT graph_execution_module_schema_fkey FOREIGN KEY (schema_id) REFERENCES metaschema_public.schema (id) ON DELETE CASCADE, |
| 69 | + CONSTRAINT graph_execution_module_private_schema_fkey FOREIGN KEY (private_schema_id) REFERENCES metaschema_public.schema (id) ON DELETE CASCADE, |
| 70 | + CONSTRAINT graph_execution_module_graph_module_fkey FOREIGN KEY (graph_module_id) REFERENCES metaschema_modules_public.graph_module (id) ON DELETE CASCADE, |
| 71 | + CONSTRAINT graph_execution_module_executions_table_fkey FOREIGN KEY (executions_table_id) REFERENCES metaschema_public.table (id) ON DELETE CASCADE, |
| 72 | + CONSTRAINT graph_execution_module_outputs_table_fkey FOREIGN KEY (outputs_table_id) REFERENCES metaschema_public.table (id) ON DELETE CASCADE, |
| 73 | + CONSTRAINT graph_execution_module_node_states_table_fkey FOREIGN KEY (node_states_table_id) REFERENCES metaschema_public.table (id) ON DELETE CASCADE, |
| 74 | + |
| 75 | + CONSTRAINT graph_execution_module_entity_table_fkey FOREIGN KEY (entity_table_id) REFERENCES metaschema_public.table (id) ON DELETE CASCADE |
| 76 | +); |
| 77 | + |
| 78 | +CREATE INDEX graph_execution_module_database_id_idx ON metaschema_modules_public.graph_execution_module ( database_id ); |
| 79 | + |
| 80 | +-- One execution module per (database, scope, prefix). |
| 81 | +CREATE UNIQUE INDEX graph_execution_module_unique_scope ON metaschema_modules_public.graph_execution_module ( database_id, scope, prefix ); |
| 82 | + |
| 83 | +COMMIT; |
0 commit comments