@pgpm/metaschema-modules 0.26.0 → 0.26.1

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.
Files changed (40) hide show
  1. package/Makefile +1 -1
  2. package/deploy/schemas/metaschema_modules_public/tables/agent_module/table.sql +77 -0
  3. package/deploy/schemas/metaschema_modules_public/tables/billing_module/table.sql +5 -0
  4. package/deploy/schemas/metaschema_modules_public/tables/compute_log_module/table.sql +44 -0
  5. package/deploy/schemas/metaschema_modules_public/tables/db_usage_module/table.sql +52 -0
  6. package/deploy/schemas/metaschema_modules_public/tables/entity_type_provision/table.sql +99 -24
  7. package/deploy/schemas/metaschema_modules_public/tables/function_module/table.sql +68 -0
  8. package/deploy/schemas/metaschema_modules_public/tables/graph_module/table.sql +73 -0
  9. package/deploy/schemas/metaschema_modules_public/tables/inference_log_module/table.sql +7 -2
  10. package/deploy/schemas/metaschema_modules_public/tables/merkle_store_module/table.sql +50 -0
  11. package/deploy/schemas/metaschema_modules_public/tables/namespace_module/table.sql +65 -0
  12. package/deploy/schemas/metaschema_modules_public/tables/storage_log_module/table.sql +44 -0
  13. package/deploy/schemas/metaschema_modules_public/tables/storage_module/table.sql +5 -6
  14. package/deploy/schemas/metaschema_modules_public/tables/transfer_log_module/table.sql +44 -0
  15. package/deploy/schemas/metaschema_modules_public/tables/user_auth_module/table.sql +1 -1
  16. package/metaschema-modules.control +1 -1
  17. package/package.json +3 -3
  18. package/pgpm.plan +9 -0
  19. package/revert/schemas/metaschema_modules_public/tables/agent_module/table.sql +7 -0
  20. package/revert/schemas/metaschema_modules_public/tables/compute_log_module/table.sql +3 -0
  21. package/revert/schemas/metaschema_modules_public/tables/db_usage_module/table.sql +3 -0
  22. package/revert/schemas/metaschema_modules_public/tables/function_module/table.sql +7 -0
  23. package/revert/schemas/metaschema_modules_public/tables/graph_module/table.sql +7 -0
  24. package/revert/schemas/metaschema_modules_public/tables/merkle_store_module/table.sql +7 -0
  25. package/revert/schemas/metaschema_modules_public/tables/namespace_module/table.sql +7 -0
  26. package/revert/schemas/metaschema_modules_public/tables/storage_log_module/table.sql +3 -0
  27. package/revert/schemas/metaschema_modules_public/tables/transfer_log_module/table.sql +3 -0
  28. package/sql/{metaschema-modules--0.15.5.sql → metaschema-modules--0.26.0.sql} +563 -22
  29. package/verify/schemas/metaschema_modules_public/tables/agent_module/table.sql +7 -0
  30. package/verify/schemas/metaschema_modules_public/tables/billing_module/table.sql +2 -0
  31. package/verify/schemas/metaschema_modules_public/tables/compute_log_module/table.sql +9 -0
  32. package/verify/schemas/metaschema_modules_public/tables/db_usage_module/table.sql +10 -0
  33. package/verify/schemas/metaschema_modules_public/tables/function_module/table.sql +7 -0
  34. package/verify/schemas/metaschema_modules_public/tables/graph_module/table.sql +7 -0
  35. package/verify/schemas/metaschema_modules_public/tables/inference_log_module/table.sql +3 -2
  36. package/verify/schemas/metaschema_modules_public/tables/merkle_store_module/table.sql +7 -0
  37. package/verify/schemas/metaschema_modules_public/tables/namespace_module/table.sql +14 -0
  38. package/verify/schemas/metaschema_modules_public/tables/profiles_module/table.sql +2 -1
  39. package/verify/schemas/metaschema_modules_public/tables/storage_log_module/table.sql +10 -0
  40. package/verify/schemas/metaschema_modules_public/tables/transfer_log_module/table.sql +10 -0
package/Makefile CHANGED
@@ -1,5 +1,5 @@
1
1
  EXTENSION = metaschema-modules
2
- DATA = sql/metaschema-modules--0.15.5.sql
2
+ DATA = sql/metaschema-modules--0.26.0.sql
3
3
 
4
4
  PG_CONFIG = pg_config
5
5
  PGXS := $(shell $(PG_CONFIG) --pgxs)
@@ -0,0 +1,77 @@
1
+ -- Deploy schemas/metaschema_modules_public/tables/agent_module/table to pg
2
+
3
+ -- requires: schemas/metaschema_modules_public/schema
4
+
5
+ BEGIN;
6
+
7
+ CREATE TABLE metaschema_modules_public.agent_module (
8
+ id uuid PRIMARY KEY DEFAULT uuidv7(),
9
+ database_id uuid NOT NULL,
10
+
11
+ -- Schema references (if uuid_nil, resolved from schema name or default)
12
+ schema_id uuid NOT NULL DEFAULT uuid_nil(),
13
+ private_schema_id uuid NOT NULL DEFAULT uuid_nil(),
14
+
15
+ -- Generated table IDs (populated by the generator)
16
+ thread_table_id uuid NOT NULL DEFAULT uuid_nil(),
17
+ message_table_id uuid NOT NULL DEFAULT uuid_nil(),
18
+ task_table_id uuid NOT NULL DEFAULT uuid_nil(),
19
+ prompts_table_id uuid NOT NULL DEFAULT uuid_nil(),
20
+ knowledge_table_id uuid DEFAULT NULL,
21
+
22
+ -- Table names (input to the generator)
23
+ thread_table_name text NOT NULL DEFAULT 'agent_thread',
24
+ message_table_name text NOT NULL DEFAULT 'agent_message',
25
+ task_table_name text NOT NULL DEFAULT 'agent_task',
26
+ prompts_table_name text NOT NULL DEFAULT 'agent_prompt',
27
+ knowledge_table_name text NOT NULL DEFAULT 'agent_knowledge',
28
+
29
+ -- Feature flags
30
+ has_knowledge boolean NOT NULL DEFAULT false,
31
+
32
+ -- API routing (get-or-create: if set, schema is added to this API; if NULL, no API is added)
33
+ api_name text DEFAULT 'agent',
34
+
35
+ -- Multi-tenant scope
36
+ membership_type int DEFAULT NULL,
37
+
38
+ -- Entity table for RLS (NULL for app-level, entity table for entity-scoped)
39
+ entity_table_id uuid NULL,
40
+
41
+ -- Configurable security policies (NULL = use defaults based on membership_type)
42
+ policies jsonb NULL,
43
+
44
+ -- Knowledge RAG config (dimensions, chunk_size, chunk_strategy, search_indexes, etc.)
45
+ -- NULL = use sensible defaults (768d, 1000 chars, paragraph, bm25)
46
+ knowledge_config jsonb NULL,
47
+
48
+ -- Custom RLS policies for knowledge table (provisions.knowledge.policies)
49
+ -- NULL = use defaults (AuthzEntityMembership or AuthzAppMembership)
50
+ knowledge_policies jsonb NULL,
51
+
52
+ -- Per-table provisions overrides from blueprint config.
53
+ -- Keys are table keys (thread, message, task, prompt, knowledge).
54
+ -- When a key is present, the module trigger skips default security for that table;
55
+ -- secure_table_provision applies the custom grants/policies instead.
56
+ provisions jsonb NULL,
57
+
58
+ -- Constraints
59
+ CONSTRAINT agent_module_db_fkey FOREIGN KEY (database_id) REFERENCES metaschema_public.database (id) ON DELETE CASCADE,
60
+ CONSTRAINT agent_module_schema_fkey FOREIGN KEY (schema_id) REFERENCES metaschema_public.schema (id) ON DELETE CASCADE,
61
+ CONSTRAINT agent_module_private_schema_fkey FOREIGN KEY (private_schema_id) REFERENCES metaschema_public.schema (id) ON DELETE CASCADE,
62
+ CONSTRAINT agent_module_thread_table_fkey FOREIGN KEY (thread_table_id) REFERENCES metaschema_public.table (id) ON DELETE CASCADE,
63
+ CONSTRAINT agent_module_message_table_fkey FOREIGN KEY (message_table_id) REFERENCES metaschema_public.table (id) ON DELETE CASCADE,
64
+ CONSTRAINT agent_module_task_table_fkey FOREIGN KEY (task_table_id) REFERENCES metaschema_public.table (id) ON DELETE CASCADE,
65
+ CONSTRAINT agent_module_prompts_table_fkey FOREIGN KEY (prompts_table_id) REFERENCES metaschema_public.table (id) ON DELETE CASCADE,
66
+ CONSTRAINT agent_module_knowledge_table_fkey FOREIGN KEY (knowledge_table_id) REFERENCES metaschema_public.table (id) ON DELETE CASCADE,
67
+ CONSTRAINT agent_module_entity_table_fkey FOREIGN KEY (entity_table_id) REFERENCES metaschema_public.table (id) ON DELETE CASCADE
68
+ );
69
+
70
+ CREATE INDEX agent_module_database_id_idx ON metaschema_modules_public.agent_module ( database_id );
71
+
72
+ -- Unique constraint on (database_id, membership_type) using COALESCE to handle NULLs.
73
+ -- NULL membership_type = app-level, non-NULL = entity-scoped.
74
+ -- Only one agent module per scope.
75
+ CREATE UNIQUE INDEX agent_module_unique_scope ON metaschema_modules_public.agent_module ( database_id, COALESCE(membership_type, -1) );
76
+
77
+ COMMIT;
@@ -31,6 +31,10 @@ CREATE TABLE metaschema_modules_public.billing_module (
31
31
  meter_credits_table_id uuid NOT NULL DEFAULT uuid_nil(),
32
32
  meter_credits_table_name text NOT NULL DEFAULT '',
33
33
 
34
+ -- Meter sources table: maps billing meters to typed daily summary table columns
35
+ meter_sources_table_id uuid NOT NULL DEFAULT uuid_nil(),
36
+ meter_sources_table_name text NOT NULL DEFAULT '',
37
+
34
38
  -- Generated functions
35
39
  record_usage_function text NOT NULL DEFAULT '',
36
40
 
@@ -44,6 +48,7 @@ CREATE TABLE metaschema_modules_public.billing_module (
44
48
  CONSTRAINT ledger_table_fkey FOREIGN KEY (ledger_table_id) REFERENCES metaschema_public.table (id) ON DELETE CASCADE,
45
49
  CONSTRAINT balances_table_fkey FOREIGN KEY (balances_table_id) REFERENCES metaschema_public.table (id) ON DELETE CASCADE,
46
50
  CONSTRAINT meter_credits_table_fkey FOREIGN KEY (meter_credits_table_id) REFERENCES metaschema_public.table (id) ON DELETE CASCADE,
51
+ CONSTRAINT meter_sources_table_fkey FOREIGN KEY (meter_sources_table_id) REFERENCES metaschema_public.table (id) ON DELETE CASCADE,
47
52
  CONSTRAINT billing_module_database_id_unique UNIQUE (database_id)
48
53
  );
49
54
 
@@ -0,0 +1,44 @@
1
+ -- Deploy schemas/metaschema_modules_public/tables/compute_log_module/table to pg
2
+
3
+ -- requires: schemas/metaschema_modules_public/schema
4
+
5
+ BEGIN;
6
+
7
+ CREATE TABLE metaschema_modules_public.compute_log_module (
8
+ id uuid PRIMARY KEY DEFAULT uuidv7(),
9
+ database_id uuid NOT NULL,
10
+
11
+ schema_id uuid NOT NULL DEFAULT uuid_nil(),
12
+ private_schema_id uuid NOT NULL DEFAULT uuid_nil(),
13
+
14
+ -- Compute log table (partitioned by completed_at)
15
+ compute_log_table_id uuid NOT NULL DEFAULT uuid_nil(),
16
+ compute_log_table_name text NOT NULL DEFAULT '',
17
+
18
+ -- Pre-aggregated daily rollup table
19
+ usage_daily_table_id uuid NOT NULL DEFAULT uuid_nil(),
20
+ usage_daily_table_name text NOT NULL DEFAULT '',
21
+
22
+ -- Partition lifecycle configuration
23
+ "interval" text NOT NULL DEFAULT '1 month',
24
+ retention text NOT NULL DEFAULT '12 months',
25
+ premake int NOT NULL DEFAULT 2,
26
+
27
+ -- Scope configuration: 'app' = per-app usage (actor_id RLS), 'platform' = tenant metering (database_id RLS)
28
+ scope text NOT NULL DEFAULT 'app',
29
+ actor_fk_table_id uuid NULL,
30
+ entity_fk_table_id uuid NULL,
31
+
32
+ prefix text NULL,
33
+
34
+ CONSTRAINT db_fkey FOREIGN KEY (database_id) REFERENCES metaschema_public.database (id) ON DELETE CASCADE,
35
+ CONSTRAINT schema_fkey FOREIGN KEY (schema_id) REFERENCES metaschema_public.schema (id) ON DELETE CASCADE,
36
+ CONSTRAINT private_schema_fkey FOREIGN KEY (private_schema_id) REFERENCES metaschema_public.schema (id) ON DELETE CASCADE,
37
+ CONSTRAINT compute_log_table_fkey FOREIGN KEY (compute_log_table_id) REFERENCES metaschema_public.table (id) ON DELETE CASCADE,
38
+ CONSTRAINT usage_daily_table_fkey FOREIGN KEY (usage_daily_table_id) REFERENCES metaschema_public.table (id) ON DELETE CASCADE,
39
+ CONSTRAINT compute_log_module_database_id_prefix_unique UNIQUE NULLS NOT DISTINCT (database_id, prefix)
40
+ );
41
+
42
+ CREATE INDEX compute_log_module_database_id_idx ON metaschema_modules_public.compute_log_module ( database_id );
43
+
44
+ COMMIT;
@@ -0,0 +1,52 @@
1
+ -- Deploy schemas/metaschema_modules_public/tables/db_usage_module/table to pg
2
+
3
+ -- requires: schemas/metaschema_modules_public/schema
4
+
5
+ BEGIN;
6
+
7
+ CREATE TABLE metaschema_modules_public.db_usage_module (
8
+ id uuid PRIMARY KEY DEFAULT uuidv7(),
9
+ database_id uuid NOT NULL,
10
+
11
+ schema_id uuid NOT NULL DEFAULT uuid_nil(),
12
+ private_schema_id uuid NOT NULL DEFAULT uuid_nil(),
13
+
14
+ -- DB table stats log (partitioned — per-table reads/writes/size from pg_stat_user_tables)
15
+ table_stats_log_table_id uuid NOT NULL DEFAULT uuid_nil(),
16
+ table_stats_log_table_name text NOT NULL DEFAULT '',
17
+
18
+ -- DB table stats daily rollup
19
+ table_stats_daily_table_id uuid NOT NULL DEFAULT uuid_nil(),
20
+ table_stats_daily_table_name text NOT NULL DEFAULT '',
21
+
22
+ -- DB query stats log (partitioned — query execution time from pg_stat_statements)
23
+ query_stats_log_table_id uuid NOT NULL DEFAULT uuid_nil(),
24
+ query_stats_log_table_name text NOT NULL DEFAULT '',
25
+
26
+ -- DB query stats daily rollup
27
+ query_stats_daily_table_id uuid NOT NULL DEFAULT uuid_nil(),
28
+ query_stats_daily_table_name text NOT NULL DEFAULT '',
29
+
30
+ -- Partition lifecycle configuration
31
+ "interval" text NOT NULL DEFAULT '1 month',
32
+ retention text NOT NULL DEFAULT '12 months',
33
+ premake int NOT NULL DEFAULT 2,
34
+
35
+ -- Scope configuration: 'app' = per-app usage, 'platform' = tenant metering (database_id RLS)
36
+ scope text NOT NULL DEFAULT 'app',
37
+
38
+ prefix text NULL,
39
+
40
+ CONSTRAINT db_fkey FOREIGN KEY (database_id) REFERENCES metaschema_public.database (id) ON DELETE CASCADE,
41
+ CONSTRAINT schema_fkey FOREIGN KEY (schema_id) REFERENCES metaschema_public.schema (id) ON DELETE CASCADE,
42
+ CONSTRAINT private_schema_fkey FOREIGN KEY (private_schema_id) REFERENCES metaschema_public.schema (id) ON DELETE CASCADE,
43
+ CONSTRAINT table_stats_log_table_fkey FOREIGN KEY (table_stats_log_table_id) REFERENCES metaschema_public.table (id) ON DELETE CASCADE,
44
+ CONSTRAINT table_stats_daily_table_fkey FOREIGN KEY (table_stats_daily_table_id) REFERENCES metaschema_public.table (id) ON DELETE CASCADE,
45
+ CONSTRAINT query_stats_log_table_fkey FOREIGN KEY (query_stats_log_table_id) REFERENCES metaschema_public.table (id) ON DELETE CASCADE,
46
+ CONSTRAINT query_stats_daily_table_fkey FOREIGN KEY (query_stats_daily_table_id) REFERENCES metaschema_public.table (id) ON DELETE CASCADE,
47
+ CONSTRAINT db_usage_module_database_id_prefix_unique UNIQUE NULLS NOT DISTINCT (database_id, prefix)
48
+ );
49
+
50
+ CREATE INDEX db_usage_module_database_id_idx ON metaschema_modules_public.db_usage_module ( database_id );
51
+
52
+ COMMIT;
@@ -47,8 +47,6 @@ CREATE TABLE metaschema_modules_public.entity_type_provision (
47
47
 
48
48
  has_levels boolean NOT NULL DEFAULT false,
49
49
 
50
- has_storage boolean NOT NULL DEFAULT false,
51
-
52
50
  has_invites boolean NOT NULL DEFAULT false,
53
51
 
54
52
  has_invite_achievements boolean NOT NULL DEFAULT false,
@@ -56,11 +54,27 @@ CREATE TABLE metaschema_modules_public.entity_type_provision (
56
54
  -- =========================================================================
57
55
  -- Storage configuration: JSON array of storage module definitions.
58
56
  -- Each element provisions a separate storage module with its own tables,
59
- -- RLS policies, and feature flags. Only used when has_storage = true.
60
- -- NULL = provision a single default storage module with default settings.
57
+ -- RLS policies, and feature flags. Presence triggers provisioning
58
+ -- (same inference model as namespaces, functions, agents).
59
+ -- NULL = do not provision. '[{}]' = provision one default storage module.
60
+ -- =========================================================================
61
+
62
+ storage jsonb DEFAULT NULL,
63
+
64
+ -- =========================================================================
65
+ -- Module configuration arrays: presence triggers provisioning.
66
+ -- Each is a JSON array of module definitions (like storage).
67
+ -- NULL = do not provision. '[{}]' = provision one default instance.
68
+ -- Each element may include "key" (discriminator) and "policies" (override).
61
69
  -- =========================================================================
62
70
 
63
- storage_config jsonb DEFAULT NULL,
71
+ namespaces jsonb DEFAULT NULL,
72
+
73
+ functions jsonb DEFAULT NULL,
74
+
75
+ graphs jsonb DEFAULT NULL,
76
+
77
+ agents jsonb DEFAULT NULL,
64
78
 
65
79
  -- =========================================================================
66
80
  -- Escape hatch: skip default entity table RLS policies
@@ -107,6 +121,26 @@ CREATE TABLE metaschema_modules_public.entity_type_provision (
107
121
 
108
122
  out_invites_module_id uuid DEFAULT NULL,
109
123
 
124
+ out_namespace_module_id uuid DEFAULT NULL,
125
+
126
+ out_namespaces_table_id uuid DEFAULT NULL,
127
+
128
+ out_namespace_events_table_id uuid DEFAULT NULL,
129
+
130
+ out_function_module_id uuid DEFAULT NULL,
131
+
132
+ out_definitions_table_id uuid DEFAULT NULL,
133
+
134
+ out_invocations_table_id uuid DEFAULT NULL,
135
+
136
+ out_execution_logs_table_id uuid DEFAULT NULL,
137
+
138
+ out_graph_module_id uuid DEFAULT NULL,
139
+
140
+ out_graphs_table_id uuid DEFAULT NULL,
141
+
142
+ out_agent_module_id uuid DEFAULT NULL,
143
+
110
144
  -- =========================================================================
111
145
  -- Constraints
112
146
  -- =========================================================================
@@ -205,20 +239,14 @@ COMMENT ON COLUMN metaschema_modules_public.entity_type_provision.has_levels IS
205
239
  Levels provide gamification/achievement tracking for members.
206
240
  When true, creates level steps, achievements, and level tables with security.';
207
241
 
208
- COMMENT ON COLUMN metaschema_modules_public.entity_type_provision.has_storage IS
209
- 'Whether to provision storage_module for this type. Defaults to false.
210
- When true, creates {prefix}_buckets and {prefix}_files tables
211
- with entity-scoped RLS (AuthzEntityMembership) using the entity''s membership_type.
212
- Storage tables get owner_id FK to the entity table, so files are owned by the entity.';
213
-
214
242
  COMMENT ON COLUMN metaschema_modules_public.entity_type_provision.has_invites IS
215
243
  'Whether to provision invites_module for this type. Defaults to false.
216
244
  When true, the trigger inserts a row into invites_module which in turn
217
245
  (via insert_invites_module BEFORE INSERT) creates {prefix}_invites and
218
246
  {prefix}_claimed_invites tables plus the submit_{prefix}_invite_code() function.
219
- Symmetric counterpart of has_storage. Re-provisioning is idempotent: the
220
- UNIQUE (database_id, membership_type) constraint on invites_module combined with
221
- ON CONFLICT DO NOTHING in the fan-out makes repeated INSERTs safe.';
247
+ Re-provisioning is idempotent: the UNIQUE (database_id, membership_type) constraint
248
+ on invites_module combined with ON CONFLICT DO NOTHING in the fan-out makes
249
+ repeated INSERTs safe.';
222
250
 
223
251
  COMMENT ON COLUMN metaschema_modules_public.entity_type_provision.has_invite_achievements IS
224
252
  'Whether to auto-attach an EventTracker to the claimed_invites table for invite-based
@@ -296,11 +324,12 @@ COMMENT ON COLUMN metaschema_modules_public.entity_type_provision.out_installed_
296
324
  'Output: array of installed module labels (e.g. ARRAY[''permissions_module:data_room'', ''memberships_module:data_room'', ''invites_module:data_room'']).
297
325
  Populated by the trigger. Useful for verifying which modules were provisioned.';
298
326
 
299
- COMMENT ON COLUMN metaschema_modules_public.entity_type_provision.storage_config IS
300
- 'Optional JSON array of storage module definitions. Each element provisions a separate
301
- storage module with its own tables ({prefix}_{storage_key}_buckets/files), RLS policies,
302
- and feature flags. Only used when has_storage = true; ignored otherwise.
303
- NULL = provision a single default storage module with all defaults.
327
+ COMMENT ON COLUMN metaschema_modules_public.entity_type_provision.storage IS
328
+ 'Optional JSON array of storage module definitions. Presence triggers provisioning
329
+ (same inference model as namespaces, functions, agents).
330
+ Each element provisions a separate storage module with its own tables
331
+ ({prefix}_{storage_key}_buckets/files), RLS policies, and feature flags.
332
+ NULL = do not provision storage. ''[{}]'' = provision one default storage module.
304
333
  Each array element recognizes (all optional):
305
334
  - storage_key (text) module discriminator, max 16 chars, lowercase snake_case.
306
335
  Defaults to ''default'' (omitted from table names).
@@ -322,22 +351,68 @@ COMMENT ON COLUMN metaschema_modules_public.entity_type_provision.storage_config
322
351
  - provisions (jsonb object) per-table customization keyed by "files" or "buckets".
323
352
  Each value: { nodes, fields, grants, use_rls, policies }.
324
353
  Example (single module, backward compat):
325
- storage_config := ''[{"buckets": [{"name": "documents"}]}]''::jsonb
354
+ storage := ''[{"buckets": [{"name": "documents"}]}]''::jsonb
326
355
  Example (multi-module):
327
- storage_config := ''[{"has_path_shares": true, "buckets": [{"name": "documents"}]}, {"storage_key": "fn", "has_custom_keys": true, "buckets": [{"name": "functions"}]}]''::jsonb';
356
+ storage := ''[{"has_path_shares": true, "buckets": [{"name": "documents"}]}, {"storage_key": "fn", "has_custom_keys": true, "buckets": [{"name": "functions"}]}]''::jsonb';
328
357
 
329
358
  COMMENT ON COLUMN metaschema_modules_public.entity_type_provision.out_storage_module_id IS
330
- 'Output: the UUID of the storage_module row created for this entity type. Populated by the trigger when has_storage=true.';
359
+ 'Output: the UUID of the storage_module row created for this entity type. Populated by the trigger when storage is non-NULL and non-empty.';
331
360
 
332
361
  COMMENT ON COLUMN metaschema_modules_public.entity_type_provision.out_buckets_table_id IS
333
- 'Output: the UUID of the generated buckets table (e.g. data_room_buckets). Populated by the trigger when has_storage=true.';
362
+ 'Output: the UUID of the generated buckets table (e.g. data_room_buckets). Populated by the trigger when storage is non-NULL and non-empty.';
334
363
 
335
364
  COMMENT ON COLUMN metaschema_modules_public.entity_type_provision.out_files_table_id IS
336
- 'Output: the UUID of the generated files table (e.g. data_room_files). Populated by the trigger when has_storage=true.';
365
+ 'Output: the UUID of the generated files table (e.g. data_room_files). Populated by the trigger when storage is non-NULL and non-empty.';
337
366
 
338
367
  COMMENT ON COLUMN metaschema_modules_public.entity_type_provision.out_invites_module_id IS
339
368
  'Output: the UUID of the invites_module row created for this entity type. Populated by the trigger when has_invites=true.
340
369
  NULL when has_invites=false, or when re-provisioning hits ON CONFLICT DO NOTHING
341
370
  (i.e. the invites_module row was created in a previous run).';
342
371
 
372
+ COMMENT ON COLUMN metaschema_modules_public.entity_type_provision.namespaces IS
373
+ 'Optional JSON array of namespace module definitions. Presence triggers provisioning.
374
+ NULL = do not provision namespaces. ''[{}]'' = provision one default namespace module.
375
+ Each element recognizes (all optional):
376
+ - key (text) module discriminator. Defaults to ''default''.
377
+ - policies (jsonb array) RLS policy overrides. NULL = apply defaults from apply_namespace_security().
378
+ Creates {prefix}_namespaces (or {prefix}_{key}_namespaces for non-default keys)
379
+ with entity-scoped RLS (AuthzEntityMembership) and a rename proxy trigger.
380
+ Registers manage_namespaces permission bit on first provision.
381
+ Example: namespaces := ''[{}]''::jsonb';
382
+
383
+ COMMENT ON COLUMN metaschema_modules_public.entity_type_provision.functions IS
384
+ 'Optional JSON array of function module definitions. Presence triggers provisioning.
385
+ NULL = do not provision functions. ''[{}]'' = provision one default function module.
386
+ Each element recognizes (all optional):
387
+ - key (text) module discriminator. Defaults to ''default''.
388
+ - policies (jsonb array) RLS policy overrides. NULL = apply defaults from apply_function_security().
389
+ Creates {prefix}_function_definitions (or {prefix}_{key}_function_definitions for non-default keys)
390
+ with entity-scoped RLS and a job trigger dispatching function:provision tasks.
391
+ Registers manage_functions + invoke_functions permission bits on first provision.
392
+ Example: functions := ''[{}]''::jsonb';
393
+
394
+ COMMENT ON COLUMN metaschema_modules_public.entity_type_provision.graphs IS
395
+ 'Optional JSON array of graph module definitions. Presence triggers provisioning.
396
+ NULL = do not provision graphs. ''[{}]'' = provision one default graph module.
397
+ Each element recognizes (all optional):
398
+ - key (text) module discriminator. Defaults to ''default''.
399
+ - policies (jsonb array) RLS policy overrides. NULL = apply defaults from apply_graph_security().
400
+ Registers manage_graphs + execute_graphs permission bits on first provision.
401
+ Graph module requires a merkle_store_module_id dependency, so entity_type_provision
402
+ only registers permissions here. The graph module itself must be provisioned
403
+ separately with the merkle store dependency resolved.
404
+ Example: graphs := ''[{}]''::jsonb';
405
+
406
+ COMMENT ON COLUMN metaschema_modules_public.entity_type_provision.out_namespace_module_id IS
407
+ 'Output: the UUID of the namespace_module row created (or found) for this entity type.
408
+ Populated by the trigger when namespaces is non-NULL. NULL otherwise.';
409
+
410
+ COMMENT ON COLUMN metaschema_modules_public.entity_type_provision.out_namespaces_table_id IS
411
+ 'Output: the UUID of the generated namespaces table (e.g. data_room_namespaces).
412
+ Populated by the trigger when namespaces is non-NULL. NULL otherwise.';
413
+
414
+ COMMENT ON COLUMN metaschema_modules_public.entity_type_provision.out_namespace_events_table_id IS
415
+ 'Output: the UUID of the generated namespace_events partitioned table (e.g. data_room_namespace_events).
416
+ Monthly partitioned, 12-month retention. Populated by the trigger when namespaces is non-NULL. NULL otherwise.';
417
+
343
418
  COMMIT;
@@ -0,0 +1,68 @@
1
+ -- Deploy schemas/metaschema_modules_public/tables/function_module/table to pg
2
+
3
+ -- requires: schemas/metaschema_modules_public/schema
4
+
5
+ BEGIN;
6
+
7
+ CREATE TABLE metaschema_modules_public.function_module (
8
+ id uuid PRIMARY KEY DEFAULT uuidv7(),
9
+ database_id uuid NOT NULL,
10
+
11
+ -- Schema references (if uuid_nil, resolved from schema name or default)
12
+ schema_id uuid NOT NULL DEFAULT uuid_nil(),
13
+ private_schema_id uuid NOT NULL DEFAULT uuid_nil(),
14
+
15
+ -- Optional schema name overrides (used when schema IDs are not provided)
16
+ public_schema_name text,
17
+ private_schema_name text,
18
+
19
+ -- Generated table IDs (populated by the generator)
20
+ definitions_table_id uuid NOT NULL DEFAULT uuid_nil(),
21
+ invocations_table_id uuid NOT NULL DEFAULT uuid_nil(),
22
+ execution_logs_table_id uuid NOT NULL DEFAULT uuid_nil(),
23
+
24
+ -- Table names (input to the generator)
25
+ definitions_table_name text NOT NULL DEFAULT 'function_definitions',
26
+ invocations_table_name text NOT NULL DEFAULT 'function_invocations',
27
+ execution_logs_table_name text NOT NULL DEFAULT 'function_execution_logs',
28
+
29
+ -- API routing (get-or-create: if set, schema is added to this API; if NULL, no API is added)
30
+ api_name text,
31
+ private_api_name text,
32
+
33
+ -- Multi-tenant function identity
34
+ membership_type int DEFAULT NULL, -- NULL = database-root (AuthzMembership via app_sprt), non-NULL = entity-scoped (AuthzEntityMembership)
35
+
36
+ -- Entity table for RLS (NULL for app-level functions, entity table for entity-scoped functions)
37
+ entity_table_id uuid NULL,
38
+
39
+ -- Configurable security policies (NULL = use defaults based on membership_type).
40
+ -- When provided, replaces the default policy set in apply_function_security.
41
+ -- Accepts a JSON array of policy objects:
42
+ -- {"$type": "AuthzEntityMembership", "privileges": ["select", "update"], "data": {...}}
43
+ policies jsonb NULL,
44
+
45
+ -- Per-table provisions overrides from blueprint config.
46
+ -- Keys are table keys (definitions, invocations, execution_logs).
47
+ -- When a key is present, the module trigger skips default security for that table;
48
+ -- secure_table_provision applies the custom grants/policies instead.
49
+ provisions jsonb NULL,
50
+
51
+ -- Constraints
52
+ CONSTRAINT function_module_db_fkey FOREIGN KEY (database_id) REFERENCES metaschema_public.database (id) ON DELETE CASCADE,
53
+ CONSTRAINT function_module_schema_fkey FOREIGN KEY (schema_id) REFERENCES metaschema_public.schema (id) ON DELETE CASCADE,
54
+ CONSTRAINT function_module_private_schema_fkey FOREIGN KEY (private_schema_id) REFERENCES metaschema_public.schema (id) ON DELETE CASCADE,
55
+ CONSTRAINT function_module_definitions_table_fkey FOREIGN KEY (definitions_table_id) REFERENCES metaschema_public.table (id) ON DELETE CASCADE,
56
+ CONSTRAINT function_module_invocations_table_fkey FOREIGN KEY (invocations_table_id) REFERENCES metaschema_public.table (id) ON DELETE CASCADE,
57
+ CONSTRAINT function_module_execution_logs_table_fkey FOREIGN KEY (execution_logs_table_id) REFERENCES metaschema_public.table (id) ON DELETE CASCADE,
58
+ CONSTRAINT function_module_entity_table_fkey FOREIGN KEY (entity_table_id) REFERENCES metaschema_public.table (id) ON DELETE CASCADE
59
+ );
60
+
61
+ CREATE INDEX function_module_database_id_idx ON metaschema_modules_public.function_module ( database_id );
62
+
63
+ -- Unique constraint on (database_id, membership_type) using COALESCE to handle NULLs.
64
+ -- NULL membership_type = app-level, non-NULL = entity-scoped.
65
+ -- Only one function module per scope.
66
+ CREATE UNIQUE INDEX function_module_unique_scope ON metaschema_modules_public.function_module ( database_id, COALESCE(membership_type, -1) );
67
+
68
+ COMMIT;
@@ -0,0 +1,73 @@
1
+ -- Deploy schemas/metaschema_modules_public/tables/graph_module/table to pg
2
+
3
+ -- requires: schemas/metaschema_modules_public/schema
4
+ -- requires: schemas/metaschema_modules_public/tables/merkle_store_module/table
5
+
6
+ BEGIN;
7
+
8
+ CREATE TABLE metaschema_modules_public.graph_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
+ public_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
+ -- Table/function prefix (e.g., 'pipeline' -> pipeline_function_graphs, ...)
21
+ -- Stored normalized (no trailing underscore); underscore added at generation time
22
+ prefix text NOT NULL DEFAULT '',
23
+
24
+ -- Reference to the Merkle store this graph module depends on
25
+ merkle_store_module_id uuid NOT NULL,
26
+
27
+ -- Generated table IDs (populated by BEFORE INSERT trigger)
28
+ graphs_table_id uuid NOT NULL DEFAULT uuid_nil(),
29
+ executions_table_id uuid NOT NULL DEFAULT uuid_nil(),
30
+ outputs_table_id uuid NOT NULL DEFAULT uuid_nil(),
31
+
32
+ -- API routing (get-or-create: if set, schema is added to this API; if NULL, no API is added)
33
+ api_name text,
34
+ private_api_name text,
35
+
36
+ -- Scope field name (column used for multi-tenant isolation)
37
+ scope_field text NOT NULL DEFAULT 'scope_id',
38
+
39
+ -- Multi-tenant scoping (entity-aware module pattern)
40
+ membership_type int DEFAULT NULL, -- NULL = database-root, non-NULL = entity-scoped
41
+ entity_table_id uuid NULL, -- Entity table for entity-scoped RLS
42
+
43
+ -- Configurable security policies (NULL = use defaults).
44
+ -- Accepts a JSON array of policy objects:
45
+ -- {"$type": "AuthzEntityMembership", "privileges": ["select", "update"], "data": {...}}
46
+ policies jsonb NULL,
47
+
48
+ -- Per-table provisions overrides from blueprint config.
49
+ -- Keys are table keys (graphs, executions, outputs).
50
+ -- When a key is present, the module trigger skips default security for that table;
51
+ -- secure_table_provision applies the custom grants/policies instead.
52
+ provisions jsonb NULL,
53
+
54
+ -- Timestamps
55
+ created_at timestamptz NOT NULL DEFAULT now(),
56
+
57
+ -- Constraints
58
+ CONSTRAINT db_fkey FOREIGN KEY (database_id) REFERENCES metaschema_public.database (id) ON DELETE CASCADE,
59
+ CONSTRAINT public_schema_fkey FOREIGN KEY (public_schema_id) REFERENCES metaschema_public.schema (id) ON DELETE CASCADE,
60
+ CONSTRAINT private_schema_fkey FOREIGN KEY (private_schema_id) REFERENCES metaschema_public.schema (id) ON DELETE CASCADE,
61
+ CONSTRAINT merkle_store_fkey FOREIGN KEY (merkle_store_module_id) REFERENCES metaschema_modules_public.merkle_store_module (id) ON DELETE CASCADE,
62
+ CONSTRAINT graphs_table_fkey FOREIGN KEY (graphs_table_id) REFERENCES metaschema_public.table (id) ON DELETE CASCADE,
63
+ CONSTRAINT executions_table_fkey FOREIGN KEY (executions_table_id) REFERENCES metaschema_public.table (id) ON DELETE CASCADE,
64
+ CONSTRAINT outputs_table_fkey FOREIGN KEY (outputs_table_id) REFERENCES metaschema_public.table (id) ON DELETE CASCADE,
65
+ CONSTRAINT graph_module_entity_table_fkey FOREIGN KEY (entity_table_id) REFERENCES metaschema_public.table (id) ON DELETE CASCADE,
66
+
67
+ -- Only one graph module per database + merkle store combination
68
+ CONSTRAINT graph_module_database_merkle_unique UNIQUE (database_id, merkle_store_module_id)
69
+ );
70
+
71
+ CREATE INDEX graph_module_database_id_idx ON metaschema_modules_public.graph_module ( database_id );
72
+
73
+ COMMIT;
@@ -21,9 +21,14 @@ CREATE TABLE metaschema_modules_public.inference_log_module (
21
21
 
22
22
  -- Partition lifecycle configuration
23
23
  "interval" text NOT NULL DEFAULT '1 month',
24
- retention text NULL,
24
+ retention text NOT NULL DEFAULT '12 months',
25
25
  premake int NOT NULL DEFAULT 2,
26
26
 
27
+ -- Scope configuration: 'app' = per-app usage (actor_id RLS), 'platform' = tenant metering (database_id RLS)
28
+ scope text NOT NULL DEFAULT 'app',
29
+ actor_fk_table_id uuid NULL,
30
+ entity_fk_table_id uuid NULL,
31
+
27
32
  prefix text NULL,
28
33
 
29
34
  CONSTRAINT db_fkey FOREIGN KEY (database_id) REFERENCES metaschema_public.database (id) ON DELETE CASCADE,
@@ -31,7 +36,7 @@ CREATE TABLE metaschema_modules_public.inference_log_module (
31
36
  CONSTRAINT private_schema_fkey FOREIGN KEY (private_schema_id) REFERENCES metaschema_public.schema (id) ON DELETE CASCADE,
32
37
  CONSTRAINT inference_log_table_fkey FOREIGN KEY (inference_log_table_id) REFERENCES metaschema_public.table (id) ON DELETE CASCADE,
33
38
  CONSTRAINT usage_daily_table_fkey FOREIGN KEY (usage_daily_table_id) REFERENCES metaschema_public.table (id) ON DELETE CASCADE,
34
- CONSTRAINT inference_log_module_database_id_unique UNIQUE (database_id)
39
+ CONSTRAINT inference_log_module_database_id_prefix_unique UNIQUE NULLS NOT DISTINCT (database_id, prefix)
35
40
  );
36
41
 
37
42
  CREATE INDEX inference_log_module_database_id_idx ON metaschema_modules_public.inference_log_module ( database_id );
@@ -0,0 +1,50 @@
1
+ -- Deploy schemas/metaschema_modules_public/tables/merkle_store_module/table to pg
2
+
3
+ -- requires: schemas/metaschema_modules_public/schema
4
+
5
+ BEGIN;
6
+
7
+ CREATE TABLE metaschema_modules_public.merkle_store_module (
8
+ id uuid PRIMARY KEY DEFAULT uuidv7(),
9
+ database_id uuid NOT NULL,
10
+
11
+ -- Schema reference (if uuid_nil, resolved from public_schema_name or default)
12
+ schema_id uuid NOT NULL DEFAULT uuid_nil(),
13
+
14
+ -- Optional schema name override (used when schema_id is not provided)
15
+ public_schema_name text,
16
+
17
+ -- Generated table IDs (populated by BEFORE INSERT trigger)
18
+ object_table_id uuid NOT NULL DEFAULT uuid_nil(),
19
+ store_table_id uuid NOT NULL DEFAULT uuid_nil(),
20
+ commit_table_id uuid NOT NULL DEFAULT uuid_nil(),
21
+ ref_table_id uuid NOT NULL DEFAULT uuid_nil(),
22
+
23
+ -- Table/function prefix (e.g., 'graph' -> graph_object, graph_store, ...)
24
+ -- Stored normalized (no trailing underscore); underscore added at generation time
25
+ prefix text NOT NULL DEFAULT '',
26
+
27
+ -- API name (if set, schema is added to this API; if NULL, no API is added)
28
+ api_name text,
29
+
30
+ -- Scope field name (column used for multi-tenant isolation)
31
+ scope_field text NOT NULL DEFAULT 'scope_id',
32
+
33
+ -- Timestamps
34
+ created_at timestamptz NOT NULL DEFAULT now(),
35
+
36
+ -- Constraints
37
+ CONSTRAINT db_fkey FOREIGN KEY (database_id) REFERENCES metaschema_public.database (id) ON DELETE CASCADE,
38
+ CONSTRAINT schema_fkey FOREIGN KEY (schema_id) REFERENCES metaschema_public.schema (id) ON DELETE CASCADE,
39
+ CONSTRAINT object_table_fkey FOREIGN KEY (object_table_id) REFERENCES metaschema_public.table (id) ON DELETE CASCADE,
40
+ CONSTRAINT store_table_fkey FOREIGN KEY (store_table_id) REFERENCES metaschema_public.table (id) ON DELETE CASCADE,
41
+ CONSTRAINT commit_table_fkey FOREIGN KEY (commit_table_id) REFERENCES metaschema_public.table (id) ON DELETE CASCADE,
42
+ CONSTRAINT ref_table_fkey FOREIGN KEY (ref_table_id) REFERENCES metaschema_public.table (id) ON DELETE CASCADE,
43
+
44
+ -- Only one merkle store module per database + prefix combination
45
+ CONSTRAINT merkle_store_module_database_prefix_unique UNIQUE (database_id, prefix)
46
+ );
47
+
48
+ CREATE INDEX merkle_store_module_database_id_idx ON metaschema_modules_public.merkle_store_module ( database_id );
49
+
50
+ COMMIT;