@pgpm/metaschema-modules 0.26.2 → 0.26.5

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 (55) hide show
  1. package/Makefile +1 -1
  2. package/deploy/schemas/metaschema_modules_public/tables/agent_module/table.sql +35 -24
  3. package/deploy/schemas/metaschema_modules_public/tables/billing_module/table.sql +13 -0
  4. package/deploy/schemas/metaschema_modules_public/tables/billing_provider_module/table.sql +4 -0
  5. package/deploy/schemas/metaschema_modules_public/tables/compute_log_module/table.sql +7 -2
  6. package/deploy/schemas/metaschema_modules_public/tables/config_secrets_module/table.sql +82 -0
  7. package/deploy/schemas/metaschema_modules_public/tables/config_secrets_org_module/table.sql +4 -0
  8. package/deploy/schemas/metaschema_modules_public/tables/config_secrets_user_module/table.sql +4 -0
  9. package/deploy/schemas/metaschema_modules_public/tables/connected_accounts_module/table.sql +4 -0
  10. package/deploy/schemas/metaschema_modules_public/tables/crypto_addresses_module/table.sql +4 -0
  11. package/deploy/schemas/metaschema_modules_public/tables/db_usage_module/table.sql +11 -2
  12. package/deploy/schemas/metaschema_modules_public/tables/emails_module/table.sql +4 -0
  13. package/deploy/schemas/metaschema_modules_public/tables/entity_type_provision/table.sql +0 -4
  14. package/deploy/schemas/metaschema_modules_public/tables/events_module/table.sql +14 -4
  15. package/deploy/schemas/metaschema_modules_public/tables/function_module/table.sql +14 -27
  16. package/deploy/schemas/metaschema_modules_public/tables/graph_module/table.sql +10 -8
  17. package/deploy/schemas/metaschema_modules_public/tables/hierarchy_module/table.sql +10 -3
  18. package/deploy/schemas/metaschema_modules_public/tables/i18n_module/table.sql +31 -0
  19. package/deploy/schemas/metaschema_modules_public/tables/identity_providers_module/table.sql +35 -3
  20. package/deploy/schemas/metaschema_modules_public/tables/inference_log_module/table.sql +7 -2
  21. package/deploy/schemas/metaschema_modules_public/tables/invites_module/table.sql +12 -10
  22. package/deploy/schemas/metaschema_modules_public/tables/limits_module/table.sql +10 -4
  23. package/deploy/schemas/metaschema_modules_public/tables/memberships_module/table.sql +13 -6
  24. package/deploy/schemas/metaschema_modules_public/tables/merkle_store_module/table.sql +3 -2
  25. package/deploy/schemas/metaschema_modules_public/tables/namespace_module/table.sql +13 -12
  26. package/deploy/schemas/metaschema_modules_public/tables/notifications_module/table.sql +8 -0
  27. package/deploy/schemas/metaschema_modules_public/tables/permissions_module/table.sql +12 -5
  28. package/deploy/schemas/metaschema_modules_public/tables/phone_numbers_module/table.sql +4 -0
  29. package/deploy/schemas/metaschema_modules_public/tables/plans_module/table.sql +16 -0
  30. package/deploy/schemas/metaschema_modules_public/tables/profiles_module/table.sql +10 -4
  31. package/deploy/schemas/metaschema_modules_public/tables/rate_limit_meters_module/table.sql +8 -0
  32. package/deploy/schemas/metaschema_modules_public/tables/realtime_module/table.sql +4 -0
  33. package/deploy/schemas/metaschema_modules_public/tables/rls_module/table.sql +4 -0
  34. package/deploy/schemas/metaschema_modules_public/tables/storage_log_module/table.sql +7 -2
  35. package/deploy/schemas/metaschema_modules_public/tables/storage_module/table.sql +19 -14
  36. package/deploy/schemas/metaschema_modules_public/tables/transfer_log_module/table.sql +7 -2
  37. package/deploy/schemas/metaschema_modules_public/tables/user_auth_module/table.sql +4 -0
  38. package/deploy/schemas/metaschema_modules_public/tables/user_credentials_module/table.sql +42 -0
  39. package/deploy/schemas/metaschema_modules_public/tables/user_settings_module/table.sql +34 -0
  40. package/deploy/schemas/metaschema_modules_public/tables/users_module/table.sql +4 -0
  41. package/deploy/schemas/metaschema_modules_public/tables/webauthn_credentials_module/table.sql +4 -0
  42. package/metaschema-modules.control +1 -1
  43. package/package.json +3 -3
  44. package/pgpm.plan +4 -0
  45. package/revert/schemas/metaschema_modules_public/tables/agent_chat_module/table.sql +3 -0
  46. package/revert/schemas/metaschema_modules_public/tables/config_secrets_module/table.sql +7 -0
  47. package/revert/schemas/metaschema_modules_public/tables/i18n_module/table.sql +7 -0
  48. package/revert/schemas/metaschema_modules_public/tables/user_credentials_module/table.sql +7 -0
  49. package/revert/schemas/metaschema_modules_public/tables/user_settings_module/table.sql +7 -0
  50. package/sql/{metaschema-modules--0.26.1.sql → metaschema-modules--0.26.3.sql} +318 -62
  51. package/verify/schemas/metaschema_modules_public/tables/config_secrets_module/table.sql +7 -0
  52. package/verify/schemas/metaschema_modules_public/tables/i18n_module/table.sql +9 -0
  53. package/verify/schemas/metaschema_modules_public/tables/namespace_module/table.sql +3 -1
  54. package/verify/schemas/metaschema_modules_public/tables/user_credentials_module/table.sql +7 -0
  55. package/verify/schemas/metaschema_modules_public/tables/user_settings_module/table.sql +7 -0
@@ -31,6 +31,8 @@ CREATE TABLE metaschema_modules_public.connected_accounts_module (
31
31
  table_id uuid NOT NULL DEFAULT uuid_nil(),
32
32
  owner_table_id uuid NOT NULL DEFAULT uuid_nil(),
33
33
  table_name text NOT NULL,
34
+ api_name text DEFAULT 'auth',
35
+ private_api_name text DEFAULT NULL,
34
36
  CONSTRAINT db_fkey
35
37
  FOREIGN KEY(database_id)
36
38
  REFERENCES metaschema_public.database (id)
@@ -64,6 +66,8 @@ CREATE TABLE metaschema_modules_public.crypto_addresses_module (
64
66
  owner_table_id uuid NOT NULL DEFAULT uuid_nil(),
65
67
  table_name text NOT NULL,
66
68
  crypto_network text NOT NULL DEFAULT 'BTC',
69
+ api_name text DEFAULT 'auth',
70
+ private_api_name text DEFAULT NULL,
67
71
  CONSTRAINT db_fkey
68
72
  FOREIGN KEY(database_id)
69
73
  REFERENCES metaschema_public.database (id)
@@ -187,6 +191,8 @@ CREATE TABLE metaschema_modules_public.emails_module (
187
191
  table_id uuid NOT NULL DEFAULT uuid_nil(),
188
192
  owner_table_id uuid NOT NULL DEFAULT uuid_nil(),
189
193
  table_name text NOT NULL,
194
+ api_name text DEFAULT 'auth',
195
+ private_api_name text DEFAULT NULL,
190
196
  CONSTRAINT db_fkey
191
197
  FOREIGN KEY(database_id)
192
198
  REFERENCES metaschema_public.database (id)
@@ -218,6 +224,8 @@ CREATE TABLE metaschema_modules_public.config_secrets_user_module (
218
224
  table_id uuid NOT NULL DEFAULT uuid_nil(),
219
225
  table_name text NOT NULL DEFAULT 'user_secrets',
220
226
  config_definitions_table_id uuid NOT NULL DEFAULT uuid_nil(),
227
+ api_name text DEFAULT 'config',
228
+ private_api_name text DEFAULT NULL,
221
229
  CONSTRAINT db_fkey
222
230
  FOREIGN KEY(database_id)
223
231
  REFERENCES metaschema_public.database (id)
@@ -250,9 +258,11 @@ CREATE TABLE metaschema_modules_public.invites_module (
250
258
  invites_table_name text NOT NULL DEFAULT '',
251
259
  claimed_invites_table_name text NOT NULL DEFAULT '',
252
260
  submit_invite_code_function text NOT NULL DEFAULT '',
253
- prefix text NULL,
254
- membership_type int NOT NULL,
261
+ scope text NOT NULL DEFAULT 'app',
262
+ prefix text NOT NULL DEFAULT '',
255
263
  entity_table_id uuid NULL,
264
+ api_name text DEFAULT 'admin',
265
+ private_api_name text DEFAULT NULL,
256
266
  CONSTRAINT db_fkey
257
267
  FOREIGN KEY(database_id)
258
268
  REFERENCES metaschema_public.database (id)
@@ -289,7 +299,7 @@ CREATE TABLE metaschema_modules_public.invites_module (
289
299
 
290
300
  CREATE INDEX invites_module_database_id_idx ON metaschema_modules_public.invites_module (database_id);
291
301
 
292
- CREATE UNIQUE INDEX invites_module_unique_scope ON metaschema_modules_public.invites_module (database_id, membership_type);
302
+ CREATE UNIQUE INDEX invites_module_unique_scope ON metaschema_modules_public.invites_module (database_id, scope, prefix);
293
303
 
294
304
  CREATE TABLE metaschema_modules_public.events_module (
295
305
  id uuid PRIMARY KEY DEFAULT uuidv7(),
@@ -327,10 +337,13 @@ CREATE TABLE metaschema_modules_public.events_module (
327
337
  interval text NOT NULL DEFAULT '1 month',
328
338
  retention text DEFAULT '12 months',
329
339
  premake int NOT NULL DEFAULT 2,
330
- prefix text NULL,
331
- membership_type int NOT NULL,
340
+ scope text NOT NULL DEFAULT 'app',
341
+ prefix text NOT NULL DEFAULT '',
332
342
  entity_table_id uuid NULL,
333
343
  actor_table_id uuid NOT NULL DEFAULT uuid_nil(),
344
+ default_permissions text[] DEFAULT NULL,
345
+ api_name text DEFAULT 'usage',
346
+ private_api_name text DEFAULT NULL,
334
347
  CONSTRAINT db_fkey
335
348
  FOREIGN KEY(database_id)
336
349
  REFERENCES metaschema_public.database (id)
@@ -412,10 +425,12 @@ CREATE TABLE metaschema_modules_public.limits_module (
412
425
  limit_warning_state_table_id uuid NULL,
413
426
  limit_check_soft_function text NOT NULL DEFAULT '',
414
427
  limit_aggregate_check_soft_function text NOT NULL DEFAULT '',
415
- prefix text NULL,
416
- membership_type int NOT NULL,
428
+ scope text NOT NULL DEFAULT 'app',
429
+ prefix text NOT NULL DEFAULT '',
417
430
  entity_table_id uuid NULL,
418
431
  actor_table_id uuid NOT NULL DEFAULT uuid_nil(),
432
+ api_name text DEFAULT 'usage',
433
+ private_api_name text DEFAULT NULL,
419
434
  CONSTRAINT db_fkey
420
435
  FOREIGN KEY(database_id)
421
436
  REFERENCES metaschema_public.database (id)
@@ -535,10 +550,10 @@ CREATE TABLE metaschema_modules_public.memberships_module (
535
550
  admin_grants_table_name text NOT NULL DEFAULT '',
536
551
  owner_grants_table_id uuid NOT NULL DEFAULT uuid_nil(),
537
552
  owner_grants_table_name text NOT NULL DEFAULT '',
538
- membership_type int NOT NULL,
553
+ scope text NOT NULL DEFAULT 'app',
554
+ prefix text NOT NULL DEFAULT '',
539
555
  entity_table_id uuid NULL,
540
556
  entity_table_owner_id uuid NULL,
541
- prefix text NULL,
542
557
  get_org_fn text NULL,
543
558
  actor_mask_check text NOT NULL DEFAULT '',
544
559
  actor_perm_check text NOT NULL DEFAULT '',
@@ -546,6 +561,8 @@ CREATE TABLE metaschema_modules_public.memberships_module (
546
561
  entity_ids_by_perm text NULL,
547
562
  entity_ids_function text NULL,
548
563
  member_profiles_table_id uuid NULL,
564
+ api_name text DEFAULT 'admin',
565
+ private_api_name text DEFAULT NULL,
549
566
  CONSTRAINT db_fkey
550
567
  FOREIGN KEY(database_id)
551
568
  REFERENCES metaschema_public.database (id)
@@ -609,7 +626,9 @@ CREATE TABLE metaschema_modules_public.memberships_module (
609
626
  CONSTRAINT default_permissions_table_fkey
610
627
  FOREIGN KEY(default_permissions_table_id)
611
628
  REFERENCES metaschema_public."table" (id)
612
- ON DELETE CASCADE
629
+ ON DELETE CASCADE,
630
+ CONSTRAINT memberships_module_unique
631
+ UNIQUE (database_id, scope, prefix)
613
632
  );
614
633
 
615
634
  CREATE INDEX memberships_module_database_id_idx ON metaschema_modules_public.memberships_module (database_id);
@@ -624,14 +643,16 @@ CREATE TABLE metaschema_modules_public.permissions_module (
624
643
  default_table_id uuid NOT NULL DEFAULT uuid_nil(),
625
644
  default_table_name text NOT NULL DEFAULT '',
626
645
  bitlen int NOT NULL DEFAULT 64,
627
- membership_type int NOT NULL,
646
+ scope text NOT NULL DEFAULT 'app',
647
+ prefix text NOT NULL DEFAULT '',
628
648
  entity_table_id uuid NULL,
629
649
  actor_table_id uuid NOT NULL DEFAULT uuid_nil(),
630
- prefix text NULL,
631
650
  get_padded_mask text NOT NULL DEFAULT '',
632
651
  get_mask text NOT NULL DEFAULT '',
633
652
  get_by_mask text NOT NULL DEFAULT '',
634
653
  get_mask_by_name text NOT NULL DEFAULT '',
654
+ api_name text DEFAULT 'admin',
655
+ private_api_name text DEFAULT NULL,
635
656
  CONSTRAINT db_fkey
636
657
  FOREIGN KEY(database_id)
637
658
  REFERENCES metaschema_public.database (id)
@@ -672,6 +693,8 @@ CREATE TABLE metaschema_modules_public.phone_numbers_module (
672
693
  table_id uuid NOT NULL DEFAULT uuid_nil(),
673
694
  owner_table_id uuid NOT NULL DEFAULT uuid_nil(),
674
695
  table_name text NOT NULL,
696
+ api_name text DEFAULT 'auth',
697
+ private_api_name text DEFAULT NULL,
675
698
  CONSTRAINT db_fkey
676
699
  FOREIGN KEY(database_id)
677
700
  REFERENCES metaschema_public.database (id)
@@ -711,12 +734,14 @@ CREATE TABLE metaschema_modules_public.profiles_module (
711
734
  profile_definition_grants_table_name text NOT NULL DEFAULT '',
712
735
  profile_templates_table_id uuid NOT NULL DEFAULT uuid_nil(),
713
736
  profile_templates_table_name text NOT NULL DEFAULT '',
714
- membership_type int NOT NULL,
737
+ scope text NOT NULL DEFAULT 'app',
738
+ prefix text NOT NULL DEFAULT '',
715
739
  entity_table_id uuid NULL,
716
740
  actor_table_id uuid NOT NULL DEFAULT uuid_nil(),
717
741
  permissions_table_id uuid NOT NULL DEFAULT uuid_nil(),
718
742
  memberships_table_id uuid NOT NULL DEFAULT uuid_nil(),
719
- prefix text NULL,
743
+ api_name text DEFAULT 'admin',
744
+ private_api_name text DEFAULT NULL,
720
745
  CONSTRAINT db_fkey
721
746
  FOREIGN KEY(database_id)
722
747
  REFERENCES metaschema_public.database (id)
@@ -766,7 +791,7 @@ CREATE TABLE metaschema_modules_public.profiles_module (
766
791
  REFERENCES metaschema_public."table" (id)
767
792
  ON DELETE CASCADE,
768
793
  CONSTRAINT profiles_module_unique
769
- UNIQUE (database_id, membership_type)
794
+ UNIQUE (database_id, scope, prefix)
770
795
  );
771
796
 
772
797
  CREATE INDEX profiles_module_database_id_idx ON metaschema_modules_public.profiles_module (database_id);
@@ -783,6 +808,8 @@ CREATE TABLE metaschema_modules_public.rls_module (
783
808
  authenticate_strict text NOT NULL DEFAULT 'authenticate_strict',
784
809
  "current_role" text NOT NULL DEFAULT 'current_user',
785
810
  current_role_id text NOT NULL DEFAULT 'current_user_id',
811
+ api_name text DEFAULT 'auth',
812
+ private_api_name text DEFAULT NULL,
786
813
  CONSTRAINT db_fkey
787
814
  FOREIGN KEY(database_id)
788
815
  REFERENCES metaschema_public.database (id)
@@ -916,6 +943,8 @@ CREATE TABLE metaschema_modules_public.user_auth_module (
916
943
  sign_in_cross_origin_function text NOT NULL DEFAULT 'sign_in_cross_origin',
917
944
  request_cross_origin_token_function text NOT NULL DEFAULT 'request_cross_origin_token',
918
945
  extend_token_expires text NOT NULL DEFAULT 'extend_token_expires',
946
+ api_name text DEFAULT 'auth',
947
+ private_api_name text DEFAULT NULL,
919
948
  CONSTRAINT db_fkey
920
949
  FOREIGN KEY(database_id)
921
950
  REFERENCES metaschema_public.database (id)
@@ -972,6 +1001,8 @@ CREATE TABLE metaschema_modules_public.users_module (
972
1001
  table_name text NOT NULL DEFAULT 'users',
973
1002
  type_table_id uuid NOT NULL DEFAULT uuid_nil(),
974
1003
  type_table_name text NOT NULL DEFAULT 'role_types',
1004
+ api_name text DEFAULT 'auth',
1005
+ private_api_name text DEFAULT NULL,
975
1006
  CONSTRAINT db_fkey
976
1007
  FOREIGN KEY(database_id)
977
1008
  REFERENCES metaschema_public.database (id)
@@ -1005,13 +1036,15 @@ CREATE TABLE metaschema_modules_public.hierarchy_module (
1005
1036
  chart_edge_grants_table_name text NOT NULL DEFAULT '',
1006
1037
  entity_table_id uuid NOT NULL,
1007
1038
  users_table_id uuid NOT NULL,
1008
- prefix text NOT NULL DEFAULT 'org',
1039
+ scope text NOT NULL DEFAULT 'org',
1040
+ prefix text NOT NULL DEFAULT '',
1009
1041
  private_schema_name text NOT NULL DEFAULT '',
1010
1042
  sprt_table_name text NOT NULL DEFAULT '',
1011
1043
  rebuild_hierarchy_function text NOT NULL DEFAULT '',
1012
1044
  get_subordinates_function text NOT NULL DEFAULT '',
1013
1045
  get_managers_function text NOT NULL DEFAULT '',
1014
1046
  is_manager_of_function text NOT NULL DEFAULT '',
1047
+ default_permissions text[] DEFAULT NULL,
1015
1048
  created_at timestamptz NOT NULL DEFAULT now(),
1016
1049
  CONSTRAINT db_fkey
1017
1050
  FOREIGN KEY(database_id)
@@ -1460,10 +1493,10 @@ CREATE TABLE metaschema_modules_public.storage_module (
1460
1493
  private_schema_id uuid NOT NULL DEFAULT uuid_nil(),
1461
1494
  buckets_table_id uuid NOT NULL DEFAULT uuid_nil(),
1462
1495
  files_table_id uuid NOT NULL DEFAULT uuid_nil(),
1463
- buckets_table_name text NOT NULL DEFAULT 'app_buckets',
1464
- files_table_name text NOT NULL DEFAULT 'app_files',
1465
- membership_type int DEFAULT NULL,
1466
- key text NOT NULL DEFAULT 'default',
1496
+ buckets_table_name text NOT NULL DEFAULT 'buckets',
1497
+ files_table_name text NOT NULL DEFAULT 'files',
1498
+ scope text NOT NULL DEFAULT 'app',
1499
+ prefix text NOT NULL DEFAULT '',
1467
1500
  policies jsonb NULL,
1468
1501
  provisions jsonb NULL,
1469
1502
  entity_table_id uuid NULL,
@@ -1488,6 +1521,9 @@ CREATE TABLE metaschema_modules_public.storage_module (
1488
1521
  has_confirm_upload boolean NOT NULL DEFAULT false,
1489
1522
  confirm_upload_delay interval NOT NULL DEFAULT '30 seconds',
1490
1523
  file_events_table_id uuid NULL DEFAULT NULL,
1524
+ default_permissions text[] DEFAULT NULL,
1525
+ api_name text DEFAULT 'admin',
1526
+ private_api_name text DEFAULT NULL,
1491
1527
  CONSTRAINT db_fkey
1492
1528
  FOREIGN KEY(database_id)
1493
1529
  REFERENCES metaschema_public.database (id)
@@ -1524,7 +1560,7 @@ CREATE TABLE metaschema_modules_public.storage_module (
1524
1560
 
1525
1561
  CREATE INDEX storage_module_database_id_idx ON metaschema_modules_public.storage_module (database_id);
1526
1562
 
1527
- CREATE UNIQUE INDEX storage_module_unique_scope ON metaschema_modules_public.storage_module (database_id, (COALESCE(membership_type, -1)), key);
1563
+ CREATE UNIQUE INDEX storage_module_unique_scope ON metaschema_modules_public.storage_module (database_id, scope, prefix);
1528
1564
 
1529
1565
  CREATE TABLE metaschema_modules_public.entity_type_provision (
1530
1566
  id uuid PRIMARY KEY DEFAULT uuidv7(),
@@ -1564,8 +1600,6 @@ CREATE TABLE metaschema_modules_public.entity_type_provision (
1564
1600
  out_invocations_table_id uuid DEFAULT NULL,
1565
1601
  out_execution_logs_table_id uuid DEFAULT NULL,
1566
1602
  out_secret_definitions_table_id uuid DEFAULT NULL,
1567
- out_requirements_table_id uuid DEFAULT NULL,
1568
- out_config_requirements_table_id uuid DEFAULT NULL,
1569
1603
  out_graph_module_id uuid DEFAULT NULL,
1570
1604
  out_graphs_table_id uuid DEFAULT NULL,
1571
1605
  out_agent_module_id uuid DEFAULT NULL,
@@ -1901,6 +1935,8 @@ CREATE TABLE metaschema_modules_public.webauthn_credentials_module (
1901
1935
  table_id uuid NOT NULL DEFAULT uuid_nil(),
1902
1936
  owner_table_id uuid NOT NULL DEFAULT uuid_nil(),
1903
1937
  table_name text NOT NULL DEFAULT 'webauthn_credentials',
1938
+ api_name text DEFAULT 'auth',
1939
+ private_api_name text DEFAULT NULL,
1904
1940
  CONSTRAINT db_fkey
1905
1941
  FOREIGN KEY(database_id)
1906
1942
  REFERENCES metaschema_public.database (id)
@@ -1989,6 +2025,11 @@ CREATE TABLE metaschema_modules_public.identity_providers_module (
1989
2025
  private_schema_id uuid NOT NULL DEFAULT uuid_nil(),
1990
2026
  table_id uuid NOT NULL DEFAULT uuid_nil(),
1991
2027
  table_name text NOT NULL DEFAULT 'identity_providers',
2028
+ api_name text DEFAULT 'auth',
2029
+ private_api_name text DEFAULT NULL,
2030
+ scope text NOT NULL DEFAULT 'app',
2031
+ prefix text NOT NULL DEFAULT '',
2032
+ entity_table_id uuid NULL,
1992
2033
  CONSTRAINT db_fkey
1993
2034
  FOREIGN KEY(database_id)
1994
2035
  REFERENCES metaschema_public.database (id)
@@ -2004,6 +2045,10 @@ CREATE TABLE metaschema_modules_public.identity_providers_module (
2004
2045
  CONSTRAINT private_schema_fkey
2005
2046
  FOREIGN KEY(private_schema_id)
2006
2047
  REFERENCES metaschema_public.schema (id)
2048
+ ON DELETE CASCADE,
2049
+ CONSTRAINT entity_table_fkey
2050
+ FOREIGN KEY(entity_table_id)
2051
+ REFERENCES metaschema_public."table" (id)
2007
2052
  ON DELETE CASCADE
2008
2053
  );
2009
2054
 
@@ -2015,7 +2060,18 @@ CREATE INDEX identity_providers_module_private_schema_id_idx ON metaschema_modul
2015
2060
 
2016
2061
  CREATE INDEX identity_providers_module_table_id_idx ON metaschema_modules_public.identity_providers_module (table_id);
2017
2062
 
2018
- COMMENT ON TABLE metaschema_modules_public.identity_providers_module IS 'Config row for the identity_providers_module, which provisions a per-database identity_providers config table holding OAuth2 / OIDC (and future SAML) provider definitions: protocol kind, endpoint URLs, encrypted client secret, scopes, audience validation, PKCE, and email-handling flags. Built-in providers (google, github, apple, ...) are seeded as is_built_in=true rows; custom providers use slugs of the form custom:<slug>.';
2063
+ CREATE UNIQUE INDEX identity_providers_module_unique_scope ON metaschema_modules_public.identity_providers_module (database_id, scope);
2064
+
2065
+ COMMENT ON TABLE metaschema_modules_public.identity_providers_module IS 'Entity-aware config row for the identity_providers_module, which provisions a per-database
2066
+ identity_providers table holding OAuth2 / OIDC (and future SAML) provider definitions.
2067
+ The scope column determines which config_secrets_module table the rotate proc targets
2068
+ (app_secrets for app scope, org_secrets for org scope). When scope = platform,
2069
+ the secrets table gets a database_id column and platform-level RLS via
2070
+ AuthzRelatedEntityMembership through database.owner_id.
2071
+ Scoping matrix:
2072
+ scope=app → per-database flat, in-app admin manages
2073
+ scope=platform → per-database, platform admin manages (generate:constructive)
2074
+ scope=org → per-org tenant, org admin manages';
2019
2075
 
2020
2076
  COMMENT ON COLUMN metaschema_modules_public.identity_providers_module.private_schema_id IS 'Private schema that hosts SECURITY DEFINER admin helpers which write to identity_providers (create / update / enable / disable / rotate-secret / delete) and the per-app quota check.';
2021
2077
 
@@ -2037,6 +2093,9 @@ CREATE TABLE metaschema_modules_public.notifications_module (
2037
2093
  has_settings_extension boolean NOT NULL DEFAULT false,
2038
2094
  has_digest_metadata boolean NOT NULL DEFAULT false,
2039
2095
  has_subscriptions boolean NOT NULL DEFAULT false,
2096
+ default_permissions text[] DEFAULT NULL,
2097
+ api_name text DEFAULT 'notifications',
2098
+ private_api_name text DEFAULT NULL,
2040
2099
  CONSTRAINT db_fkey
2041
2100
  FOREIGN KEY(database_id)
2042
2101
  REFERENCES metaschema_public.database (id)
@@ -2125,9 +2184,15 @@ CREATE TABLE metaschema_modules_public.plans_module (
2125
2184
  plan_limits_table_name text NOT NULL DEFAULT '',
2126
2185
  plan_pricing_table_id uuid NULL,
2127
2186
  plan_overrides_table_id uuid NULL,
2187
+ plan_meter_limits_table_id uuid NULL,
2188
+ plan_caps_table_id uuid NULL,
2128
2189
  apply_plan_function text NOT NULL DEFAULT '',
2129
2190
  apply_plan_aggregate_function text NOT NULL DEFAULT '',
2191
+ apply_billing_plan_function text NULL,
2192
+ apply_plan_caps_function text NULL,
2130
2193
  prefix text NULL,
2194
+ api_name text DEFAULT 'usage',
2195
+ private_api_name text DEFAULT NULL,
2131
2196
  CONSTRAINT db_fkey
2132
2197
  FOREIGN KEY(database_id)
2133
2198
  REFERENCES metaschema_public.database (id)
@@ -2156,6 +2221,14 @@ CREATE TABLE metaschema_modules_public.plans_module (
2156
2221
  FOREIGN KEY(plan_overrides_table_id)
2157
2222
  REFERENCES metaschema_public."table" (id)
2158
2223
  ON DELETE CASCADE,
2224
+ CONSTRAINT plan_meter_limits_table_fkey
2225
+ FOREIGN KEY(plan_meter_limits_table_id)
2226
+ REFERENCES metaschema_public."table" (id)
2227
+ ON DELETE CASCADE,
2228
+ CONSTRAINT plan_caps_table_fkey
2229
+ FOREIGN KEY(plan_caps_table_id)
2230
+ REFERENCES metaschema_public."table" (id)
2231
+ ON DELETE CASCADE,
2159
2232
  CONSTRAINT plans_module_database_id_unique
2160
2233
  UNIQUE (database_id)
2161
2234
  );
@@ -2179,8 +2252,13 @@ CREATE TABLE metaschema_modules_public.billing_module (
2179
2252
  meter_credits_table_name text NOT NULL DEFAULT '',
2180
2253
  meter_sources_table_id uuid NOT NULL DEFAULT uuid_nil(),
2181
2254
  meter_sources_table_name text NOT NULL DEFAULT '',
2255
+ meter_defaults_table_id uuid NOT NULL DEFAULT uuid_nil(),
2256
+ meter_defaults_table_name text NOT NULL DEFAULT '',
2182
2257
  record_usage_function text NOT NULL DEFAULT '',
2183
2258
  prefix text NULL,
2259
+ default_permissions text[] DEFAULT NULL,
2260
+ api_name text DEFAULT 'usage',
2261
+ private_api_name text DEFAULT NULL,
2184
2262
  CONSTRAINT db_fkey
2185
2263
  FOREIGN KEY(database_id)
2186
2264
  REFERENCES metaschema_public.database (id)
@@ -2217,6 +2295,10 @@ CREATE TABLE metaschema_modules_public.billing_module (
2217
2295
  FOREIGN KEY(meter_sources_table_id)
2218
2296
  REFERENCES metaschema_public."table" (id)
2219
2297
  ON DELETE CASCADE,
2298
+ CONSTRAINT meter_defaults_table_fkey
2299
+ FOREIGN KEY(meter_defaults_table_id)
2300
+ REFERENCES metaschema_public."table" (id)
2301
+ ON DELETE CASCADE,
2220
2302
  CONSTRAINT billing_module_database_id_unique
2221
2303
  UNIQUE (database_id)
2222
2304
  );
@@ -2244,6 +2326,8 @@ CREATE TABLE metaschema_modules_public.billing_provider_module (
2244
2326
  billing_webhook_events_table_name text NOT NULL DEFAULT '',
2245
2327
  process_billing_event_function text NOT NULL DEFAULT '',
2246
2328
  prefix text NULL,
2329
+ api_name text DEFAULT NULL,
2330
+ private_api_name text DEFAULT NULL,
2247
2331
  CONSTRAINT db_fkey
2248
2332
  FOREIGN KEY(database_id)
2249
2333
  REFERENCES metaschema_public.database (id)
@@ -2307,6 +2391,8 @@ CREATE TABLE metaschema_modules_public.realtime_module (
2307
2391
  premake int NOT NULL DEFAULT 7,
2308
2392
  interval text NOT NULL DEFAULT '1 day',
2309
2393
  notify_channel text NULL,
2394
+ api_name text DEFAULT 'realtime',
2395
+ private_api_name text DEFAULT NULL,
2310
2396
  CONSTRAINT db_fkey
2311
2397
  FOREIGN KEY(database_id)
2312
2398
  REFERENCES metaschema_public.database (id)
@@ -2366,6 +2452,9 @@ CREATE TABLE metaschema_modules_public.rate_limit_meters_module (
2366
2452
  rate_window_limits_table_name text NOT NULL DEFAULT '',
2367
2453
  check_rate_limit_function text NOT NULL DEFAULT '',
2368
2454
  prefix text NULL,
2455
+ default_permissions text[] DEFAULT NULL,
2456
+ api_name text DEFAULT 'usage',
2457
+ private_api_name text DEFAULT NULL,
2369
2458
  CONSTRAINT db_fkey
2370
2459
  FOREIGN KEY(database_id)
2371
2460
  REFERENCES metaschema_public.database (id)
@@ -2408,6 +2497,8 @@ CREATE TABLE metaschema_modules_public.config_secrets_org_module (
2408
2497
  schema_id uuid NOT NULL DEFAULT uuid_nil(),
2409
2498
  table_id uuid NOT NULL DEFAULT uuid_nil(),
2410
2499
  table_name text NOT NULL DEFAULT 'org_secrets',
2500
+ api_name text DEFAULT 'config',
2501
+ private_api_name text DEFAULT NULL,
2411
2502
  CONSTRAINT db_fkey
2412
2503
  FOREIGN KEY(database_id)
2413
2504
  REFERENCES metaschema_public.database (id)
@@ -2445,7 +2536,9 @@ CREATE TABLE metaschema_modules_public.inference_log_module (
2445
2536
  scope text NOT NULL DEFAULT 'app',
2446
2537
  actor_fk_table_id uuid NULL,
2447
2538
  entity_fk_table_id uuid NULL,
2448
- prefix text NULL,
2539
+ prefix text NOT NULL DEFAULT '',
2540
+ api_name text DEFAULT 'usage',
2541
+ private_api_name text DEFAULT NULL,
2449
2542
  CONSTRAINT db_fkey
2450
2543
  FOREIGN KEY(database_id)
2451
2544
  REFERENCES metaschema_public.database (id)
@@ -2487,7 +2580,9 @@ CREATE TABLE metaschema_modules_public.compute_log_module (
2487
2580
  scope text NOT NULL DEFAULT 'app',
2488
2581
  actor_fk_table_id uuid NULL,
2489
2582
  entity_fk_table_id uuid NULL,
2490
- prefix text NULL,
2583
+ prefix text NOT NULL DEFAULT '',
2584
+ api_name text DEFAULT 'usage',
2585
+ private_api_name text DEFAULT NULL,
2491
2586
  CONSTRAINT db_fkey
2492
2587
  FOREIGN KEY(database_id)
2493
2588
  REFERENCES metaschema_public.database (id)
@@ -2529,7 +2624,9 @@ CREATE TABLE metaschema_modules_public.transfer_log_module (
2529
2624
  scope text NOT NULL DEFAULT 'app',
2530
2625
  actor_fk_table_id uuid NULL,
2531
2626
  entity_fk_table_id uuid NULL,
2532
- prefix text NULL,
2627
+ prefix text NOT NULL DEFAULT '',
2628
+ api_name text DEFAULT 'usage',
2629
+ private_api_name text DEFAULT NULL,
2533
2630
  CONSTRAINT db_fkey
2534
2631
  FOREIGN KEY(database_id)
2535
2632
  REFERENCES metaschema_public.database (id)
@@ -2571,7 +2668,9 @@ CREATE TABLE metaschema_modules_public.storage_log_module (
2571
2668
  scope text NOT NULL DEFAULT 'app',
2572
2669
  actor_fk_table_id uuid NULL,
2573
2670
  entity_fk_table_id uuid NULL,
2574
- prefix text NULL,
2671
+ prefix text NOT NULL DEFAULT '',
2672
+ api_name text DEFAULT 'usage',
2673
+ private_api_name text DEFAULT NULL,
2575
2674
  CONSTRAINT db_fkey
2576
2675
  FOREIGN KEY(database_id)
2577
2676
  REFERENCES metaschema_public.database (id)
@@ -2615,7 +2714,10 @@ CREATE TABLE metaschema_modules_public.db_usage_module (
2615
2714
  retention text NOT NULL DEFAULT '12 months',
2616
2715
  premake int NOT NULL DEFAULT 2,
2617
2716
  scope text NOT NULL DEFAULT 'app',
2618
- prefix text NULL,
2717
+ prefix text NOT NULL DEFAULT '',
2718
+ default_permissions text[] DEFAULT NULL,
2719
+ api_name text DEFAULT 'usage',
2720
+ private_api_name text DEFAULT NULL,
2619
2721
  CONSTRAINT db_fkey
2620
2722
  FOREIGN KEY(database_id)
2621
2723
  REFERENCES metaschema_public.database (id)
@@ -2659,21 +2761,31 @@ CREATE TABLE metaschema_modules_public.agent_module (
2659
2761
  message_table_id uuid NOT NULL DEFAULT uuid_nil(),
2660
2762
  task_table_id uuid NOT NULL DEFAULT uuid_nil(),
2661
2763
  prompts_table_id uuid NOT NULL DEFAULT uuid_nil(),
2662
- knowledge_table_id uuid DEFAULT NULL,
2764
+ plan_table_id uuid DEFAULT NULL,
2765
+ agent_table_id uuid DEFAULT NULL,
2766
+ persona_table_id uuid DEFAULT NULL,
2767
+ resource_table_id uuid DEFAULT NULL,
2663
2768
  thread_table_name text NOT NULL DEFAULT 'agent_thread',
2664
2769
  message_table_name text NOT NULL DEFAULT 'agent_message',
2665
2770
  task_table_name text NOT NULL DEFAULT 'agent_task',
2666
2771
  prompts_table_name text NOT NULL DEFAULT 'agent_prompt',
2667
- knowledge_table_name text NOT NULL DEFAULT 'agent_knowledge',
2668
- has_knowledge boolean NOT NULL DEFAULT false,
2772
+ plan_table_name text NOT NULL DEFAULT 'agent_plan',
2773
+ agent_table_name text NOT NULL DEFAULT 'agent',
2774
+ persona_table_name text NOT NULL DEFAULT 'agent_persona',
2775
+ resource_table_name text NOT NULL DEFAULT 'agent_resource',
2776
+ has_plans boolean NOT NULL DEFAULT false,
2777
+ has_resources boolean NOT NULL DEFAULT false,
2778
+ has_agents boolean NOT NULL DEFAULT false,
2779
+ shared boolean NOT NULL DEFAULT false,
2669
2780
  api_name text DEFAULT 'agent',
2670
- membership_type int DEFAULT NULL,
2671
- key text NOT NULL DEFAULT 'default',
2781
+ private_api_name text DEFAULT NULL,
2782
+ scope text NOT NULL DEFAULT 'app',
2783
+ prefix text NOT NULL DEFAULT '',
2672
2784
  entity_table_id uuid NULL,
2673
2785
  policies jsonb NULL,
2674
- knowledge_config jsonb NULL,
2675
- knowledge_policies jsonb NULL,
2786
+ resources jsonb NULL,
2676
2787
  provisions jsonb NULL,
2788
+ default_permissions text[] DEFAULT NULL,
2677
2789
  CONSTRAINT agent_module_db_fkey
2678
2790
  FOREIGN KEY(database_id)
2679
2791
  REFERENCES metaschema_public.database (id)
@@ -2702,8 +2814,20 @@ CREATE TABLE metaschema_modules_public.agent_module (
2702
2814
  FOREIGN KEY(prompts_table_id)
2703
2815
  REFERENCES metaschema_public."table" (id)
2704
2816
  ON DELETE CASCADE,
2705
- CONSTRAINT agent_module_knowledge_table_fkey
2706
- FOREIGN KEY(knowledge_table_id)
2817
+ CONSTRAINT agent_module_plan_table_fkey
2818
+ FOREIGN KEY(plan_table_id)
2819
+ REFERENCES metaschema_public."table" (id)
2820
+ ON DELETE CASCADE,
2821
+ CONSTRAINT agent_module_agent_table_fkey
2822
+ FOREIGN KEY(agent_table_id)
2823
+ REFERENCES metaschema_public."table" (id)
2824
+ ON DELETE CASCADE,
2825
+ CONSTRAINT agent_module_persona_table_fkey
2826
+ FOREIGN KEY(persona_table_id)
2827
+ REFERENCES metaschema_public."table" (id)
2828
+ ON DELETE CASCADE,
2829
+ CONSTRAINT agent_module_resource_table_fkey
2830
+ FOREIGN KEY(resource_table_id)
2707
2831
  REFERENCES metaschema_public."table" (id)
2708
2832
  ON DELETE CASCADE,
2709
2833
  CONSTRAINT agent_module_entity_table_fkey
@@ -2714,7 +2838,7 @@ CREATE TABLE metaschema_modules_public.agent_module (
2714
2838
 
2715
2839
  CREATE INDEX agent_module_database_id_idx ON metaschema_modules_public.agent_module (database_id);
2716
2840
 
2717
- CREATE UNIQUE INDEX agent_module_unique_scope ON metaschema_modules_public.agent_module (database_id, (COALESCE(membership_type, -1)), key);
2841
+ CREATE UNIQUE INDEX agent_module_unique_scope ON metaschema_modules_public.agent_module (database_id, scope, prefix);
2718
2842
 
2719
2843
  CREATE TABLE metaschema_modules_public.merkle_store_module (
2720
2844
  id uuid PRIMARY KEY DEFAULT uuidv7(),
@@ -2730,7 +2854,7 @@ CREATE TABLE metaschema_modules_public.merkle_store_module (
2730
2854
  prefix text NOT NULL DEFAULT '',
2731
2855
  api_name text,
2732
2856
  private_api_name text,
2733
- scope_field text NOT NULL DEFAULT 'scope_id',
2857
+ scope text NOT NULL DEFAULT 'app',
2734
2858
  created_at timestamptz NOT NULL DEFAULT now(),
2735
2859
  CONSTRAINT db_fkey
2736
2860
  FOREIGN KEY(database_id)
@@ -2775,6 +2899,7 @@ CREATE TABLE metaschema_modules_public.graph_module (
2775
2899
  private_schema_id uuid NOT NULL DEFAULT uuid_nil(),
2776
2900
  public_schema_name text,
2777
2901
  private_schema_name text,
2902
+ scope text NOT NULL DEFAULT 'app',
2778
2903
  prefix text NOT NULL DEFAULT '',
2779
2904
  merkle_store_module_id uuid NOT NULL,
2780
2905
  graphs_table_id uuid NOT NULL DEFAULT uuid_nil(),
@@ -2782,11 +2907,10 @@ CREATE TABLE metaschema_modules_public.graph_module (
2782
2907
  outputs_table_id uuid NOT NULL DEFAULT uuid_nil(),
2783
2908
  api_name text,
2784
2909
  private_api_name text,
2785
- scope_field text NOT NULL DEFAULT 'scope_id',
2786
- membership_type int DEFAULT NULL,
2787
2910
  entity_table_id uuid NULL,
2788
2911
  policies jsonb NULL,
2789
2912
  provisions jsonb NULL,
2913
+ default_permissions text[] DEFAULT NULL,
2790
2914
  created_at timestamptz NOT NULL DEFAULT now(),
2791
2915
  CONSTRAINT db_fkey
2792
2916
  FOREIGN KEY(database_id)
@@ -2839,11 +2963,12 @@ CREATE TABLE metaschema_modules_public.namespace_module (
2839
2963
  namespace_events_table_name text NOT NULL DEFAULT 'namespace_events',
2840
2964
  api_name text,
2841
2965
  private_api_name text,
2842
- membership_type int DEFAULT NULL,
2843
- key text NOT NULL DEFAULT 'default',
2966
+ scope text NOT NULL DEFAULT 'app',
2967
+ prefix text NOT NULL DEFAULT '',
2844
2968
  entity_table_id uuid NULL,
2845
2969
  policies jsonb NULL,
2846
2970
  provisions jsonb NULL,
2971
+ default_permissions text[] DEFAULT NULL,
2847
2972
  CONSTRAINT namespace_module_db_fkey
2848
2973
  FOREIGN KEY(database_id)
2849
2974
  REFERENCES metaschema_public.database (id)
@@ -2872,7 +2997,7 @@ CREATE TABLE metaschema_modules_public.namespace_module (
2872
2997
 
2873
2998
  CREATE INDEX namespace_module_database_id_idx ON metaschema_modules_public.namespace_module (database_id);
2874
2999
 
2875
- CREATE UNIQUE INDEX namespace_module_unique_scope ON metaschema_modules_public.namespace_module (database_id, (COALESCE(membership_type, -1)), key);
3000
+ CREATE UNIQUE INDEX namespace_module_unique_scope ON metaschema_modules_public.namespace_module (database_id, scope, prefix);
2876
3001
 
2877
3002
  CREATE TABLE metaschema_modules_public.function_module (
2878
3003
  id uuid PRIMARY KEY DEFAULT uuidv7(),
@@ -2885,23 +3010,18 @@ CREATE TABLE metaschema_modules_public.function_module (
2885
3010
  invocations_table_id uuid NOT NULL DEFAULT uuid_nil(),
2886
3011
  execution_logs_table_id uuid NOT NULL DEFAULT uuid_nil(),
2887
3012
  secret_definitions_table_id uuid NOT NULL DEFAULT uuid_nil(),
2888
- requirements_table_id uuid NOT NULL DEFAULT uuid_nil(),
2889
- config_definitions_table_id uuid NOT NULL DEFAULT uuid_nil(),
2890
- config_requirements_table_id uuid NOT NULL DEFAULT uuid_nil(),
2891
3013
  definitions_table_name text NOT NULL DEFAULT 'function_definitions',
2892
3014
  invocations_table_name text NOT NULL DEFAULT 'function_invocations',
2893
3015
  execution_logs_table_name text NOT NULL DEFAULT 'function_execution_logs',
2894
3016
  secret_definitions_table_name text NOT NULL DEFAULT 'secret_definitions',
2895
- requirements_table_name text NOT NULL DEFAULT 'function_secret_requirements',
2896
- config_requirements_table_name text NOT NULL DEFAULT 'function_config_requirements',
2897
3017
  api_name text,
2898
3018
  private_api_name text,
2899
- membership_type int DEFAULT NULL,
2900
- prefix text NULL,
2901
- key text NOT NULL DEFAULT 'default',
3019
+ scope text NOT NULL DEFAULT 'app',
3020
+ prefix text NOT NULL DEFAULT '',
2902
3021
  entity_table_id uuid NULL,
2903
3022
  policies jsonb NULL,
2904
3023
  provisions jsonb NULL,
3024
+ default_permissions text[] DEFAULT NULL,
2905
3025
  CONSTRAINT function_module_db_fkey
2906
3026
  FOREIGN KEY(database_id)
2907
3027
  REFERENCES metaschema_public.database (id)
@@ -2930,24 +3050,160 @@ CREATE TABLE metaschema_modules_public.function_module (
2930
3050
  FOREIGN KEY(secret_definitions_table_id)
2931
3051
  REFERENCES metaschema_public."table" (id)
2932
3052
  ON DELETE CASCADE,
2933
- CONSTRAINT function_module_requirements_table_fkey
2934
- FOREIGN KEY(requirements_table_id)
3053
+ CONSTRAINT function_module_entity_table_fkey
3054
+ FOREIGN KEY(entity_table_id)
2935
3055
  REFERENCES metaschema_public."table" (id)
3056
+ ON DELETE CASCADE
3057
+ );
3058
+
3059
+ CREATE INDEX function_module_database_id_idx ON metaschema_modules_public.function_module (database_id);
3060
+
3061
+ CREATE UNIQUE INDEX function_module_unique_scope ON metaschema_modules_public.function_module (database_id, scope, prefix);
3062
+
3063
+ CREATE TABLE metaschema_modules_public.config_secrets_module (
3064
+ id uuid PRIMARY KEY DEFAULT uuidv7(),
3065
+ database_id uuid NOT NULL,
3066
+ schema_id uuid NOT NULL DEFAULT uuid_nil(),
3067
+ private_schema_id uuid NOT NULL DEFAULT uuid_nil(),
3068
+ table_id uuid NOT NULL DEFAULT uuid_nil(),
3069
+ config_definitions_table_id uuid NULL DEFAULT NULL,
3070
+ table_name text NOT NULL DEFAULT 'secrets',
3071
+ api_name text DEFAULT 'config',
3072
+ private_api_name text DEFAULT NULL,
3073
+ scope text NOT NULL DEFAULT 'app',
3074
+ prefix text NOT NULL DEFAULT '',
3075
+ entity_table_id uuid NULL,
3076
+ policies jsonb NULL,
3077
+ provisions jsonb NULL,
3078
+ has_config boolean NOT NULL DEFAULT false,
3079
+ CONSTRAINT config_secrets_module_db_fkey
3080
+ FOREIGN KEY(database_id)
3081
+ REFERENCES metaschema_public.database (id)
2936
3082
  ON DELETE CASCADE,
2937
- CONSTRAINT function_module_config_defs_table_fkey
2938
- FOREIGN KEY(config_definitions_table_id)
3083
+ CONSTRAINT config_secrets_module_schema_fkey
3084
+ FOREIGN KEY(schema_id)
3085
+ REFERENCES metaschema_public.schema (id)
3086
+ ON DELETE CASCADE,
3087
+ CONSTRAINT config_secrets_module_private_schema_fkey
3088
+ FOREIGN KEY(private_schema_id)
3089
+ REFERENCES metaschema_public.schema (id)
3090
+ ON DELETE CASCADE,
3091
+ CONSTRAINT config_secrets_module_table_fkey
3092
+ FOREIGN KEY(table_id)
2939
3093
  REFERENCES metaschema_public."table" (id)
2940
3094
  ON DELETE CASCADE,
2941
- CONSTRAINT function_module_config_reqs_table_fkey
2942
- FOREIGN KEY(config_requirements_table_id)
3095
+ CONSTRAINT config_secrets_module_config_defs_table_fkey
3096
+ FOREIGN KEY(config_definitions_table_id)
2943
3097
  REFERENCES metaschema_public."table" (id)
2944
3098
  ON DELETE CASCADE,
2945
- CONSTRAINT function_module_entity_table_fkey
3099
+ CONSTRAINT config_secrets_module_entity_table_fkey
2946
3100
  FOREIGN KEY(entity_table_id)
2947
3101
  REFERENCES metaschema_public."table" (id)
2948
3102
  ON DELETE CASCADE
2949
3103
  );
2950
3104
 
2951
- CREATE INDEX function_module_database_id_idx ON metaschema_modules_public.function_module (database_id);
3105
+ CREATE INDEX config_secrets_module_database_id_idx ON metaschema_modules_public.config_secrets_module (database_id);
3106
+
3107
+ CREATE INDEX config_secrets_module_schema_id_idx ON metaschema_modules_public.config_secrets_module (schema_id);
3108
+
3109
+ CREATE INDEX config_secrets_module_table_id_idx ON metaschema_modules_public.config_secrets_module (table_id);
3110
+
3111
+ CREATE UNIQUE INDEX config_secrets_module_unique_scope ON metaschema_modules_public.config_secrets_module (database_id, scope, prefix);
3112
+
3113
+ COMMENT ON TABLE metaschema_modules_public.config_secrets_module IS 'Entity-aware PGP-encrypted key-value config/secrets module. Supports app-level (admin-only)
3114
+ and org-scoped (per-org secrets with manage_secrets permission) via the scope column.
3115
+ User-scoped bcrypt credentials are handled by user_credentials_module.';
3116
+
3117
+ CREATE TABLE metaschema_modules_public.user_credentials_module (
3118
+ id uuid PRIMARY KEY DEFAULT uuidv7(),
3119
+ database_id uuid NOT NULL,
3120
+ schema_id uuid NOT NULL DEFAULT uuid_nil(),
3121
+ table_id uuid NOT NULL DEFAULT uuid_nil(),
3122
+ table_name text NOT NULL DEFAULT 'user_secrets',
3123
+ api_name text DEFAULT 'config',
3124
+ private_api_name text DEFAULT NULL,
3125
+ CONSTRAINT user_credentials_module_db_fkey
3126
+ FOREIGN KEY(database_id)
3127
+ REFERENCES metaschema_public.database (id)
3128
+ ON DELETE CASCADE,
3129
+ CONSTRAINT user_credentials_module_schema_fkey
3130
+ FOREIGN KEY(schema_id)
3131
+ REFERENCES metaschema_public.schema (id)
3132
+ ON DELETE CASCADE,
3133
+ CONSTRAINT user_credentials_module_table_fkey
3134
+ FOREIGN KEY(table_id)
3135
+ REFERENCES metaschema_public."table" (id)
3136
+ ON DELETE CASCADE
3137
+ );
3138
+
3139
+ CREATE INDEX user_credentials_module_database_id_idx ON metaschema_modules_public.user_credentials_module (database_id);
3140
+
3141
+ CREATE INDEX user_credentials_module_schema_id_idx ON metaschema_modules_public.user_credentials_module (schema_id);
3142
+
3143
+ CREATE INDEX user_credentials_module_table_id_idx ON metaschema_modules_public.user_credentials_module (table_id);
3144
+
3145
+ CREATE UNIQUE INDEX user_credentials_module_unique ON metaschema_modules_public.user_credentials_module (database_id);
3146
+
3147
+ COMMENT ON TABLE metaschema_modules_public.user_credentials_module IS 'Per-user bcrypt credential store (password hashes, API key hashes).
3148
+ Always user-scoped with AuthzDirectOwner RLS. Consumed by user_auth_module,
3149
+ identity_providers_module, and bootstrap procedures.';
3150
+
3151
+ CREATE TABLE metaschema_modules_public.user_settings_module (
3152
+ id uuid PRIMARY KEY DEFAULT uuidv7(),
3153
+ database_id uuid NOT NULL,
3154
+ schema_id uuid NOT NULL DEFAULT uuid_nil(),
3155
+ table_id uuid NOT NULL DEFAULT uuid_nil(),
3156
+ owner_table_id uuid NOT NULL DEFAULT uuid_nil(),
3157
+ table_name text NOT NULL DEFAULT 'user_settings',
3158
+ api_name text DEFAULT NULL,
3159
+ CONSTRAINT db_fkey
3160
+ FOREIGN KEY(database_id)
3161
+ REFERENCES metaschema_public.database (id)
3162
+ ON DELETE CASCADE,
3163
+ CONSTRAINT schema_fkey
3164
+ FOREIGN KEY(schema_id)
3165
+ REFERENCES metaschema_public.schema (id)
3166
+ ON DELETE CASCADE,
3167
+ CONSTRAINT table_fkey
3168
+ FOREIGN KEY(table_id)
3169
+ REFERENCES metaschema_public."table" (id)
3170
+ ON DELETE CASCADE,
3171
+ CONSTRAINT owner_table_fkey
3172
+ FOREIGN KEY(owner_table_id)
3173
+ REFERENCES metaschema_public."table" (id)
3174
+ ON DELETE CASCADE
3175
+ );
3176
+
3177
+ CREATE INDEX user_settings_module_database_id_idx ON metaschema_modules_public.user_settings_module (database_id);
3178
+
3179
+ CREATE UNIQUE INDEX user_settings_module_unique_per_db ON metaschema_modules_public.user_settings_module (database_id);
3180
+
3181
+ CREATE TABLE metaschema_modules_public.i18n_module (
3182
+ id uuid PRIMARY KEY DEFAULT uuidv7(),
3183
+ database_id uuid NOT NULL,
3184
+ schema_id uuid NOT NULL DEFAULT uuid_nil(),
3185
+ private_schema_id uuid NOT NULL DEFAULT uuid_nil(),
3186
+ settings_table_id uuid NOT NULL DEFAULT uuid_nil(),
3187
+ api_name text DEFAULT NULL,
3188
+ private_api_name text DEFAULT NULL,
3189
+ CONSTRAINT db_fkey
3190
+ FOREIGN KEY(database_id)
3191
+ REFERENCES metaschema_public.database (id)
3192
+ ON DELETE CASCADE,
3193
+ CONSTRAINT schema_fkey
3194
+ FOREIGN KEY(schema_id)
3195
+ REFERENCES metaschema_public.schema (id)
3196
+ ON DELETE CASCADE,
3197
+ CONSTRAINT private_schema_fkey
3198
+ FOREIGN KEY(private_schema_id)
3199
+ REFERENCES metaschema_public.schema (id)
3200
+ ON DELETE CASCADE,
3201
+ CONSTRAINT settings_table_fkey
3202
+ FOREIGN KEY(settings_table_id)
3203
+ REFERENCES metaschema_public."table" (id)
3204
+ ON DELETE CASCADE
3205
+ );
3206
+
3207
+ CREATE INDEX i18n_module_database_id_idx ON metaschema_modules_public.i18n_module (database_id);
2952
3208
 
2953
- CREATE UNIQUE INDEX function_module_unique_scope ON metaschema_modules_public.function_module (database_id, (COALESCE(membership_type, -1)), key);
3209
+ CREATE UNIQUE INDEX i18n_module_unique_per_db ON metaschema_modules_public.i18n_module (database_id);