@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
@@ -894,7 +894,7 @@ CREATE TABLE metaschema_modules_public.user_auth_module (
894
894
  sessions_table_id uuid NOT NULL DEFAULT uuid_nil(),
895
895
  session_credentials_table_id uuid NOT NULL DEFAULT uuid_nil(),
896
896
  audits_table_id uuid NOT NULL DEFAULT uuid_nil(),
897
- audits_table_name text NOT NULL DEFAULT 'audit_logs',
897
+ audits_table_name text NOT NULL DEFAULT 'audit_log_auth',
898
898
  sign_in_function text NOT NULL DEFAULT 'sign_in',
899
899
  sign_up_function text NOT NULL DEFAULT 'sign_up',
900
900
  sign_out_function text NOT NULL DEFAULT 'sign_out',
@@ -1459,7 +1459,7 @@ CREATE TABLE metaschema_modules_public.storage_module (
1459
1459
  membership_type int DEFAULT NULL,
1460
1460
  storage_key text NOT NULL DEFAULT 'default',
1461
1461
  policies jsonb NULL,
1462
- skip_default_policy_tables text[] NOT NULL DEFAULT '{}',
1462
+ provisions jsonb NULL,
1463
1463
  entity_table_id uuid NULL,
1464
1464
  endpoint text NULL,
1465
1465
  public_url_prefix text NULL,
@@ -1532,10 +1532,13 @@ CREATE TABLE metaschema_modules_public.entity_type_provision (
1532
1532
  has_limits boolean NOT NULL DEFAULT false,
1533
1533
  has_profiles boolean NOT NULL DEFAULT false,
1534
1534
  has_levels boolean NOT NULL DEFAULT false,
1535
- has_storage boolean NOT NULL DEFAULT false,
1536
1535
  has_invites boolean NOT NULL DEFAULT false,
1537
1536
  has_invite_achievements boolean NOT NULL DEFAULT false,
1538
- storage_config jsonb DEFAULT NULL,
1537
+ storage jsonb DEFAULT NULL,
1538
+ namespaces jsonb DEFAULT NULL,
1539
+ functions jsonb DEFAULT NULL,
1540
+ graphs jsonb DEFAULT NULL,
1541
+ agents jsonb DEFAULT NULL,
1539
1542
  skip_entity_policies boolean NOT NULL DEFAULT false,
1540
1543
  table_provision jsonb DEFAULT NULL,
1541
1544
  out_membership_type int DEFAULT NULL,
@@ -1547,6 +1550,16 @@ CREATE TABLE metaschema_modules_public.entity_type_provision (
1547
1550
  out_files_table_id uuid DEFAULT NULL,
1548
1551
  out_path_shares_table_id uuid DEFAULT NULL,
1549
1552
  out_invites_module_id uuid DEFAULT NULL,
1553
+ out_namespace_module_id uuid DEFAULT NULL,
1554
+ out_namespaces_table_id uuid DEFAULT NULL,
1555
+ out_namespace_events_table_id uuid DEFAULT NULL,
1556
+ out_function_module_id uuid DEFAULT NULL,
1557
+ out_definitions_table_id uuid DEFAULT NULL,
1558
+ out_invocations_table_id uuid DEFAULT NULL,
1559
+ out_execution_logs_table_id uuid DEFAULT NULL,
1560
+ out_graph_module_id uuid DEFAULT NULL,
1561
+ out_graphs_table_id uuid DEFAULT NULL,
1562
+ out_agent_module_id uuid DEFAULT NULL,
1550
1563
  CONSTRAINT entity_type_provision_unique_prefix
1551
1564
  UNIQUE (database_id, prefix),
1552
1565
  CONSTRAINT entity_type_provision_db_fkey
@@ -1608,18 +1621,13 @@ COMMENT ON COLUMN metaschema_modules_public.entity_type_provision.has_levels IS
1608
1621
  Levels provide gamification/achievement tracking for members.
1609
1622
  When true, creates level steps, achievements, and level tables with security.';
1610
1623
 
1611
- COMMENT ON COLUMN metaschema_modules_public.entity_type_provision.has_storage IS 'Whether to provision storage_module for this type. Defaults to false.
1612
- When true, creates {prefix}_buckets and {prefix}_files tables
1613
- with entity-scoped RLS (AuthzEntityMembership) using the entity''s membership_type.
1614
- Storage tables get owner_id FK to the entity table, so files are owned by the entity.';
1615
-
1616
1624
  COMMENT ON COLUMN metaschema_modules_public.entity_type_provision.has_invites IS 'Whether to provision invites_module for this type. Defaults to false.
1617
1625
  When true, the trigger inserts a row into invites_module which in turn
1618
1626
  (via insert_invites_module BEFORE INSERT) creates {prefix}_invites and
1619
1627
  {prefix}_claimed_invites tables plus the submit_{prefix}_invite_code() function.
1620
- Symmetric counterpart of has_storage. Re-provisioning is idempotent: the
1621
- UNIQUE (database_id, membership_type) constraint on invites_module combined with
1622
- ON CONFLICT DO NOTHING in the fan-out makes repeated INSERTs safe.';
1628
+ Re-provisioning is idempotent: the UNIQUE (database_id, membership_type) constraint
1629
+ on invites_module combined with ON CONFLICT DO NOTHING in the fan-out makes
1630
+ repeated INSERTs safe.';
1623
1631
 
1624
1632
  COMMENT ON COLUMN metaschema_modules_public.entity_type_provision.has_invite_achievements IS 'Whether to auto-attach an EventTracker to the claimed_invites table for invite-based
1625
1633
  achievements. Defaults to false. Requires has_invites=true AND has_levels=true.
@@ -1682,10 +1690,11 @@ COMMENT ON COLUMN metaschema_modules_public.entity_type_provision.out_entity_tab
1682
1690
  COMMENT ON COLUMN metaschema_modules_public.entity_type_provision.out_installed_modules IS 'Output: array of installed module labels (e.g. ARRAY[''permissions_module:data_room'', ''memberships_module:data_room'', ''invites_module:data_room'']).
1683
1691
  Populated by the trigger. Useful for verifying which modules were provisioned.';
1684
1692
 
1685
- COMMENT ON COLUMN metaschema_modules_public.entity_type_provision.storage_config IS 'Optional JSON array of storage module definitions. Each element provisions a separate
1686
- storage module with its own tables ({prefix}_{storage_key}_buckets/files), RLS policies,
1687
- and feature flags. Only used when has_storage = true; ignored otherwise.
1688
- NULL = provision a single default storage module with all defaults.
1693
+ COMMENT ON COLUMN metaschema_modules_public.entity_type_provision.storage IS 'Optional JSON array of storage module definitions. Presence triggers provisioning
1694
+ (same inference model as namespaces, functions, agents).
1695
+ Each element provisions a separate storage module with its own tables
1696
+ ({prefix}_{storage_key}_buckets/files), RLS policies, and feature flags.
1697
+ NULL = do not provision storage. ''[{}]'' = provision one default storage module.
1689
1698
  Each array element recognizes (all optional):
1690
1699
  - storage_key (text) module discriminator, max 16 chars, lowercase snake_case.
1691
1700
  Defaults to ''default'' (omitted from table names).
@@ -1707,20 +1716,60 @@ COMMENT ON COLUMN metaschema_modules_public.entity_type_provision.storage_config
1707
1716
  - provisions (jsonb object) per-table customization keyed by "files" or "buckets".
1708
1717
  Each value: { nodes, fields, grants, use_rls, policies }.
1709
1718
  Example (single module, backward compat):
1710
- storage_config := ''[{"buckets": [{"name": "documents"}]}]''::jsonb
1719
+ storage := ''[{"buckets": [{"name": "documents"}]}]''::jsonb
1711
1720
  Example (multi-module):
1712
- storage_config := ''[{"has_path_shares": true, "buckets": [{"name": "documents"}]}, {"storage_key": "fn", "has_custom_keys": true, "buckets": [{"name": "functions"}]}]''::jsonb';
1721
+ storage := ''[{"has_path_shares": true, "buckets": [{"name": "documents"}]}, {"storage_key": "fn", "has_custom_keys": true, "buckets": [{"name": "functions"}]}]''::jsonb';
1713
1722
 
1714
- COMMENT ON COLUMN metaschema_modules_public.entity_type_provision.out_storage_module_id IS 'Output: the UUID of the storage_module row created for this entity type. Populated by the trigger when has_storage=true.';
1723
+ COMMENT ON COLUMN metaschema_modules_public.entity_type_provision.out_storage_module_id IS '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.';
1715
1724
 
1716
- COMMENT ON COLUMN metaschema_modules_public.entity_type_provision.out_buckets_table_id IS 'Output: the UUID of the generated buckets table (e.g. data_room_buckets). Populated by the trigger when has_storage=true.';
1725
+ COMMENT ON COLUMN metaschema_modules_public.entity_type_provision.out_buckets_table_id IS '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.';
1717
1726
 
1718
- COMMENT ON COLUMN metaschema_modules_public.entity_type_provision.out_files_table_id IS 'Output: the UUID of the generated files table (e.g. data_room_files). Populated by the trigger when has_storage=true.';
1727
+ COMMENT ON COLUMN metaschema_modules_public.entity_type_provision.out_files_table_id IS '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.';
1719
1728
 
1720
1729
  COMMENT ON COLUMN metaschema_modules_public.entity_type_provision.out_invites_module_id IS 'Output: the UUID of the invites_module row created for this entity type. Populated by the trigger when has_invites=true.
1721
1730
  NULL when has_invites=false, or when re-provisioning hits ON CONFLICT DO NOTHING
1722
1731
  (i.e. the invites_module row was created in a previous run).';
1723
1732
 
1733
+ COMMENT ON COLUMN metaschema_modules_public.entity_type_provision.namespaces IS 'Optional JSON array of namespace module definitions. Presence triggers provisioning.
1734
+ NULL = do not provision namespaces. ''[{}]'' = provision one default namespace module.
1735
+ Each element recognizes (all optional):
1736
+ - key (text) module discriminator. Defaults to ''default''.
1737
+ - policies (jsonb array) RLS policy overrides. NULL = apply defaults from apply_namespace_security().
1738
+ Creates {prefix}_namespaces (or {prefix}_{key}_namespaces for non-default keys)
1739
+ with entity-scoped RLS (AuthzEntityMembership) and a rename proxy trigger.
1740
+ Registers manage_namespaces permission bit on first provision.
1741
+ Example: namespaces := ''[{}]''::jsonb';
1742
+
1743
+ COMMENT ON COLUMN metaschema_modules_public.entity_type_provision.functions IS 'Optional JSON array of function module definitions. Presence triggers provisioning.
1744
+ NULL = do not provision functions. ''[{}]'' = provision one default function module.
1745
+ Each element recognizes (all optional):
1746
+ - key (text) module discriminator. Defaults to ''default''.
1747
+ - policies (jsonb array) RLS policy overrides. NULL = apply defaults from apply_function_security().
1748
+ Creates {prefix}_function_definitions (or {prefix}_{key}_function_definitions for non-default keys)
1749
+ with entity-scoped RLS and a job trigger dispatching function:provision tasks.
1750
+ Registers manage_functions + invoke_functions permission bits on first provision.
1751
+ Example: functions := ''[{}]''::jsonb';
1752
+
1753
+ COMMENT ON COLUMN metaschema_modules_public.entity_type_provision.graphs IS 'Optional JSON array of graph module definitions. Presence triggers provisioning.
1754
+ NULL = do not provision graphs. ''[{}]'' = provision one default graph module.
1755
+ Each element recognizes (all optional):
1756
+ - key (text) module discriminator. Defaults to ''default''.
1757
+ - policies (jsonb array) RLS policy overrides. NULL = apply defaults from apply_graph_security().
1758
+ Registers manage_graphs + execute_graphs permission bits on first provision.
1759
+ Graph module requires a merkle_store_module_id dependency, so entity_type_provision
1760
+ only registers permissions here. The graph module itself must be provisioned
1761
+ separately with the merkle store dependency resolved.
1762
+ Example: graphs := ''[{}]''::jsonb';
1763
+
1764
+ COMMENT ON COLUMN metaschema_modules_public.entity_type_provision.out_namespace_module_id IS 'Output: the UUID of the namespace_module row created (or found) for this entity type.
1765
+ Populated by the trigger when namespaces is non-NULL. NULL otherwise.';
1766
+
1767
+ COMMENT ON COLUMN metaschema_modules_public.entity_type_provision.out_namespaces_table_id IS 'Output: the UUID of the generated namespaces table (e.g. data_room_namespaces).
1768
+ Populated by the trigger when namespaces is non-NULL. NULL otherwise.';
1769
+
1770
+ COMMENT ON COLUMN metaschema_modules_public.entity_type_provision.out_namespace_events_table_id IS 'Output: the UUID of the generated namespace_events partitioned table (e.g. data_room_namespace_events).
1771
+ Monthly partitioned, 12-month retention. Populated by the trigger when namespaces is non-NULL. NULL otherwise.';
1772
+
1724
1773
  CREATE TABLE metaschema_modules_public.rate_limits_module (
1725
1774
  id uuid PRIMARY KEY DEFAULT uuidv7(),
1726
1775
  database_id uuid NOT NULL,
@@ -2118,6 +2167,8 @@ CREATE TABLE metaschema_modules_public.billing_module (
2118
2167
  balances_table_name text NOT NULL DEFAULT '',
2119
2168
  meter_credits_table_id uuid NOT NULL DEFAULT uuid_nil(),
2120
2169
  meter_credits_table_name text NOT NULL DEFAULT '',
2170
+ meter_sources_table_id uuid NOT NULL DEFAULT uuid_nil(),
2171
+ meter_sources_table_name text NOT NULL DEFAULT '',
2121
2172
  record_usage_function text NOT NULL DEFAULT '',
2122
2173
  prefix text NULL,
2123
2174
  CONSTRAINT db_fkey
@@ -2152,6 +2203,10 @@ CREATE TABLE metaschema_modules_public.billing_module (
2152
2203
  FOREIGN KEY(meter_credits_table_id)
2153
2204
  REFERENCES metaschema_public.table (id)
2154
2205
  ON DELETE CASCADE,
2206
+ CONSTRAINT meter_sources_table_fkey
2207
+ FOREIGN KEY(meter_sources_table_id)
2208
+ REFERENCES metaschema_public.table (id)
2209
+ ON DELETE CASCADE,
2155
2210
  CONSTRAINT billing_module_database_id_unique
2156
2211
  UNIQUE (database_id)
2157
2212
  );
@@ -2363,4 +2418,490 @@ CREATE INDEX config_secrets_org_module_schema_id_idx ON metaschema_modules_publi
2363
2418
 
2364
2419
  CREATE INDEX config_secrets_org_module_table_id_idx ON metaschema_modules_public.config_secrets_org_module (table_id);
2365
2420
 
2366
- COMMENT ON TABLE metaschema_modules_public.config_secrets_org_module IS 'Config row for the config_secrets_org_module, which provisions an organization-scoped encrypted key-value secrets store with manage_secrets permission and entity-membership RLS.';
2421
+ COMMENT ON TABLE metaschema_modules_public.config_secrets_org_module IS 'Config row for the config_secrets_org_module, which provisions an organization-scoped encrypted key-value secrets store with manage_secrets permission and entity-membership RLS.';
2422
+
2423
+ CREATE TABLE metaschema_modules_public.inference_log_module (
2424
+ id uuid PRIMARY KEY DEFAULT uuidv7(),
2425
+ database_id uuid NOT NULL,
2426
+ schema_id uuid NOT NULL DEFAULT uuid_nil(),
2427
+ private_schema_id uuid NOT NULL DEFAULT uuid_nil(),
2428
+ inference_log_table_id uuid NOT NULL DEFAULT uuid_nil(),
2429
+ inference_log_table_name text NOT NULL DEFAULT '',
2430
+ usage_daily_table_id uuid NOT NULL DEFAULT uuid_nil(),
2431
+ usage_daily_table_name text NOT NULL DEFAULT '',
2432
+ "interval" text NOT NULL DEFAULT '1 month',
2433
+ retention text NOT NULL DEFAULT '12 months',
2434
+ premake int NOT NULL DEFAULT 2,
2435
+ scope text NOT NULL DEFAULT 'app',
2436
+ actor_fk_table_id uuid NULL,
2437
+ entity_fk_table_id uuid NULL,
2438
+ prefix text NULL,
2439
+ CONSTRAINT db_fkey
2440
+ FOREIGN KEY(database_id)
2441
+ REFERENCES metaschema_public.database (id)
2442
+ ON DELETE CASCADE,
2443
+ CONSTRAINT schema_fkey
2444
+ FOREIGN KEY(schema_id)
2445
+ REFERENCES metaschema_public.schema (id)
2446
+ ON DELETE CASCADE,
2447
+ CONSTRAINT private_schema_fkey
2448
+ FOREIGN KEY(private_schema_id)
2449
+ REFERENCES metaschema_public.schema (id)
2450
+ ON DELETE CASCADE,
2451
+ CONSTRAINT inference_log_table_fkey
2452
+ FOREIGN KEY(inference_log_table_id)
2453
+ REFERENCES metaschema_public.table (id)
2454
+ ON DELETE CASCADE,
2455
+ CONSTRAINT usage_daily_table_fkey
2456
+ FOREIGN KEY(usage_daily_table_id)
2457
+ REFERENCES metaschema_public.table (id)
2458
+ ON DELETE CASCADE,
2459
+ CONSTRAINT inference_log_module_database_id_prefix_unique
2460
+ UNIQUE NULLS NOT DISTINCT (database_id, prefix)
2461
+ );
2462
+
2463
+ CREATE INDEX inference_log_module_database_id_idx ON metaschema_modules_public.inference_log_module (database_id);
2464
+
2465
+ CREATE TABLE metaschema_modules_public.compute_log_module (
2466
+ id uuid PRIMARY KEY DEFAULT uuidv7(),
2467
+ database_id uuid NOT NULL,
2468
+ schema_id uuid NOT NULL DEFAULT uuid_nil(),
2469
+ private_schema_id uuid NOT NULL DEFAULT uuid_nil(),
2470
+ compute_log_table_id uuid NOT NULL DEFAULT uuid_nil(),
2471
+ compute_log_table_name text NOT NULL DEFAULT '',
2472
+ usage_daily_table_id uuid NOT NULL DEFAULT uuid_nil(),
2473
+ usage_daily_table_name text NOT NULL DEFAULT '',
2474
+ "interval" text NOT NULL DEFAULT '1 month',
2475
+ retention text NOT NULL DEFAULT '12 months',
2476
+ premake int NOT NULL DEFAULT 2,
2477
+ scope text NOT NULL DEFAULT 'app',
2478
+ actor_fk_table_id uuid NULL,
2479
+ entity_fk_table_id uuid NULL,
2480
+ prefix text NULL,
2481
+ CONSTRAINT db_fkey
2482
+ FOREIGN KEY(database_id)
2483
+ REFERENCES metaschema_public.database (id)
2484
+ ON DELETE CASCADE,
2485
+ CONSTRAINT schema_fkey
2486
+ FOREIGN KEY(schema_id)
2487
+ REFERENCES metaschema_public.schema (id)
2488
+ ON DELETE CASCADE,
2489
+ CONSTRAINT private_schema_fkey
2490
+ FOREIGN KEY(private_schema_id)
2491
+ REFERENCES metaschema_public.schema (id)
2492
+ ON DELETE CASCADE,
2493
+ CONSTRAINT compute_log_table_fkey
2494
+ FOREIGN KEY(compute_log_table_id)
2495
+ REFERENCES metaschema_public.table (id)
2496
+ ON DELETE CASCADE,
2497
+ CONSTRAINT usage_daily_table_fkey
2498
+ FOREIGN KEY(usage_daily_table_id)
2499
+ REFERENCES metaschema_public.table (id)
2500
+ ON DELETE CASCADE,
2501
+ CONSTRAINT compute_log_module_database_id_prefix_unique
2502
+ UNIQUE NULLS NOT DISTINCT (database_id, prefix)
2503
+ );
2504
+
2505
+ CREATE INDEX compute_log_module_database_id_idx ON metaschema_modules_public.compute_log_module (database_id);
2506
+
2507
+ CREATE TABLE metaschema_modules_public.transfer_log_module (
2508
+ id uuid PRIMARY KEY DEFAULT uuidv7(),
2509
+ database_id uuid NOT NULL,
2510
+ schema_id uuid NOT NULL DEFAULT uuid_nil(),
2511
+ private_schema_id uuid NOT NULL DEFAULT uuid_nil(),
2512
+ transfer_log_table_id uuid NOT NULL DEFAULT uuid_nil(),
2513
+ transfer_log_table_name text NOT NULL DEFAULT '',
2514
+ usage_daily_table_id uuid NOT NULL DEFAULT uuid_nil(),
2515
+ usage_daily_table_name text NOT NULL DEFAULT '',
2516
+ "interval" text NOT NULL DEFAULT '1 month',
2517
+ retention text NOT NULL DEFAULT '12 months',
2518
+ premake int NOT NULL DEFAULT 2,
2519
+ scope text NOT NULL DEFAULT 'app',
2520
+ actor_fk_table_id uuid NULL,
2521
+ entity_fk_table_id uuid NULL,
2522
+ prefix text NULL,
2523
+ CONSTRAINT db_fkey
2524
+ FOREIGN KEY(database_id)
2525
+ REFERENCES metaschema_public.database (id)
2526
+ ON DELETE CASCADE,
2527
+ CONSTRAINT schema_fkey
2528
+ FOREIGN KEY(schema_id)
2529
+ REFERENCES metaschema_public.schema (id)
2530
+ ON DELETE CASCADE,
2531
+ CONSTRAINT private_schema_fkey
2532
+ FOREIGN KEY(private_schema_id)
2533
+ REFERENCES metaschema_public.schema (id)
2534
+ ON DELETE CASCADE,
2535
+ CONSTRAINT transfer_log_table_fkey
2536
+ FOREIGN KEY(transfer_log_table_id)
2537
+ REFERENCES metaschema_public.table (id)
2538
+ ON DELETE CASCADE,
2539
+ CONSTRAINT usage_daily_table_fkey
2540
+ FOREIGN KEY(usage_daily_table_id)
2541
+ REFERENCES metaschema_public.table (id)
2542
+ ON DELETE CASCADE,
2543
+ CONSTRAINT transfer_log_module_database_id_prefix_unique
2544
+ UNIQUE NULLS NOT DISTINCT (database_id, prefix)
2545
+ );
2546
+
2547
+ CREATE INDEX transfer_log_module_database_id_idx ON metaschema_modules_public.transfer_log_module (database_id);
2548
+
2549
+ CREATE TABLE metaschema_modules_public.storage_log_module (
2550
+ id uuid PRIMARY KEY DEFAULT uuidv7(),
2551
+ database_id uuid NOT NULL,
2552
+ schema_id uuid NOT NULL DEFAULT uuid_nil(),
2553
+ private_schema_id uuid NOT NULL DEFAULT uuid_nil(),
2554
+ storage_log_table_id uuid NOT NULL DEFAULT uuid_nil(),
2555
+ storage_log_table_name text NOT NULL DEFAULT '',
2556
+ usage_daily_table_id uuid NOT NULL DEFAULT uuid_nil(),
2557
+ usage_daily_table_name text NOT NULL DEFAULT '',
2558
+ "interval" text NOT NULL DEFAULT '1 month',
2559
+ retention text NOT NULL DEFAULT '12 months',
2560
+ premake int NOT NULL DEFAULT 2,
2561
+ scope text NOT NULL DEFAULT 'app',
2562
+ actor_fk_table_id uuid NULL,
2563
+ entity_fk_table_id uuid NULL,
2564
+ prefix text NULL,
2565
+ CONSTRAINT db_fkey
2566
+ FOREIGN KEY(database_id)
2567
+ REFERENCES metaschema_public.database (id)
2568
+ ON DELETE CASCADE,
2569
+ CONSTRAINT schema_fkey
2570
+ FOREIGN KEY(schema_id)
2571
+ REFERENCES metaschema_public.schema (id)
2572
+ ON DELETE CASCADE,
2573
+ CONSTRAINT private_schema_fkey
2574
+ FOREIGN KEY(private_schema_id)
2575
+ REFERENCES metaschema_public.schema (id)
2576
+ ON DELETE CASCADE,
2577
+ CONSTRAINT storage_log_table_fkey
2578
+ FOREIGN KEY(storage_log_table_id)
2579
+ REFERENCES metaschema_public.table (id)
2580
+ ON DELETE CASCADE,
2581
+ CONSTRAINT usage_daily_table_fkey
2582
+ FOREIGN KEY(usage_daily_table_id)
2583
+ REFERENCES metaschema_public.table (id)
2584
+ ON DELETE CASCADE,
2585
+ CONSTRAINT storage_log_module_database_id_prefix_unique
2586
+ UNIQUE NULLS NOT DISTINCT (database_id, prefix)
2587
+ );
2588
+
2589
+ CREATE INDEX storage_log_module_database_id_idx ON metaschema_modules_public.storage_log_module (database_id);
2590
+
2591
+ CREATE TABLE metaschema_modules_public.db_usage_module (
2592
+ id uuid PRIMARY KEY DEFAULT uuidv7(),
2593
+ database_id uuid NOT NULL,
2594
+ schema_id uuid NOT NULL DEFAULT uuid_nil(),
2595
+ private_schema_id uuid NOT NULL DEFAULT uuid_nil(),
2596
+ table_stats_log_table_id uuid NOT NULL DEFAULT uuid_nil(),
2597
+ table_stats_log_table_name text NOT NULL DEFAULT '',
2598
+ table_stats_daily_table_id uuid NOT NULL DEFAULT uuid_nil(),
2599
+ table_stats_daily_table_name text NOT NULL DEFAULT '',
2600
+ query_stats_log_table_id uuid NOT NULL DEFAULT uuid_nil(),
2601
+ query_stats_log_table_name text NOT NULL DEFAULT '',
2602
+ query_stats_daily_table_id uuid NOT NULL DEFAULT uuid_nil(),
2603
+ query_stats_daily_table_name text NOT NULL DEFAULT '',
2604
+ "interval" text NOT NULL DEFAULT '1 month',
2605
+ retention text NOT NULL DEFAULT '12 months',
2606
+ premake int NOT NULL DEFAULT 2,
2607
+ scope text NOT NULL DEFAULT 'app',
2608
+ prefix text NULL,
2609
+ CONSTRAINT db_fkey
2610
+ FOREIGN KEY(database_id)
2611
+ REFERENCES metaschema_public.database (id)
2612
+ ON DELETE CASCADE,
2613
+ CONSTRAINT schema_fkey
2614
+ FOREIGN KEY(schema_id)
2615
+ REFERENCES metaschema_public.schema (id)
2616
+ ON DELETE CASCADE,
2617
+ CONSTRAINT private_schema_fkey
2618
+ FOREIGN KEY(private_schema_id)
2619
+ REFERENCES metaschema_public.schema (id)
2620
+ ON DELETE CASCADE,
2621
+ CONSTRAINT table_stats_log_table_fkey
2622
+ FOREIGN KEY(table_stats_log_table_id)
2623
+ REFERENCES metaschema_public.table (id)
2624
+ ON DELETE CASCADE,
2625
+ CONSTRAINT table_stats_daily_table_fkey
2626
+ FOREIGN KEY(table_stats_daily_table_id)
2627
+ REFERENCES metaschema_public.table (id)
2628
+ ON DELETE CASCADE,
2629
+ CONSTRAINT query_stats_log_table_fkey
2630
+ FOREIGN KEY(query_stats_log_table_id)
2631
+ REFERENCES metaschema_public.table (id)
2632
+ ON DELETE CASCADE,
2633
+ CONSTRAINT query_stats_daily_table_fkey
2634
+ FOREIGN KEY(query_stats_daily_table_id)
2635
+ REFERENCES metaschema_public.table (id)
2636
+ ON DELETE CASCADE,
2637
+ CONSTRAINT db_usage_module_database_id_prefix_unique
2638
+ UNIQUE NULLS NOT DISTINCT (database_id, prefix)
2639
+ );
2640
+
2641
+ CREATE INDEX db_usage_module_database_id_idx ON metaschema_modules_public.db_usage_module (database_id);
2642
+
2643
+ CREATE TABLE metaschema_modules_public.agent_module (
2644
+ id uuid PRIMARY KEY DEFAULT uuidv7(),
2645
+ database_id uuid NOT NULL,
2646
+ schema_id uuid NOT NULL DEFAULT uuid_nil(),
2647
+ private_schema_id uuid NOT NULL DEFAULT uuid_nil(),
2648
+ thread_table_id uuid NOT NULL DEFAULT uuid_nil(),
2649
+ message_table_id uuid NOT NULL DEFAULT uuid_nil(),
2650
+ task_table_id uuid NOT NULL DEFAULT uuid_nil(),
2651
+ prompts_table_id uuid NOT NULL DEFAULT uuid_nil(),
2652
+ knowledge_table_id uuid DEFAULT NULL,
2653
+ thread_table_name text NOT NULL DEFAULT 'agent_thread',
2654
+ message_table_name text NOT NULL DEFAULT 'agent_message',
2655
+ task_table_name text NOT NULL DEFAULT 'agent_task',
2656
+ prompts_table_name text NOT NULL DEFAULT 'agent_prompt',
2657
+ knowledge_table_name text NOT NULL DEFAULT 'agent_knowledge',
2658
+ has_knowledge boolean NOT NULL DEFAULT false,
2659
+ api_name text DEFAULT 'agent',
2660
+ membership_type int DEFAULT NULL,
2661
+ entity_table_id uuid NULL,
2662
+ policies jsonb NULL,
2663
+ knowledge_config jsonb NULL,
2664
+ knowledge_policies jsonb NULL,
2665
+ provisions jsonb NULL,
2666
+ CONSTRAINT agent_module_db_fkey
2667
+ FOREIGN KEY(database_id)
2668
+ REFERENCES metaschema_public.database (id)
2669
+ ON DELETE CASCADE,
2670
+ CONSTRAINT agent_module_schema_fkey
2671
+ FOREIGN KEY(schema_id)
2672
+ REFERENCES metaschema_public.schema (id)
2673
+ ON DELETE CASCADE,
2674
+ CONSTRAINT agent_module_private_schema_fkey
2675
+ FOREIGN KEY(private_schema_id)
2676
+ REFERENCES metaschema_public.schema (id)
2677
+ ON DELETE CASCADE,
2678
+ CONSTRAINT agent_module_thread_table_fkey
2679
+ FOREIGN KEY(thread_table_id)
2680
+ REFERENCES metaschema_public.table (id)
2681
+ ON DELETE CASCADE,
2682
+ CONSTRAINT agent_module_message_table_fkey
2683
+ FOREIGN KEY(message_table_id)
2684
+ REFERENCES metaschema_public.table (id)
2685
+ ON DELETE CASCADE,
2686
+ CONSTRAINT agent_module_task_table_fkey
2687
+ FOREIGN KEY(task_table_id)
2688
+ REFERENCES metaschema_public.table (id)
2689
+ ON DELETE CASCADE,
2690
+ CONSTRAINT agent_module_prompts_table_fkey
2691
+ FOREIGN KEY(prompts_table_id)
2692
+ REFERENCES metaschema_public.table (id)
2693
+ ON DELETE CASCADE,
2694
+ CONSTRAINT agent_module_knowledge_table_fkey
2695
+ FOREIGN KEY(knowledge_table_id)
2696
+ REFERENCES metaschema_public.table (id)
2697
+ ON DELETE CASCADE,
2698
+ CONSTRAINT agent_module_entity_table_fkey
2699
+ FOREIGN KEY(entity_table_id)
2700
+ REFERENCES metaschema_public.table (id)
2701
+ ON DELETE CASCADE
2702
+ );
2703
+
2704
+ CREATE INDEX agent_module_database_id_idx ON metaschema_modules_public.agent_module (database_id);
2705
+
2706
+ CREATE UNIQUE INDEX agent_module_unique_scope ON metaschema_modules_public.agent_module (database_id, (COALESCE(membership_type, -1)));
2707
+
2708
+ CREATE TABLE metaschema_modules_public.merkle_store_module (
2709
+ id uuid PRIMARY KEY DEFAULT uuidv7(),
2710
+ database_id uuid NOT NULL,
2711
+ schema_id uuid NOT NULL DEFAULT uuid_nil(),
2712
+ public_schema_name text,
2713
+ object_table_id uuid NOT NULL DEFAULT uuid_nil(),
2714
+ store_table_id uuid NOT NULL DEFAULT uuid_nil(),
2715
+ commit_table_id uuid NOT NULL DEFAULT uuid_nil(),
2716
+ ref_table_id uuid NOT NULL DEFAULT uuid_nil(),
2717
+ prefix text NOT NULL DEFAULT '',
2718
+ api_name text,
2719
+ scope_field text NOT NULL DEFAULT 'scope_id',
2720
+ created_at timestamptz NOT NULL DEFAULT now(),
2721
+ CONSTRAINT db_fkey
2722
+ FOREIGN KEY(database_id)
2723
+ REFERENCES metaschema_public.database (id)
2724
+ ON DELETE CASCADE,
2725
+ CONSTRAINT schema_fkey
2726
+ FOREIGN KEY(schema_id)
2727
+ REFERENCES metaschema_public.schema (id)
2728
+ ON DELETE CASCADE,
2729
+ CONSTRAINT object_table_fkey
2730
+ FOREIGN KEY(object_table_id)
2731
+ REFERENCES metaschema_public.table (id)
2732
+ ON DELETE CASCADE,
2733
+ CONSTRAINT store_table_fkey
2734
+ FOREIGN KEY(store_table_id)
2735
+ REFERENCES metaschema_public.table (id)
2736
+ ON DELETE CASCADE,
2737
+ CONSTRAINT commit_table_fkey
2738
+ FOREIGN KEY(commit_table_id)
2739
+ REFERENCES metaschema_public.table (id)
2740
+ ON DELETE CASCADE,
2741
+ CONSTRAINT ref_table_fkey
2742
+ FOREIGN KEY(ref_table_id)
2743
+ REFERENCES metaschema_public.table (id)
2744
+ ON DELETE CASCADE,
2745
+ CONSTRAINT merkle_store_module_database_prefix_unique
2746
+ UNIQUE (database_id, prefix)
2747
+ );
2748
+
2749
+ CREATE INDEX merkle_store_module_database_id_idx ON metaschema_modules_public.merkle_store_module (database_id);
2750
+
2751
+ CREATE TABLE metaschema_modules_public.graph_module (
2752
+ id uuid PRIMARY KEY DEFAULT uuidv7(),
2753
+ database_id uuid NOT NULL,
2754
+ public_schema_id uuid NOT NULL DEFAULT uuid_nil(),
2755
+ private_schema_id uuid NOT NULL DEFAULT uuid_nil(),
2756
+ public_schema_name text,
2757
+ private_schema_name text,
2758
+ prefix text NOT NULL DEFAULT '',
2759
+ merkle_store_module_id uuid NOT NULL,
2760
+ graphs_table_id uuid NOT NULL DEFAULT uuid_nil(),
2761
+ executions_table_id uuid NOT NULL DEFAULT uuid_nil(),
2762
+ outputs_table_id uuid NOT NULL DEFAULT uuid_nil(),
2763
+ api_name text,
2764
+ private_api_name text,
2765
+ scope_field text NOT NULL DEFAULT 'scope_id',
2766
+ membership_type int DEFAULT NULL,
2767
+ entity_table_id uuid NULL,
2768
+ policies jsonb NULL,
2769
+ provisions jsonb NULL,
2770
+ created_at timestamptz NOT NULL DEFAULT now(),
2771
+ CONSTRAINT db_fkey
2772
+ FOREIGN KEY(database_id)
2773
+ REFERENCES metaschema_public.database (id)
2774
+ ON DELETE CASCADE,
2775
+ CONSTRAINT public_schema_fkey
2776
+ FOREIGN KEY(public_schema_id)
2777
+ REFERENCES metaschema_public.schema (id)
2778
+ ON DELETE CASCADE,
2779
+ CONSTRAINT private_schema_fkey
2780
+ FOREIGN KEY(private_schema_id)
2781
+ REFERENCES metaschema_public.schema (id)
2782
+ ON DELETE CASCADE,
2783
+ CONSTRAINT merkle_store_fkey
2784
+ FOREIGN KEY(merkle_store_module_id)
2785
+ REFERENCES metaschema_modules_public.merkle_store_module (id)
2786
+ ON DELETE CASCADE,
2787
+ CONSTRAINT graphs_table_fkey
2788
+ FOREIGN KEY(graphs_table_id)
2789
+ REFERENCES metaschema_public.table (id)
2790
+ ON DELETE CASCADE,
2791
+ CONSTRAINT executions_table_fkey
2792
+ FOREIGN KEY(executions_table_id)
2793
+ REFERENCES metaschema_public.table (id)
2794
+ ON DELETE CASCADE,
2795
+ CONSTRAINT outputs_table_fkey
2796
+ FOREIGN KEY(outputs_table_id)
2797
+ REFERENCES metaschema_public.table (id)
2798
+ ON DELETE CASCADE,
2799
+ CONSTRAINT graph_module_entity_table_fkey
2800
+ FOREIGN KEY(entity_table_id)
2801
+ REFERENCES metaschema_public.table (id)
2802
+ ON DELETE CASCADE,
2803
+ CONSTRAINT graph_module_database_merkle_unique
2804
+ UNIQUE (database_id, merkle_store_module_id)
2805
+ );
2806
+
2807
+ CREATE INDEX graph_module_database_id_idx ON metaschema_modules_public.graph_module (database_id);
2808
+
2809
+ CREATE TABLE metaschema_modules_public.namespace_module (
2810
+ id uuid PRIMARY KEY DEFAULT uuidv7(),
2811
+ database_id uuid NOT NULL,
2812
+ schema_id uuid NOT NULL DEFAULT uuid_nil(),
2813
+ private_schema_id uuid NOT NULL DEFAULT uuid_nil(),
2814
+ public_schema_name text,
2815
+ private_schema_name text,
2816
+ namespaces_table_id uuid NOT NULL DEFAULT uuid_nil(),
2817
+ namespace_events_table_id uuid NOT NULL DEFAULT uuid_nil(),
2818
+ namespaces_table_name text NOT NULL DEFAULT 'namespaces',
2819
+ namespace_events_table_name text NOT NULL DEFAULT 'namespace_events',
2820
+ api_name text,
2821
+ private_api_name text,
2822
+ membership_type int DEFAULT NULL,
2823
+ entity_table_id uuid NULL,
2824
+ policies jsonb NULL,
2825
+ provisions jsonb NULL,
2826
+ CONSTRAINT namespace_module_db_fkey
2827
+ FOREIGN KEY(database_id)
2828
+ REFERENCES metaschema_public.database (id)
2829
+ ON DELETE CASCADE,
2830
+ CONSTRAINT namespace_module_schema_fkey
2831
+ FOREIGN KEY(schema_id)
2832
+ REFERENCES metaschema_public.schema (id)
2833
+ ON DELETE CASCADE,
2834
+ CONSTRAINT namespace_module_private_schema_fkey
2835
+ FOREIGN KEY(private_schema_id)
2836
+ REFERENCES metaschema_public.schema (id)
2837
+ ON DELETE CASCADE,
2838
+ CONSTRAINT namespace_module_namespaces_table_fkey
2839
+ FOREIGN KEY(namespaces_table_id)
2840
+ REFERENCES metaschema_public.table (id)
2841
+ ON DELETE CASCADE,
2842
+ CONSTRAINT namespace_module_events_table_fkey
2843
+ FOREIGN KEY(namespace_events_table_id)
2844
+ REFERENCES metaschema_public.table (id)
2845
+ ON DELETE CASCADE,
2846
+ CONSTRAINT namespace_module_entity_table_fkey
2847
+ FOREIGN KEY(entity_table_id)
2848
+ REFERENCES metaschema_public.table (id)
2849
+ ON DELETE CASCADE
2850
+ );
2851
+
2852
+ CREATE INDEX namespace_module_database_id_idx ON metaschema_modules_public.namespace_module (database_id);
2853
+
2854
+ CREATE UNIQUE INDEX namespace_module_unique_scope ON metaschema_modules_public.namespace_module (database_id, (COALESCE(membership_type, -1)));
2855
+
2856
+ CREATE TABLE metaschema_modules_public.function_module (
2857
+ id uuid PRIMARY KEY DEFAULT uuidv7(),
2858
+ database_id uuid NOT NULL,
2859
+ schema_id uuid NOT NULL DEFAULT uuid_nil(),
2860
+ private_schema_id uuid NOT NULL DEFAULT uuid_nil(),
2861
+ public_schema_name text,
2862
+ private_schema_name text,
2863
+ definitions_table_id uuid NOT NULL DEFAULT uuid_nil(),
2864
+ invocations_table_id uuid NOT NULL DEFAULT uuid_nil(),
2865
+ execution_logs_table_id uuid NOT NULL DEFAULT uuid_nil(),
2866
+ definitions_table_name text NOT NULL DEFAULT 'function_definitions',
2867
+ invocations_table_name text NOT NULL DEFAULT 'function_invocations',
2868
+ execution_logs_table_name text NOT NULL DEFAULT 'function_execution_logs',
2869
+ api_name text,
2870
+ private_api_name text,
2871
+ membership_type int DEFAULT NULL,
2872
+ entity_table_id uuid NULL,
2873
+ policies jsonb NULL,
2874
+ provisions jsonb NULL,
2875
+ CONSTRAINT function_module_db_fkey
2876
+ FOREIGN KEY(database_id)
2877
+ REFERENCES metaschema_public.database (id)
2878
+ ON DELETE CASCADE,
2879
+ CONSTRAINT function_module_schema_fkey
2880
+ FOREIGN KEY(schema_id)
2881
+ REFERENCES metaschema_public.schema (id)
2882
+ ON DELETE CASCADE,
2883
+ CONSTRAINT function_module_private_schema_fkey
2884
+ FOREIGN KEY(private_schema_id)
2885
+ REFERENCES metaschema_public.schema (id)
2886
+ ON DELETE CASCADE,
2887
+ CONSTRAINT function_module_definitions_table_fkey
2888
+ FOREIGN KEY(definitions_table_id)
2889
+ REFERENCES metaschema_public.table (id)
2890
+ ON DELETE CASCADE,
2891
+ CONSTRAINT function_module_invocations_table_fkey
2892
+ FOREIGN KEY(invocations_table_id)
2893
+ REFERENCES metaschema_public.table (id)
2894
+ ON DELETE CASCADE,
2895
+ CONSTRAINT function_module_execution_logs_table_fkey
2896
+ FOREIGN KEY(execution_logs_table_id)
2897
+ REFERENCES metaschema_public.table (id)
2898
+ ON DELETE CASCADE,
2899
+ CONSTRAINT function_module_entity_table_fkey
2900
+ FOREIGN KEY(entity_table_id)
2901
+ REFERENCES metaschema_public.table (id)
2902
+ ON DELETE CASCADE
2903
+ );
2904
+
2905
+ CREATE INDEX function_module_database_id_idx ON metaschema_modules_public.function_module (database_id);
2906
+
2907
+ CREATE UNIQUE INDEX function_module_unique_scope ON metaschema_modules_public.function_module (database_id, (COALESCE(membership_type, -1)));
@@ -0,0 +1,7 @@
1
+ -- Verify schemas/metaschema_modules_public/tables/agent_module/table on pg
2
+
3
+ BEGIN;
4
+
5
+ SELECT verify_table ('metaschema_modules_public.agent_module');
6
+
7
+ ROLLBACK;
@@ -15,6 +15,8 @@ SELECT
15
15
  ledger_table_name,
16
16
  balances_table_id,
17
17
  balances_table_name,
18
+ meter_sources_table_id,
19
+ meter_sources_table_name,
18
20
  record_usage_function,
19
21
  prefix
20
22
  FROM metaschema_modules_public.billing_module