@pgpm/metaschema-modules 0.23.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 (69) hide show
  1. package/Makefile +1 -1
  2. package/README.md +1 -1
  3. package/deploy/schemas/metaschema_modules_public/tables/agent_module/table.sql +77 -0
  4. package/deploy/schemas/metaschema_modules_public/tables/billing_module/table.sql +10 -0
  5. package/deploy/schemas/metaschema_modules_public/tables/compute_log_module/table.sql +44 -0
  6. package/deploy/schemas/metaschema_modules_public/tables/config_secrets_org_module/table.sql +28 -0
  7. package/deploy/schemas/metaschema_modules_public/tables/{encrypted_secrets_module → config_secrets_user_module}/table.sql +4 -4
  8. package/deploy/schemas/metaschema_modules_public/tables/db_usage_module/table.sql +52 -0
  9. package/deploy/schemas/metaschema_modules_public/tables/entity_type_provision/table.sql +135 -49
  10. package/deploy/schemas/metaschema_modules_public/tables/events_module/table.sql +85 -0
  11. package/deploy/schemas/metaschema_modules_public/tables/function_module/table.sql +68 -0
  12. package/deploy/schemas/metaschema_modules_public/tables/graph_module/table.sql +73 -0
  13. package/deploy/schemas/metaschema_modules_public/tables/inference_log_module/table.sql +44 -0
  14. package/deploy/schemas/metaschema_modules_public/tables/limits_module/table.sql +11 -1
  15. package/deploy/schemas/metaschema_modules_public/tables/merkle_store_module/table.sql +50 -0
  16. package/deploy/schemas/metaschema_modules_public/tables/namespace_module/table.sql +65 -0
  17. package/deploy/schemas/metaschema_modules_public/tables/rate_limit_meters_module/table.sql +51 -0
  18. package/deploy/schemas/metaschema_modules_public/tables/realtime_module/table.sql +2 -2
  19. package/deploy/schemas/metaschema_modules_public/tables/storage_log_module/table.sql +44 -0
  20. package/deploy/schemas/metaschema_modules_public/tables/storage_module/table.sql +17 -9
  21. package/deploy/schemas/metaschema_modules_public/tables/transfer_log_module/table.sql +44 -0
  22. package/deploy/schemas/metaschema_modules_public/tables/user_auth_module/table.sql +1 -1
  23. package/deploy/schemas/metaschema_modules_public/tables/{secrets_module → user_state_module}/table.sql +4 -4
  24. package/metaschema-modules.control +1 -1
  25. package/package.json +4 -4
  26. package/pgpm.plan +15 -3
  27. package/revert/schemas/metaschema_modules_public/tables/agent_module/table.sql +7 -0
  28. package/revert/schemas/metaschema_modules_public/tables/compute_log_module/table.sql +3 -0
  29. package/revert/schemas/metaschema_modules_public/tables/config_secrets_org_module/table.sql +7 -0
  30. package/revert/schemas/metaschema_modules_public/tables/config_secrets_user_module/table.sql +7 -0
  31. package/revert/schemas/metaschema_modules_public/tables/db_usage_module/table.sql +3 -0
  32. package/revert/schemas/metaschema_modules_public/tables/events_module/table.sql +7 -0
  33. package/revert/schemas/metaschema_modules_public/tables/function_module/table.sql +7 -0
  34. package/revert/schemas/metaschema_modules_public/tables/graph_module/table.sql +7 -0
  35. package/revert/schemas/metaschema_modules_public/tables/inference_log_module/table.sql +3 -0
  36. package/revert/schemas/metaschema_modules_public/tables/merkle_store_module/table.sql +7 -0
  37. package/revert/schemas/metaschema_modules_public/tables/namespace_module/table.sql +7 -0
  38. package/revert/schemas/metaschema_modules_public/tables/rate_limit_meters_module/table.sql +7 -0
  39. package/revert/schemas/metaschema_modules_public/tables/storage_log_module/table.sql +3 -0
  40. package/revert/schemas/metaschema_modules_public/tables/transfer_log_module/table.sql +3 -0
  41. package/revert/schemas/metaschema_modules_public/tables/user_state_module/table.sql +7 -0
  42. package/sql/{metaschema-modules--0.15.5.sql → metaschema-modules--0.26.0.sql} +884 -213
  43. package/verify/schemas/metaschema_modules_public/tables/agent_module/table.sql +7 -0
  44. package/verify/schemas/metaschema_modules_public/tables/billing_module/table.sql +2 -0
  45. package/verify/schemas/metaschema_modules_public/tables/compute_log_module/table.sql +9 -0
  46. package/verify/schemas/metaschema_modules_public/tables/config_secrets_org_module/table.sql +7 -0
  47. package/verify/schemas/metaschema_modules_public/tables/config_secrets_user_module/table.sql +7 -0
  48. package/verify/schemas/metaschema_modules_public/tables/db_usage_module/table.sql +10 -0
  49. package/verify/schemas/metaschema_modules_public/tables/events_module/table.sql +7 -0
  50. package/verify/schemas/metaschema_modules_public/tables/function_module/table.sql +7 -0
  51. package/verify/schemas/metaschema_modules_public/tables/graph_module/table.sql +7 -0
  52. package/verify/schemas/metaschema_modules_public/tables/inference_log_module/table.sql +22 -0
  53. package/verify/schemas/metaschema_modules_public/tables/merkle_store_module/table.sql +7 -0
  54. package/verify/schemas/metaschema_modules_public/tables/namespace_module/table.sql +14 -0
  55. package/verify/schemas/metaschema_modules_public/tables/profiles_module/table.sql +2 -1
  56. package/verify/schemas/metaschema_modules_public/tables/rate_limit_meters_module/table.sql +7 -0
  57. package/verify/schemas/metaschema_modules_public/tables/storage_log_module/table.sql +10 -0
  58. package/verify/schemas/metaschema_modules_public/tables/transfer_log_module/table.sql +10 -0
  59. package/verify/schemas/metaschema_modules_public/tables/user_state_module/table.sql +7 -0
  60. package/deploy/schemas/metaschema_modules_public/tables/levels_module/table.sql +0 -64
  61. package/deploy/schemas/metaschema_modules_public/tables/table_template_module/table.sql +0 -43
  62. package/revert/schemas/metaschema_modules_public/tables/encrypted_secrets_module/table.sql +0 -7
  63. package/revert/schemas/metaschema_modules_public/tables/levels_module/table.sql +0 -7
  64. package/revert/schemas/metaschema_modules_public/tables/secrets_module/table.sql +0 -7
  65. package/revert/schemas/metaschema_modules_public/tables/table_template_module/table.sql +0 -7
  66. package/verify/schemas/metaschema_modules_public/tables/encrypted_secrets_module/table.sql +0 -7
  67. package/verify/schemas/metaschema_modules_public/tables/levels_module/table.sql +0 -7
  68. package/verify/schemas/metaschema_modules_public/tables/secrets_module/table.sql +0 -7
  69. package/verify/schemas/metaschema_modules_public/tables/table_template_module/table.sql +0 -18
@@ -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;
@@ -0,0 +1,44 @@
1
+ -- Deploy schemas/metaschema_modules_public/tables/inference_log_module/table to pg
2
+
3
+ -- requires: schemas/metaschema_modules_public/schema
4
+
5
+ BEGIN;
6
+
7
+ CREATE TABLE metaschema_modules_public.inference_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
+ -- Inference log table (partitioned by created_at)
15
+ inference_log_table_id uuid NOT NULL DEFAULT uuid_nil(),
16
+ inference_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 inference_log_table_fkey FOREIGN KEY (inference_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 inference_log_module_database_id_prefix_unique UNIQUE NULLS NOT DISTINCT (database_id, prefix)
40
+ );
41
+
42
+ CREATE INDEX inference_log_module_database_id_idx ON metaschema_modules_public.inference_log_module ( database_id );
43
+
44
+ COMMIT;
@@ -53,6 +53,14 @@ CREATE TABLE metaschema_modules_public.limits_module (
53
53
  -- Resolve cap function (COALESCE lookup: per-entity → default → 0)
54
54
  resolve_cap_function text NOT NULL DEFAULT '',
55
55
 
56
+ -- Warning tables for soft-limit notifications
57
+ limit_warnings_table_id uuid NULL,
58
+ limit_warning_state_table_id uuid NULL,
59
+
60
+ -- Soft limit check functions
61
+ limit_check_soft_function text NOT NULL DEFAULT '',
62
+ limit_aggregate_check_soft_function text NOT NULL DEFAULT '',
63
+
56
64
  prefix text NULL,
57
65
 
58
66
  membership_type int NOT NULL,
@@ -77,7 +85,9 @@ CREATE TABLE metaschema_modules_public.limits_module (
77
85
  CONSTRAINT credit_code_items_table_fkey FOREIGN KEY (credit_code_items_table_id) REFERENCES metaschema_public.table (id) ON DELETE CASCADE,
78
86
  CONSTRAINT credit_redemptions_table_fkey FOREIGN KEY (credit_redemptions_table_id) REFERENCES metaschema_public.table (id) ON DELETE CASCADE,
79
87
  CONSTRAINT limit_caps_table_fkey FOREIGN KEY (limit_caps_table_id) REFERENCES metaschema_public.table (id) ON DELETE CASCADE,
80
- CONSTRAINT limit_caps_defaults_table_fkey FOREIGN KEY (limit_caps_defaults_table_id) REFERENCES metaschema_public.table (id) ON DELETE CASCADE
88
+ CONSTRAINT limit_caps_defaults_table_fkey FOREIGN KEY (limit_caps_defaults_table_id) REFERENCES metaschema_public.table (id) ON DELETE CASCADE,
89
+ CONSTRAINT limit_warnings_table_fkey FOREIGN KEY (limit_warnings_table_id) REFERENCES metaschema_public.table (id) ON DELETE CASCADE,
90
+ CONSTRAINT limit_warning_state_table_fkey FOREIGN KEY (limit_warning_state_table_id) REFERENCES metaschema_public.table (id) ON DELETE CASCADE
81
91
 
82
92
  );
83
93
 
@@ -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;
@@ -0,0 +1,65 @@
1
+ -- Deploy schemas/metaschema_modules_public/tables/namespace_module/table to pg
2
+
3
+ -- requires: schemas/metaschema_modules_public/schema
4
+
5
+ BEGIN;
6
+
7
+ CREATE TABLE metaschema_modules_public.namespace_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
+ namespaces_table_id uuid NOT NULL DEFAULT uuid_nil(),
21
+ namespace_events_table_id uuid NOT NULL DEFAULT uuid_nil(),
22
+
23
+ -- Table names (input to the generator)
24
+ namespaces_table_name text NOT NULL DEFAULT 'namespaces',
25
+ namespace_events_table_name text NOT NULL DEFAULT 'namespace_events',
26
+
27
+ -- API routing (get-or-create: if set, schema is added to this API; if NULL, no API is added)
28
+ api_name text,
29
+ private_api_name text,
30
+
31
+ -- Multi-tenant namespace identity
32
+ membership_type int DEFAULT NULL, -- NULL = database-root (AuthzMembership via app_sprt), non-NULL = entity-scoped (AuthzEntityMembership)
33
+
34
+ -- Entity table for RLS (NULL for app-level namespaces, entity table for entity-scoped namespaces)
35
+ entity_table_id uuid NULL,
36
+
37
+ -- Configurable security policies (NULL = use defaults based on membership_type).
38
+ -- When provided, replaces the default policy set in apply_namespace_security.
39
+ -- Accepts a JSON array of policy objects:
40
+ -- {"$type": "AuthzEntityMembership", "privileges": ["select", "update"], "data": {...}}
41
+ policies jsonb NULL,
42
+
43
+ -- Per-table provisions overrides from blueprint config.
44
+ -- Keys are table keys (namespaces, namespace_events).
45
+ -- When a key is present, the module trigger skips default security for that table;
46
+ -- secure_table_provision applies the custom grants/policies instead.
47
+ provisions jsonb NULL,
48
+
49
+ -- Constraints
50
+ CONSTRAINT namespace_module_db_fkey FOREIGN KEY (database_id) REFERENCES metaschema_public.database (id) ON DELETE CASCADE,
51
+ CONSTRAINT namespace_module_schema_fkey FOREIGN KEY (schema_id) REFERENCES metaschema_public.schema (id) ON DELETE CASCADE,
52
+ CONSTRAINT namespace_module_private_schema_fkey FOREIGN KEY (private_schema_id) REFERENCES metaschema_public.schema (id) ON DELETE CASCADE,
53
+ CONSTRAINT namespace_module_namespaces_table_fkey FOREIGN KEY (namespaces_table_id) REFERENCES metaschema_public.table (id) ON DELETE CASCADE,
54
+ CONSTRAINT namespace_module_events_table_fkey FOREIGN KEY (namespace_events_table_id) REFERENCES metaschema_public.table (id) ON DELETE CASCADE,
55
+ CONSTRAINT namespace_module_entity_table_fkey FOREIGN KEY (entity_table_id) REFERENCES metaschema_public.table (id) ON DELETE CASCADE
56
+ );
57
+
58
+ CREATE INDEX namespace_module_database_id_idx ON metaschema_modules_public.namespace_module ( database_id );
59
+
60
+ -- Unique constraint on (database_id, membership_type) using COALESCE to handle NULLs.
61
+ -- NULL membership_type = app-level, non-NULL = entity-scoped.
62
+ -- Only one namespace module per scope (unlike storage_module which has storage_key).
63
+ CREATE UNIQUE INDEX namespace_module_unique_scope ON metaschema_modules_public.namespace_module ( database_id, COALESCE(membership_type, -1) );
64
+
65
+ COMMIT;
@@ -0,0 +1,51 @@
1
+ -- Deploy schemas/metaschema_modules_public/tables/rate_limit_meters_module/table to pg
2
+
3
+ -- requires: schemas/metaschema_modules_public/schema
4
+
5
+ BEGIN;
6
+
7
+ CREATE TABLE metaschema_modules_public.rate_limit_meters_module (
8
+ id uuid PRIMARY KEY DEFAULT uuidv7(),
9
+ database_id uuid NOT NULL,
10
+
11
+ -- Public schema: rate_limit_overrides table (admin-manageable via GraphQL API)
12
+ schema_id uuid NOT NULL DEFAULT uuid_nil(),
13
+ -- Private schema: rate_limit_state table, check_rate_limit function (internal)
14
+ private_schema_id uuid NOT NULL DEFAULT uuid_nil(),
15
+
16
+ -- State table: sliding window tracking per entity/actor/meter/window (private)
17
+ rate_limit_state_table_id uuid NOT NULL DEFAULT uuid_nil(),
18
+ rate_limit_state_table_name text NOT NULL DEFAULT '',
19
+
20
+ -- Overrides table: per-entity and per-actor rate limit overrides (public)
21
+ rate_limit_overrides_table_id uuid NULL,
22
+ rate_limit_overrides_table_name text NOT NULL DEFAULT '',
23
+
24
+ -- Rate window limits table: per-plan rate limit configuration (public)
25
+ rate_window_limits_table_id uuid NULL,
26
+ rate_window_limits_table_name text NOT NULL DEFAULT '',
27
+
28
+ -- Generated check function (private)
29
+ check_rate_limit_function text NOT NULL DEFAULT '',
30
+
31
+ prefix text NULL,
32
+
33
+ CONSTRAINT db_fkey FOREIGN KEY (database_id) REFERENCES metaschema_public.database (id) ON DELETE CASCADE,
34
+ CONSTRAINT schema_fkey FOREIGN KEY (schema_id) REFERENCES metaschema_public.schema (id) ON DELETE CASCADE,
35
+ CONSTRAINT private_schema_fkey FOREIGN KEY (private_schema_id) REFERENCES metaschema_public.schema (id) ON DELETE CASCADE,
36
+ CONSTRAINT rate_limit_state_table_fkey FOREIGN KEY (rate_limit_state_table_id) REFERENCES metaschema_public.table (id) ON DELETE CASCADE,
37
+ CONSTRAINT rate_limit_overrides_table_fkey FOREIGN KEY (rate_limit_overrides_table_id) REFERENCES metaschema_public.table (id) ON DELETE CASCADE,
38
+ CONSTRAINT rate_window_limits_table_fkey FOREIGN KEY (rate_window_limits_table_id) REFERENCES metaschema_public.table (id) ON DELETE CASCADE,
39
+ CONSTRAINT rate_limit_meters_module_database_id_unique UNIQUE (database_id)
40
+ );
41
+
42
+ CREATE INDEX rate_limit_meters_module_database_id_idx ON metaschema_modules_public.rate_limit_meters_module ( database_id );
43
+
44
+ COMMENT ON CONSTRAINT rate_limit_state_table_fkey
45
+ ON metaschema_modules_public.rate_limit_meters_module IS E'@fieldName rateLimitStateTableByRateLimitStateTableId';
46
+ COMMENT ON CONSTRAINT rate_limit_overrides_table_fkey
47
+ ON metaschema_modules_public.rate_limit_meters_module IS E'@fieldName rateLimitOverridesTableByRateLimitOverridesTableId';
48
+ COMMENT ON CONSTRAINT rate_window_limits_table_fkey
49
+ ON metaschema_modules_public.rate_limit_meters_module IS E'@fieldName rateWindowLimitsTableByRateWindowLimitsTableId';
50
+
51
+ COMMIT;
@@ -20,8 +20,8 @@ CREATE TABLE metaschema_modules_public.realtime_module (
20
20
 
21
21
  -- Partition lifecycle configuration for change_log
22
22
  retention_hours integer NOT NULL DEFAULT 168,
23
- lookahead_hours integer NOT NULL DEFAULT 24,
24
- partition_interval text NOT NULL DEFAULT 'hourly',
23
+ premake int NOT NULL DEFAULT 7,
24
+ "interval" text NOT NULL DEFAULT '1 day',
25
25
 
26
26
  -- NOTIFY hybrid wake-up channel name (NULL = use default)
27
27
  notify_channel text NULL,
@@ -0,0 +1,44 @@
1
+ -- Deploy schemas/metaschema_modules_public/tables/storage_log_module/table to pg
2
+
3
+ -- requires: schemas/metaschema_modules_public/schema
4
+
5
+ BEGIN;
6
+
7
+ CREATE TABLE metaschema_modules_public.storage_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
+ -- Storage log table (partitioned by snapshot_at)
15
+ storage_log_table_id uuid NOT NULL DEFAULT uuid_nil(),
16
+ storage_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 storage_log_table_fkey FOREIGN KEY (storage_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 storage_log_module_database_id_prefix_unique UNIQUE NULLS NOT DISTINCT (database_id, prefix)
40
+ );
41
+
42
+ CREATE INDEX storage_log_module_database_id_idx ON metaschema_modules_public.storage_log_module ( database_id );
43
+
44
+ COMMIT;
@@ -23,18 +23,23 @@ CREATE TABLE metaschema_modules_public.storage_module (
23
23
  -- Multi-tenant storage identity
24
24
  membership_type int DEFAULT NULL, -- NULL = global gate (AuthzMembership via app_sprt), non-NULL = entity-scoped (AuthzEntityMembership)
25
25
 
26
+ -- Storage module discriminator: allows multiple storage modules per entity type.
27
+ -- 'default' is omitted from table names (backward compat), any other value becomes
28
+ -- an infix: {prefix}_{storage_key}_{buckets|files}.
29
+ -- Max 16 chars, lowercase snake_case, cannot be 'buckets'/'files'/'bucket'/'file'.
30
+ storage_key text NOT NULL DEFAULT 'default',
31
+
26
32
  -- Configurable security policies (NULL = use defaults based on membership_type).
27
33
  -- When provided, replaces the default policy set in apply_storage_security.
28
34
  -- Accepts a JSON array of policy objects:
29
35
  -- {"$type": "AuthzEntityMembership", "privileges": ["select", "update"], "data": {...}}
30
36
  policies jsonb NULL,
31
37
 
32
- -- Per-table skip list for apply_storage_security default policies.
33
- -- When a table role name ("files", "buckets") is listed here,
34
- -- apply_storage_security skips its default policies for that table.
35
- -- Used by entity_type_provision to mark tables whose policies are
36
- -- supplied via provisions (secure_table_provision).
37
- skip_default_policy_tables text[] NOT NULL DEFAULT '{}',
38
+ -- Per-table provisions overrides from blueprint config.
39
+ -- Keys are table keys (files, buckets).
40
+ -- When a key is present, the module trigger skips default security for that table;
41
+ -- secure_table_provision applies the custom grants/policies instead.
42
+ provisions jsonb NULL,
38
43
 
39
44
  -- Entity table for RLS (NULL for app-level storage, entity table for entity-scoped storage)
40
45
  entity_table_id uuid NULL,
@@ -76,6 +81,8 @@ CREATE TABLE metaschema_modules_public.storage_module (
76
81
  has_content_hash boolean NOT NULL DEFAULT false, -- Content hash column for dedup + integrity verification
77
82
  has_custom_keys boolean NOT NULL DEFAULT false, -- allow_custom_keys on buckets (implies has_versioning + has_content_hash)
78
83
  has_audit_log boolean NOT NULL DEFAULT false, -- File events audit table: upload, delete, move, rename, download, share events
84
+ has_confirm_upload boolean NOT NULL DEFAULT false, -- Deferred HeadObject confirmation: enqueues storage:confirm_upload job on INSERT, creates status transition functions
85
+ confirm_upload_delay interval NOT NULL DEFAULT '30 seconds', -- Delay before first confirmation attempt (only used when has_confirm_upload = true)
79
86
 
80
87
  -- Generated table ID for file_events (populated by the generator when has_audit_log=true)
81
88
  file_events_table_id uuid NULL DEFAULT NULL,
@@ -93,8 +100,9 @@ CREATE TABLE metaschema_modules_public.storage_module (
93
100
 
94
101
  CREATE INDEX storage_module_database_id_idx ON metaschema_modules_public.storage_module ( database_id );
95
102
 
96
- -- Unique constraint on (database_id, membership_type) using COALESCE to handle NULLs.
97
- -- NULL membership_type = app-level (only one per database), non-NULL = entity-scoped (one per membership_type per database).
98
- CREATE UNIQUE INDEX storage_module_unique_scope ON metaschema_modules_public.storage_module ( database_id, COALESCE(membership_type, -1) );
103
+ -- Unique constraint on (database_id, membership_type, storage_key) using COALESCE to handle NULLs.
104
+ -- NULL membership_type = app-level, non-NULL = entity-scoped. storage_key discriminates
105
+ -- multiple storage modules for the same entity type (e.g. 'default' + 'fn').
106
+ CREATE UNIQUE INDEX storage_module_unique_scope ON metaschema_modules_public.storage_module ( database_id, COALESCE(membership_type, -1), storage_key );
99
107
 
100
108
  COMMIT;
@@ -0,0 +1,44 @@
1
+ -- Deploy schemas/metaschema_modules_public/tables/transfer_log_module/table to pg
2
+
3
+ -- requires: schemas/metaschema_modules_public/schema
4
+
5
+ BEGIN;
6
+
7
+ CREATE TABLE metaschema_modules_public.transfer_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
+ -- Transfer log table (partitioned by created_at)
15
+ transfer_log_table_id uuid NOT NULL DEFAULT uuid_nil(),
16
+ transfer_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 transfer_log_table_fkey FOREIGN KEY (transfer_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 transfer_log_module_database_id_prefix_unique UNIQUE NULLS NOT DISTINCT (database_id, prefix)
40
+ );
41
+
42
+ CREATE INDEX transfer_log_module_database_id_idx ON metaschema_modules_public.transfer_log_module ( database_id );
43
+
44
+ COMMIT;
@@ -19,7 +19,7 @@ CREATE TABLE metaschema_modules_public.user_auth_module (
19
19
  session_credentials_table_id uuid NOT NULL DEFAULT uuid_nil(),
20
20
 
21
21
  audits_table_id uuid NOT NULL DEFAULT uuid_nil(),
22
- audits_table_name text NOT NULL DEFAULT 'audit_logs',
22
+ audits_table_name text NOT NULL DEFAULT 'audit_log_auth',
23
23
 
24
24
  -- api_id uuid NOT NULL REFERENCES services_public.apis (id),
25
25
 
@@ -1,16 +1,16 @@
1
- -- Deploy schemas/metaschema_modules_public/tables/secrets_module/table to pg
1
+ -- Deploy schemas/metaschema_modules_public/tables/user_state_module/table to pg
2
2
 
3
3
  -- requires: schemas/metaschema_modules_public/schema
4
4
 
5
5
  BEGIN;
6
6
 
7
- CREATE TABLE metaschema_modules_public.secrets_module (
7
+ CREATE TABLE metaschema_modules_public.user_state_module (
8
8
  id uuid PRIMARY KEY DEFAULT uuidv7(),
9
9
  database_id uuid NOT NULL,
10
10
  --
11
11
  schema_id uuid NOT NULL DEFAULT uuid_nil(),
12
12
  table_id uuid NOT NULL DEFAULT uuid_nil(),
13
- table_name text NOT NULL DEFAULT 'secrets',
13
+ table_name text NOT NULL DEFAULT 'user_state',
14
14
  --
15
15
  CONSTRAINT db_fkey FOREIGN KEY (database_id) REFERENCES metaschema_public.database (id) ON DELETE CASCADE,
16
16
  CONSTRAINT schema_fkey FOREIGN KEY (schema_id) REFERENCES metaschema_public.schema (id) ON DELETE CASCADE,
@@ -18,6 +18,6 @@ CREATE TABLE metaschema_modules_public.secrets_module (
18
18
 
19
19
  );
20
20
 
21
- CREATE INDEX secrets_module_database_id_idx ON metaschema_modules_public.secrets_module ( database_id );
21
+ CREATE INDEX user_state_module_database_id_idx ON metaschema_modules_public.user_state_module ( database_id );
22
22
 
23
23
  COMMIT;
@@ -1,6 +1,6 @@
1
1
  # metaschema-modules extension
2
2
  comment = 'metaschema-modules extension'
3
- default_version = '0.15.5'
3
+ default_version = '0.26.0'
4
4
  module_pathname = '$libdir/metaschema-modules'
5
5
  requires = 'plpgsql,uuid-ossp,metaschema-schema,services,pgpm-verify'
6
6
  relocatable = false
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pgpm/metaschema-modules",
3
- "version": "0.23.0",
3
+ "version": "0.26.1",
4
4
  "description": "Module metadata handling and dependency tracking",
5
5
  "author": "Dan Lynch <pyramation@gmail.com>",
6
6
  "contributors": [
@@ -21,8 +21,8 @@
21
21
  "test:watch": "jest --watch"
22
22
  },
23
23
  "dependencies": {
24
- "@pgpm/metaschema-schema": "0.23.0",
25
- "@pgpm/verify": "0.23.0"
24
+ "@pgpm/metaschema-schema": "0.26.1",
25
+ "@pgpm/verify": "0.26.0"
26
26
  },
27
27
  "devDependencies": {
28
28
  "pgpm": "^4.23.2"
@@ -35,5 +35,5 @@
35
35
  "bugs": {
36
36
  "url": "https://github.com/constructive-io/pgpm-modules/issues"
37
37
  },
38
- "gitHead": "c051ba5f98dd780c1f69e3ac07c2cc870d1c859d"
38
+ "gitHead": "e1f2e9bec1c91d0751ebe49e9193459191d3c464"
39
39
  }