@rebasepro/server-postgres 0.30.1 → 0.31.0-canary.g59cd6fd

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 (248) hide show
  1. package/README.md +11 -8
  2. package/dist/{BranchService-CrXvcES2.js → BranchService-USp1AvZB.js} +3 -3
  3. package/dist/{BranchService-CrXvcES2.js.map → BranchService-USp1AvZB.js.map} +1 -1
  4. package/dist/PostgresBackendDriver.d.ts +99 -54
  5. package/dist/PostgresBootstrapper.d.ts +12 -27
  6. package/dist/auth/ensure-tables.d.ts +16 -5
  7. package/dist/auth/schema-version.d.ts +2 -2
  8. package/dist/auth/services.d.ts +2 -3
  9. package/dist/{auth-users-columns-C72EMoDJ.js → auth-users-columns-BpfgbkxZ.js} +2 -16
  10. package/dist/auth-users-columns-BpfgbkxZ.js.map +1 -0
  11. package/dist/{backup-cli-CTKCOLpX.js → backup-cli-DbKyEj6c.js} +4 -4
  12. package/dist/{backup-cli-CTKCOLpX.js.map → backup-cli-DbKyEj6c.js.map} +1 -1
  13. package/dist/{boot-ddl-CqGIwSYx.js → boot-ddl-5H2bL_80.js} +2 -2
  14. package/dist/{boot-ddl-CqGIwSYx.js.map → boot-ddl-5H2bL_80.js.map} +1 -1
  15. package/dist/{cli-console-DBPw-oAz.js → cli-console-DsRgGSBR.js} +65 -39
  16. package/dist/cli-console-DsRgGSBR.js.map +1 -0
  17. package/dist/cli-console.d.ts +16 -13
  18. package/dist/cli-flags.d.ts +8 -9
  19. package/dist/cli-helpers.d.ts +15 -11
  20. package/dist/{cli-errors-DYTxnLbW.js → cli-schema-dir-CiN0ephV.js} +184 -70
  21. package/dist/cli-schema-dir-CiN0ephV.js.map +1 -0
  22. package/dist/cli-schema-dir.d.ts +64 -0
  23. package/dist/cli.js +192 -257
  24. package/dist/cli.js.map +1 -1
  25. package/dist/data-transformer.d.ts +50 -19
  26. package/dist/{database-preflight-iBpT7-vv.js → database-preflight-bfnIBnjM.js} +5 -5
  27. package/dist/database-preflight-bfnIBnjM.js.map +1 -0
  28. package/dist/{deferred-index-build-BCU9RoHK.js → deferred-index-build-CcSDA7wE.js} +69 -13
  29. package/dist/deferred-index-build-CcSDA7wE.js.map +1 -0
  30. package/dist/{ensure-collection-policies-Bo-_fDAy.js → ensure-policies-rRmXb5bt.js} +31 -31
  31. package/dist/ensure-policies-rRmXb5bt.js.map +1 -0
  32. package/dist/{ensure-collection-tables-DCJINkT_.js → ensure-tables-Bvm-F2wW.js} +44 -37
  33. package/dist/ensure-tables-Bvm-F2wW.js.map +1 -0
  34. package/dist/{ensure-tables-BPGaGh0y.js → ensure-tables-CC8p_AK3.js} +34 -29
  35. package/dist/ensure-tables-CC8p_AK3.js.map +1 -0
  36. package/dist/{enum-labels-kept-YAgOZS4I.js → enum-labels-kept-FlX9SHdf.js} +8 -8
  37. package/dist/enum-labels-kept-FlX9SHdf.js.map +1 -0
  38. package/dist/{generate-drizzle-schema-DcrFr7YX.js → generate-drizzle-schema-SJMXxzPI.js} +12 -12
  39. package/dist/generate-drizzle-schema-SJMXxzPI.js.map +1 -0
  40. package/dist/{generate-drizzle-schema-logic-LTLZvt6r.js → generate-drizzle-schema-logic-DL7R1rAF.js} +15 -8
  41. package/dist/generate-drizzle-schema-logic-DL7R1rAF.js.map +1 -0
  42. package/dist/{generate-files-CsaVzatS.js → generate-files-tlJ9_lGI.js} +23 -30
  43. package/dist/generate-files-tlJ9_lGI.js.map +1 -0
  44. package/dist/{generate-next-step-DgK5BlBn.js → generate-next-step-CO09dovd.js} +3 -3
  45. package/dist/generate-next-step-CO09dovd.js.map +1 -0
  46. package/dist/{generate-postgres-ddl-logic-Dg0bcENZ.js → generate-postgres-ddl-logic-B8huc03c.js} +51 -21
  47. package/dist/generate-postgres-ddl-logic-B8huc03c.js.map +1 -0
  48. package/dist/{generated-schema-diff-By4dxyTH.js → generated-schema-diff-DoT2dYDe.js} +297 -279
  49. package/dist/generated-schema-diff-DoT2dYDe.js.map +1 -0
  50. package/dist/{generated-schema-staleness-BvNF3i-s.js → generated-schema-staleness-YBVq2kTn.js} +21 -29
  51. package/dist/generated-schema-staleness-YBVq2kTn.js.map +1 -0
  52. package/dist/history/ensure-history-table.d.ts +22 -0
  53. package/dist/index.d.ts +8 -2
  54. package/dist/index.es.js +201 -25
  55. package/dist/index.es.js.map +1 -1
  56. package/dist/interfaces.d.ts +3 -4
  57. package/dist/{introspect-db-queries-DevUrzll.js → introspect-db-queries-BgiRQqtR.js} +7 -2
  58. package/dist/introspect-db-queries-BgiRQqtR.js.map +1 -0
  59. package/dist/introspect-tables-Cw_A-kk4.js +2086 -0
  60. package/dist/introspect-tables-Cw_A-kk4.js.map +1 -0
  61. package/dist/load-tables-B1Re74ng.js +92 -0
  62. package/dist/load-tables-B1Re74ng.js.map +1 -0
  63. package/dist/{migrate-baseline-CmWXL7qx.js → migrate-baseline-DZmekgpD.js} +19 -32
  64. package/dist/migrate-baseline-DZmekgpD.js.map +1 -0
  65. package/dist/{migrate-policy-stamps-BN_Qad6c.js → migrate-policy-stamps-B_acrUQB.js} +18 -19
  66. package/dist/migrate-policy-stamps-B_acrUQB.js.map +1 -0
  67. package/dist/model/PostgresTableRegistry.d.ts +159 -0
  68. package/dist/model/build-registry.d.ts +25 -0
  69. package/dist/model/refresh-relational-schema.d.ts +24 -0
  70. package/dist/model/runtime-table.d.ts +53 -0
  71. package/dist/{collections → model}/validate-relations.d.ts +15 -21
  72. package/dist/{open-rebase-40paQfVW.js → open-rebase-4kisUF_k.js} +3946 -3870
  73. package/dist/open-rebase-4kisUF_k.js.map +1 -0
  74. package/dist/open-rebase.d.ts +16 -15
  75. package/dist/{pg-error-utils-DJHjCF7-.js → pg-error-utils-BT5NzGFZ.js} +17 -20
  76. package/dist/pg-error-utils-BT5NzGFZ.js.map +1 -0
  77. package/dist/plan-schema-Hbtjhge3.js +1633 -0
  78. package/dist/plan-schema-Hbtjhge3.js.map +1 -0
  79. package/dist/{policy-drift-C-m0uWHH.js → policy-drift-BVMyqHSa.js} +29 -29
  80. package/dist/policy-drift-BVMyqHSa.js.map +1 -0
  81. package/dist/{push-index-adoption-Cp7oZxSl.js → push-index-adoption-hpHTyXMR.js} +7 -7
  82. package/dist/push-index-adoption-hpHTyXMR.js.map +1 -0
  83. package/dist/{push-index-prebuild-DbwKGtQT.js → push-index-prebuild-Bty9F7bD.js} +6 -6
  84. package/dist/push-index-prebuild-Bty9F7bD.js.map +1 -0
  85. package/dist/{push-kept-defaults-CLcgsEPt.js → push-kept-defaults-Bst4MDup.js} +13 -16
  86. package/dist/push-kept-defaults-Bst4MDup.js.map +1 -0
  87. package/dist/{push-legacy-renames-BthD0E9W.js → push-legacy-renames-bB4bM6br.js} +6 -6
  88. package/dist/push-legacy-renames-bB4bM6br.js.map +1 -0
  89. package/dist/{push-policy-plan-BgcrroxQ.js → push-policy-plan-BI8U4BOD.js} +11 -11
  90. package/dist/push-policy-plan-BI8U4BOD.js.map +1 -0
  91. package/dist/{render-ddl-Ci3S_SoI.js → render-ddl-D4n86NHz.js} +14 -7
  92. package/dist/render-ddl-D4n86NHz.js.map +1 -0
  93. package/dist/{request-role-cli-Dy1EgJU9.js → request-role-cli-BdRzdE87.js} +11 -11
  94. package/dist/{request-role-cli-Dy1EgJU9.js.map → request-role-cli-BdRzdE87.js.map} +1 -1
  95. package/dist/{request-role-migration-GHTJnPMV.js → request-role-migration-C8aq_TO3.js} +2 -2
  96. package/dist/{request-role-migration-GHTJnPMV.js.map → request-role-migration-C8aq_TO3.js.map} +1 -1
  97. package/dist/{rls-enforcement-Cc_UhOxb.js → rls-enforcement-DB5HHj96.js} +19 -19
  98. package/dist/rls-enforcement-DB5HHj96.js.map +1 -0
  99. package/dist/{rls-settings-BCGMIig3.js → rls-settings-CmGK2U0a.js} +2 -2
  100. package/dist/rls-settings-CmGK2U0a.js.map +1 -0
  101. package/dist/schema/auth-users-columns.d.ts +1 -11
  102. package/dist/schema/catalogue-schema.d.ts +33 -29
  103. package/dist/schema/classify-change.d.ts +23 -16
  104. package/dist/schema/column-type-drift.d.ts +16 -0
  105. package/dist/schema/config-relations.d.ts +10 -9
  106. package/dist/schema/deferred-index-build.d.ts +1 -1
  107. package/dist/schema/doctor-cli.js +1544 -66
  108. package/dist/schema/doctor-cli.js.map +1 -1
  109. package/dist/schema/doctor-database.d.ts +7 -7
  110. package/dist/schema/doctor-policy-checks.d.ts +4 -4
  111. package/dist/schema/doctor-search-scale.d.ts +14 -14
  112. package/dist/schema/doctor.d.ts +27 -27
  113. package/dist/schema/dynamic-tables.d.ts +6 -5
  114. package/dist/schema/{ensure-collection-policies.d.ts → ensure-policies.d.ts} +20 -20
  115. package/dist/schema/{ensure-collection-tables.d.ts → ensure-tables.d.ts} +11 -11
  116. package/dist/schema/enum-labels-kept.d.ts +6 -6
  117. package/dist/schema/generate-drizzle-schema-logic.d.ts +3 -3
  118. package/dist/schema/generate-drizzle-schema.js +1 -1
  119. package/dist/schema/generate-files.d.ts +6 -6
  120. package/dist/schema/generate-postgres-ddl-logic.d.ts +23 -20
  121. package/dist/schema/generate-postgres-ddl.js +11 -11
  122. package/dist/schema/generate-postgres-ddl.js.map +1 -1
  123. package/dist/schema/generate-schema-commit.d.ts +13 -8
  124. package/dist/schema/generated-schema-diff.d.ts +16 -16
  125. package/dist/schema/generated-schema-staleness.d.ts +11 -11
  126. package/dist/schema/index-adoption.d.ts +4 -4
  127. package/dist/schema/introspect-db-customization.d.ts +47 -0
  128. package/dist/schema/introspect-db-inference.d.ts +30 -9
  129. package/dist/schema/introspect-db-logic.d.ts +79 -110
  130. package/dist/schema/introspect-db-project.d.ts +15 -18
  131. package/dist/schema/introspect-db-queries.d.ts +1 -1
  132. package/dist/schema/introspect-db-search.d.ts +25 -4
  133. package/dist/schema/introspect-db-storage.d.ts +4 -74
  134. package/dist/schema/introspect-db.js +102 -90
  135. package/dist/schema/introspect-db.js.map +1 -1
  136. package/dist/schema/introspect-runtime.d.ts +47 -36
  137. package/dist/schema/introspect-tables.d.ts +182 -0
  138. package/dist/schema/load-tables.d.ts +55 -0
  139. package/dist/schema/migrate-policy-stamps.d.ts +4 -4
  140. package/dist/schema/migration-freshness.d.ts +13 -13
  141. package/dist/schema/plan/column-order.d.ts +82 -0
  142. package/dist/schema/plan/diff-plan.d.ts +9 -3
  143. package/dist/schema/plan/plan-schema.d.ts +55 -52
  144. package/dist/schema/plan/render-drizzle.d.ts +1 -1
  145. package/dist/schema/plan/types.d.ts +24 -15
  146. package/dist/schema/push-index-adoption.d.ts +3 -3
  147. package/dist/schema/push-index-prebuild.d.ts +3 -3
  148. package/dist/schema/push-kept-defaults.d.ts +7 -7
  149. package/dist/schema/push-legacy-renames.d.ts +3 -3
  150. package/dist/schema/push-policy-plan.d.ts +5 -5
  151. package/dist/schema/reconcile-schema.d.ts +5 -5
  152. package/dist/schema/relation-names.d.ts +15 -20
  153. package/dist/schema/render-outputs.d.ts +76 -0
  154. package/dist/schema/search-column.d.ts +11 -43
  155. package/dist/schema/{collection-index.d.ts → table-index.d.ts} +21 -42
  156. package/dist/schema/{collections-schema-version.d.ts → tables-schema-version.d.ts} +8 -2
  157. package/dist/schema/vector-index.d.ts +24 -28
  158. package/dist/{search-column-BM-GV6vH.js → search-column-BO-WND-B.js} +86 -149
  159. package/dist/search-column-BO-WND-B.js.map +1 -0
  160. package/dist/security/caller-sql-columns.d.ts +9 -6
  161. package/dist/security/policy-drift.d.ts +14 -14
  162. package/dist/security/rls-enforcement.d.ts +19 -25
  163. package/dist/security/rls-settings.d.ts +2 -2
  164. package/dist/security/served-table-protection.d.ts +125 -0
  165. package/dist/services/FetchService.d.ts +22 -133
  166. package/dist/services/PersistService.d.ts +6 -17
  167. package/dist/services/RelationService.d.ts +57 -106
  168. package/dist/services/RelationWriteService.d.ts +59 -66
  169. package/dist/services/cdc/identity-columns.d.ts +7 -5
  170. package/dist/services/cdc/junction-tables.d.ts +14 -14
  171. package/dist/services/collection-helpers.d.ts +52 -95
  172. package/dist/services/dataService.d.ts +15 -12
  173. package/dist/services/field-op-sql.d.ts +11 -9
  174. package/dist/services/field-viewer.d.ts +12 -11
  175. package/dist/services/hidden-columns.d.ts +30 -0
  176. package/dist/services/index.d.ts +1 -1
  177. package/dist/services/junction-writes.d.ts +37 -18
  178. package/dist/services/nested-path.d.ts +18 -18
  179. package/dist/services/read-field-access.d.ts +23 -7
  180. package/dist/services/read-scope.d.ts +10 -9
  181. package/dist/services/realtimeService.d.ts +25 -10
  182. package/dist/services/relation-tables.d.ts +97 -0
  183. package/dist/services/row-pipeline.d.ts +50 -69
  184. package/dist/services/soft-delete.d.ts +25 -24
  185. package/dist/services/table-hooks.d.ts +146 -0
  186. package/dist/services/view-access.d.ts +7 -7
  187. package/dist/services/write-transaction-scope.d.ts +1 -1
  188. package/dist/{source-fZb92pN8.js → source-VxbrQojV.js} +111 -79
  189. package/dist/source-VxbrQojV.js.map +1 -0
  190. package/dist/{collections-schema-version-D7bDI0PJ.js → tables-schema-version-YvZIBlOP.js} +12 -6
  191. package/dist/tables-schema-version-YvZIBlOP.js.map +1 -0
  192. package/dist/utils/drizzle-conditions.d.ts +70 -84
  193. package/dist/utils/pg-array-null-patch.d.ts +27 -10
  194. package/dist/utils/pg-error-utils.d.ts +4 -4
  195. package/dist/{vector-index-DsQ3V2d2.js → vector-index-VSh3ufTd.js} +62 -54
  196. package/dist/vector-index-VSh3ufTd.js.map +1 -0
  197. package/dist/{websocket-B7ex6AQM.js → websocket-BevXvwfo.js} +51 -40
  198. package/dist/websocket-BevXvwfo.js.map +1 -0
  199. package/dist/websocket.d.ts +2 -2
  200. package/package.json +7 -7
  201. package/dist/auth-users-columns-C72EMoDJ.js.map +0 -1
  202. package/dist/cli-collections-path.d.ts +0 -31
  203. package/dist/cli-console-DBPw-oAz.js.map +0 -1
  204. package/dist/cli-errors-DYTxnLbW.js.map +0 -1
  205. package/dist/collections/PostgresCollectionRegistry.d.ts +0 -47
  206. package/dist/collections/buildRegistry.d.ts +0 -27
  207. package/dist/collections-schema-version-D7bDI0PJ.js.map +0 -1
  208. package/dist/column-plan-helpers-BeSztMor.js +0 -161
  209. package/dist/column-plan-helpers-BeSztMor.js.map +0 -1
  210. package/dist/database-preflight-iBpT7-vv.js.map +0 -1
  211. package/dist/deferred-index-build-BCU9RoHK.js.map +0 -1
  212. package/dist/doctor-Kg1oUK0Q.js +0 -1458
  213. package/dist/doctor-Kg1oUK0Q.js.map +0 -1
  214. package/dist/ensure-collection-policies-Bo-_fDAy.js.map +0 -1
  215. package/dist/ensure-collection-tables-DCJINkT_.js.map +0 -1
  216. package/dist/ensure-tables-BPGaGh0y.js.map +0 -1
  217. package/dist/enum-labels-kept-YAgOZS4I.js.map +0 -1
  218. package/dist/generate-drizzle-schema-DcrFr7YX.js.map +0 -1
  219. package/dist/generate-drizzle-schema-logic-LTLZvt6r.js.map +0 -1
  220. package/dist/generate-files-CsaVzatS.js.map +0 -1
  221. package/dist/generate-next-step-DgK5BlBn.js.map +0 -1
  222. package/dist/generate-postgres-ddl-logic-Dg0bcENZ.js.map +0 -1
  223. package/dist/generated-schema-diff-By4dxyTH.js.map +0 -1
  224. package/dist/generated-schema-staleness-BvNF3i-s.js.map +0 -1
  225. package/dist/introspect-db-logic-DWqAEURB.js +0 -2047
  226. package/dist/introspect-db-logic-DWqAEURB.js.map +0 -1
  227. package/dist/introspect-db-queries-DevUrzll.js.map +0 -1
  228. package/dist/migrate-baseline-CmWXL7qx.js.map +0 -1
  229. package/dist/migrate-policy-stamps-BN_Qad6c.js.map +0 -1
  230. package/dist/open-rebase-40paQfVW.js.map +0 -1
  231. package/dist/pg-error-utils-DJHjCF7-.js.map +0 -1
  232. package/dist/plan-schema-vJd3UEmT.js +0 -1604
  233. package/dist/plan-schema-vJd3UEmT.js.map +0 -1
  234. package/dist/policy-drift-C-m0uWHH.js.map +0 -1
  235. package/dist/push-index-adoption-Cp7oZxSl.js.map +0 -1
  236. package/dist/push-index-prebuild-DbwKGtQT.js.map +0 -1
  237. package/dist/push-kept-defaults-CLcgsEPt.js.map +0 -1
  238. package/dist/push-legacy-renames-BthD0E9W.js.map +0 -1
  239. package/dist/push-policy-plan-BgcrroxQ.js.map +0 -1
  240. package/dist/render-ddl-Ci3S_SoI.js.map +0 -1
  241. package/dist/rls-enforcement-Cc_UhOxb.js.map +0 -1
  242. package/dist/rls-settings-BCGMIig3.js.map +0 -1
  243. package/dist/schema/column-plan-helpers.d.ts +0 -161
  244. package/dist/schema/introspect-db-naming.d.ts +0 -10
  245. package/dist/search-column-BM-GV6vH.js.map +0 -1
  246. package/dist/source-fZb92pN8.js.map +0 -1
  247. package/dist/vector-index-DsQ3V2d2.js.map +0 -1
  248. package/dist/websocket-B7ex6AQM.js.map +0 -1
@@ -1,4 +1,4 @@
1
- import { CollectionConfig, Property } from "@rebasepro/types";
1
+ import { type ColumnType, type CompiledTable, type TableDescriptor } from "@rebasepro/types";
2
2
  import { type SchemaDifference } from "./generated-schema-diff.js";
3
3
  import type { PgType, SchemaPlan, TablePlan } from "./plan/types.js";
4
4
  export type IssueSeverity = "error" | "warning" | "info";
@@ -68,24 +68,15 @@ export interface DoctorReport {
68
68
  };
69
69
  }
70
70
  /**
71
- * The `data_type` the database should report for a property's column, or `null`
72
- * when there is nothing to compare.
73
- *
74
- * `null` covers the two honest cases: a `relation`, whose column is derived from
75
- * the relation rather than from the property, and a configuration the planner
76
- * refuses outright — which is a problem the doctor's other phases report with a
77
- * message, not a type mismatch to invent one for.
78
- */
79
- export declare function getExpectedColumnType(prop: Property): string | null;
80
- /**
81
- * Re-exported so callers keep importing it from here, but the implementation is
82
- * now shared with the runtime and the generators — a doctor that disagreed with
83
- * the policy generator about which files are collections would compare the
84
- * wrong thing.
71
+ * The `data_type` the database should report for a column of this type, or
72
+ * `null` when there is nothing to compare: a `col.custom()` type (the boot diff
73
+ * compares it by `format_type`), or a type the planner refuses outright.
85
74
  */
86
- export declare function loadCollections(collectionsPath: string): Promise<CollectionConfig[]>;
87
- export declare function checkCollectionsVsSchema(collections: CollectionConfig[], schemaFilePath: string): Promise<DoctorPhase>;
88
- export declare function checkCollectionsVsSdk(collections: CollectionConfig[], sdkFilePath: string): Promise<DoctorPhase>;
75
+ export declare function expectedDataType(type: ColumnType): string | null;
76
+ export declare function checkTablesVsSchema(tables: readonly CompiledTable[], schemaFilePath: string): Promise<DoctorPhase>;
77
+ export declare function checkTablesVsSdk(
78
+ /** The tables' compiled descriptors — what `rebase generate-sdk` generates from. */
79
+ descriptors: readonly TableDescriptor[], sdkFilePath: string): Promise<DoctorPhase>;
89
80
  interface DbColumn {
90
81
  table_schema: string;
91
82
  table_name: string;
@@ -95,9 +86,9 @@ interface DbColumn {
95
86
  udt_name: string;
96
87
  }
97
88
  /**
98
- * Extensions the collections need, that the database does not have installed.
89
+ * Extensions the tables need, that the database does not have installed.
99
90
  *
100
- * Only `vector` today, and only because a `{ type: "vector" }` property plans a
91
+ * Only `vector` today, and only because a `col.vector()` column plans a
101
92
  * column of a type that will not exist. Rebase installs it only where a project
102
93
  * has said it may (`database({ extensions: ["vector"] })`), so the absence is
103
94
  * often correct configuration and a wrong deployment — which is exactly why the
@@ -105,12 +96,13 @@ interface DbColumn {
105
96
  *
106
97
  * Exported for its test.
107
98
  */
108
- export declare function missingExtensionIssues(collections: CollectionConfig[], installed: ReadonlySet<string>): DoctorIssue[];
99
+ export declare function missingExtensionIssues(tables: readonly TableDescriptor[], installed: ReadonlySet<string>): DoctorIssue[];
109
100
  /**
110
- * The stamp the runtime wrote, against the collections on disk.
101
+ * The stamp the runtime wrote, against the tables on disk (their compiled
102
+ * descriptors, which is what the stamp is computed over).
111
103
  *
112
104
  * A stamp that disagrees means this database was provisioned from a different
113
- * set of collections than the ones in this checkout — a colleague's branch, an
105
+ * set of tables than the ones in this checkout — a colleague's branch, an
114
106
  * older deploy, a tenant somebody else migrated. Everything else in this report
115
107
  * is then describing a schema somebody else created, which is worth knowing
116
108
  * before acting on any of it.
@@ -124,7 +116,9 @@ export declare function schemaStampIssues(pool: {
124
116
  query<T>(text: string): Promise<{
125
117
  rows: T[];
126
118
  }>;
127
- }, collections: CollectionConfig[]): Promise<DoctorIssue[]>;
119
+ },
120
+ /** The version this checkout computes — `defaultDatabaseSchemaVersion`, what a boot and a push stamp. */
121
+ expected: string): Promise<DoctorIssue[]>;
128
122
  /**
129
123
  * What to do about a column whose type is not the one the collection plans.
130
124
  *
@@ -158,13 +152,19 @@ export declare function junctionKeyIssues(junctionPlan: TablePlan, dbColumns: Db
158
152
  * the doctor never compared them, which is how it came to say "In sync" beside
159
153
  * a boot that had just warned about both.
160
154
  */
161
- export declare function generatedSchemaDriftIssues(differences: SchemaDifference[], already: DoctorIssue[], collections: CollectionConfig[]): DoctorIssue[];
162
- export declare function checkCollectionsVsDatabase(collections: CollectionConfig[], databaseUrl: string, options?: {
155
+ export declare function generatedSchemaDriftIssues(differences: SchemaDifference[], already: DoctorIssue[], tables: readonly TableDescriptor[]): DoctorIssue[];
156
+ export declare function checkTablesVsDatabase(tables: readonly CompiledTable[], databaseUrl: string, options?: {
163
157
  /**
164
158
  * The `tables` export of `schema.generated.ts`, for boot's own drift
165
159
  * comparison. Without it the doctor compares the collections alone.
166
160
  */
167
161
  generated?: Record<string, unknown>;
162
+ /**
163
+ * The schema version this checkout computes
164
+ * (`defaultDatabaseSchemaVersion`), to compare against the stamp the
165
+ * runtime or a push wrote. Without it that one check is not made.
166
+ */
167
+ schemaVersion?: string;
168
168
  }): Promise<DoctorPhase>;
169
169
  /**
170
170
  * A `public` table in the junction shape that no collection declares.
@@ -187,7 +187,7 @@ export declare function orphanedJunctionIssues(plan: SchemaPlan, columnsByTable:
187
187
  }[]>): DoctorIssue[];
188
188
  export declare function renderReport(report: DoctorReport): void;
189
189
  export declare function runDoctor(options: {
190
- collectionsPath: string;
190
+ schemaDir: string;
191
191
  schemaPath: string;
192
192
  sdkPath: string;
193
193
  databaseUrl?: string;
@@ -16,9 +16,9 @@
16
16
  * Two things a caller has to supply for the tables to match what the generated
17
17
  * module used to produce, both about *names*: the Drizzle object is keyed by the
18
18
  * wire name of a column and not by the column (`authorId`, not `author_id`), and
19
- * a relation is keyed by the collection's own relation key rather than by a
20
- * guess made from the foreign key. Both come from the collections — see
21
- * `columnKeysFromCollections` and `buildDrizzleRelationsFromCollections`.
19
+ * a relation is keyed by the table's own relation name rather than by a
20
+ * guess made from the foreign key. Both come from the table descriptors — see
21
+ * `columnKeysFromTables` and `buildDrizzleRelationsFromTables`.
22
22
  */
23
23
  import { type PgTable } from "drizzle-orm/pg-core";
24
24
  import { type Relations } from "drizzle-orm";
@@ -46,7 +46,8 @@ export declare function buildDrizzleTablesFromSchema(tablesMap: Map<string, Tabl
46
46
  * property on the collection. Tables alone don't satisfy that — without these,
47
47
  * `?include=author` silently returns the raw `author_id` and no author.
48
48
  *
49
- * The keys here must match `buildRelations` in introspect-runtime.ts, which is
50
- * what names the collection's relation properties.
49
+ * The keys here must match the relation names `introspectTables` gives an
50
+ * introspected table (`introspect-tables.ts`), which name the collection's
51
+ * relation properties.
51
52
  */
52
53
  export declare function buildDrizzleRelationsFromSchema(tablesMap: Map<string, TableMeta>, tables: Record<string, PgTable>, columnKey?: ColumnKeyResolver): Record<string, Relations>;
@@ -1,6 +1,6 @@
1
- import { type CollectionConfig } from "@rebasepro/types";
2
- import { type CollectionPolicyPlan } from "./generate-postgres-ddl-logic.js";
3
- import { type Queryable } from "./ensure-collection-tables.js";
1
+ import { type CompiledTable } from "@rebasepro/types";
2
+ import { type TablePolicyPlan } from "./generate-postgres-ddl-logic.js";
3
+ import { type Queryable } from "./ensure-tables.js";
4
4
  import { type BootLockOptions } from "./boot-ddl.js";
5
5
  export interface PolicyEnsureResult {
6
6
  /** `CREATE POLICY` statements that ran successfully. */
@@ -69,18 +69,18 @@ export interface PolicyEnsureResult {
69
69
  rulesChanged: boolean;
70
70
  }[];
71
71
  /**
72
- * Tables whose collection declares no rule of its own and which still held
72
+ * Tables that declare no rule of their own (`rls: "admin-only"`, or
73
+ * `"inherit"` of an admin-only `defaultRls`) and which still held
73
74
  * generated rule policies, all of them dropped: the generated policies, by
74
75
  * name, the boot is to warn about.
75
76
  *
76
77
  * An edited rule supersedes its old policy, and that drop is the point of
77
- * {@link PolicyEnsureResult.orphansDropped}. A collection with no rule at
78
- * all is something else: what a collection looks like when the
79
- * `defaultSecurityRules` its directory's index declares never reached it —
80
- * an array handed to a backend without them. Dropping is still right (the
81
- * declared state wins, and the table is left admin-only rather than open),
82
- * but it changes who can read the table on every server sharing the
83
- * database, so it is not done in silence.
78
+ * {@link PolicyEnsureResult.orphansDropped}. A table with no rule at all is
79
+ * something else: what a table looks like when the `defaultRls` it meant
80
+ * to inherit never reached it — a server handed another schema directory,
81
+ * say. Dropping is still right (the declared state wins, and the table is
82
+ * left admin-only rather than open), but it changes who can read the table
83
+ * on every server sharing the database, so it is not done in silence.
84
84
  */
85
85
  rulesDropped: {
86
86
  table: string;
@@ -102,7 +102,7 @@ export declare const POLICY_STAMP_PREFIX = "rebase:";
102
102
  * @param only the names to stamp, when not every policy on the table is known
103
103
  * to be what its statement makes — see `stampPoliciesStoredAsRendered`.
104
104
  */
105
- export declare function policyStampSql(plan: CollectionPolicyPlan, only?: ReadonlySet<string>): string | undefined;
105
+ export declare function policyStampSql(plan: TablePolicyPlan, only?: ReadonlySet<string>): string | undefined;
106
106
  /**
107
107
  * What its stamp says of a declared policy the database has: written by Rebase
108
108
  * from the statement the plan renders now and still holding that definition
@@ -120,7 +120,7 @@ export type PolicyStampState = "current" | "stale" | "unstamped";
120
120
  * `search_path`: call it under the path the stamps were written under (a
121
121
  * boot's, `public` unless the URL pins one), or a current stamp reads stale.
122
122
  */
123
- export declare function readPolicyStamps(client: Queryable, collections: CollectionConfig[], options?: {
123
+ export declare function readPolicyStamps(client: Queryable, compiledTables: readonly CompiledTable[], options?: {
124
124
  adminRoleAvailable?: boolean;
125
125
  }): Promise<Map<string, Map<string, PolicyStampState>>>;
126
126
  /**
@@ -140,7 +140,7 @@ export declare function readPolicyStamps(client: Queryable, collections: Collect
140
140
  * parse — is left out of the answer, and the caller keeps what the stamp said.
141
141
  * Keyed `schema.table.name`.
142
142
  */
143
- export declare function probeRenderedPolicies(client: Queryable, collections: CollectionConfig[], policies: readonly {
143
+ export declare function probeRenderedPolicies(client: Queryable, compiledTables: readonly CompiledTable[], policies: readonly {
144
144
  schema: string;
145
145
  table: string;
146
146
  name: string;
@@ -155,7 +155,7 @@ export interface TableLockResult {
155
155
  unsecured: PolicyEnsureResult["unsecured"];
156
156
  }
157
157
  /**
158
- * Switch RLS on for every table the collections declare — each collection's
158
+ * Switch RLS on for every table the tables declare — each collection's
159
159
  * and each junction's — and do nothing else.
160
160
  *
161
161
  * The first thing `rebase db push` does once Atlas has committed. Atlas cannot
@@ -169,13 +169,13 @@ export interface TableLockResult {
169
169
  * A declared table that is not in the database is skipped — nothing can reach
170
170
  * a table that does not exist, and the step that creates it locks it.
171
171
  */
172
- export declare function lockCollectionTables(client: Queryable, collections: CollectionConfig[]): Promise<TableLockResult>;
172
+ export declare function lockTables(client: Queryable, compiledTables: readonly CompiledTable[]): Promise<TableLockResult>;
173
173
  /**
174
- * The declared tables {@link lockCollectionTables} would switch row-level
174
+ * The declared tables {@link lockTables} would switch row-level
175
175
  * security on for: those in the database with it off. What `db push
176
176
  * --dry-run` lists, read the way the push's lock step reads it.
177
177
  */
178
- export declare function tablesRlsWouldEnable(client: Queryable, collections: CollectionConfig[]): Promise<string[]>;
178
+ export declare function tablesRlsWouldEnable(client: Queryable, compiledTables: readonly CompiledTable[]): Promise<string[]>;
179
179
  /**
180
180
  * Bring the declared collections' RLS policies up to date. Returns what it did.
181
181
  *
@@ -215,7 +215,7 @@ export declare function tablesRlsWouldEnable(client: Queryable, collections: Col
215
215
  * it is exactly as it was before this boot — or, if RLS was off on it, closed
216
216
  * by revoking the user role's grant, like every table RLS cannot be enabled on.
217
217
  */
218
- export declare function ensureCollectionPolicies(client: Queryable, collections: CollectionConfig[], log?: (message: string) => void, options?: BootLockOptions & {
218
+ export declare function ensureTablePolicies(client: Queryable, compiledTables: readonly CompiledTable[], log?: (message: string) => void, options?: BootLockOptions & {
219
219
  /**
220
220
  * Whether this server's admin switch is live (`settleAdminSwitch`).
221
221
  * `false` writes the server-or-admin policies `TO public` and creates
@@ -226,7 +226,7 @@ export declare function ensureCollectionPolicies(client: Queryable, collections:
226
226
  adminRoleAvailable?: boolean;
227
227
  /**
228
228
  * Whether the admin-only policies get their `TO rebase_admin_request
229
- * USING (true)` companions — see `planCollectionPolicies`. Only a boot
229
+ * USING (true)` companions — see `planTablePolicies`. Only a boot
230
230
  * that has made that role safe (`settleAdminRequestGroup`) says so;
231
231
  * anywhere else they are not planned, and any in the database are
232
232
  * dropped as orphans.
@@ -21,7 +21,7 @@
21
21
  * human reading a diff. So it may only ever do things that cannot lose data.
22
22
  * See `diff-plan.ts` for the whole of that argument.
23
23
  */
24
- import { type CollectionConfig } from "@rebasepro/types";
24
+ import { type CompiledTable } from "@rebasepro/types";
25
25
  import { type ConstraintPolicy, type DeferredIndexBuild, type DiffOptions, type EnsureAction, type EnsurePlan, type ExistingSchema, type LegacyForeignKey, type OrphanedRequiredColumn, type SearchColumnDrift, type WithheldConstraint } from "./plan/diff-plan.js";
26
26
  import { type DeferredIndexOutcome, type OpenIndexBuildSession } from "./deferred-index-build.js";
27
27
  export type { ConstraintPolicy, DeferredIndexBuild, EnsureAction, EnsurePlan, ExistingSchema, LegacyForeignKey, OrphanedRequiredColumn, SearchColumnDrift, WithheldConstraint };
@@ -48,7 +48,7 @@ export interface EnsureOptions extends DiffOptions {
48
48
  * Explicit rather than read from the resource registry in here, because the
49
49
  * planner is pure and several callers plan against fixtures: reaching for a
50
50
  * process-wide registry would make the plan depend on whatever some other
51
- * module happened to import. `ensureCollectionTables` is the boundary that
51
+ * module happened to import. `ensureTables` is the boundary that
52
52
  * reads the world.
53
53
  */
54
54
  databaseExtensions?: readonly string[];
@@ -64,7 +64,7 @@ export interface EnsureOptions extends DiffOptions {
64
64
  * Apply the statements that build tables this run creates — and the enum
65
65
  * types they use — in transactions of up to {@link NEW_TABLE_BATCH}
66
66
  * statements instead of one autocommit each. The boot sets it; see
67
- * `ensureCollectionTables`.
67
+ * `ensureTables`.
68
68
  */
69
69
  batchNewTables?: boolean;
70
70
  /**
@@ -112,15 +112,15 @@ export interface EnsureOutcome extends EnsurePlan {
112
112
  * Decide what to add. Pure — the caller supplies what exists and runs the
113
113
  * result.
114
114
  *
115
- * A plan and a diff: the collections are read once, by `planSchema`, into the
115
+ * A plan and a diff: the tables are read once, by `planSchema`, into the
116
116
  * same {@link SchemaPlan} `db push` renders `schema.sql` from, and the diff
117
117
  * subtracts what the database already has. Before that split this function had
118
- * its own reading of every `Property`, and the audit found twelve places where
118
+ * its own reading of every column, and the audit found twelve places where
119
119
  * it disagreed with the two generators — a required `author_id` that was
120
120
  * NOT NULL after a push and nullable after a boot among them, on the one path
121
121
  * with no developer in the loop.
122
122
  */
123
- export declare function planCollectionSchemaEnsure(allCollections: CollectionConfig[], existing: ExistingSchema, options?: EnsureOptions): EnsurePlan;
123
+ export declare function planTableSchemaEnsure(tables: readonly CompiledTable[], existing: ExistingSchema, options?: EnsureOptions): EnsurePlan;
124
124
  export interface ReadSchemaOptions {
125
125
  /**
126
126
  * The existing tables worth probing for rows, given every table's columns.
@@ -138,15 +138,15 @@ export interface ReadSchemaOptions {
138
138
  /** Read what the database has, for the schemas the collections live in. */
139
139
  export declare function readExistingSchema(client: Queryable, schemas: string[], options?: ReadSchemaOptions): Promise<ExistingSchema>;
140
140
  /**
141
- * Read what the database looks like, for the schemas a set of collections
142
- * lives in.
141
+ * Read what the database looks like, for the schemas a set of tables lives
142
+ * in.
143
143
  *
144
- * The same read `ensureCollectionTables` does at boot, exposed on its own for
144
+ * The same read `ensureTables` does at boot, exposed on its own for
145
145
  * the callers that want to *plan* against a real database without changing it —
146
146
  * the live schema editor, which has to tell somebody what a change would do
147
147
  * before they agree to it.
148
148
  */
149
- export declare function readSchemaFactsFor(client: Queryable, collections: CollectionConfig[]): Promise<ExistingSchema>;
149
+ export declare function readSchemaFactsFor(client: Queryable, tables: readonly CompiledTable[]): Promise<ExistingSchema>;
150
150
  /**
151
151
  * Bring the database up to date. Returns what it did.
152
152
  *
@@ -155,7 +155,7 @@ export declare function readSchemaFactsFor(client: Queryable, collections: Colle
155
155
  * cannot be added, say) should not roll back the tables that were created fine.
156
156
  * The error is surfaced with the statement that caused it.
157
157
  */
158
- export declare function ensureCollectionTables(client: Queryable, collections: CollectionConfig[], log?: (message: string) => void, options?: EnsureOptions): Promise<EnsureOutcome>;
158
+ export declare function ensureTables(client: Queryable, tables: readonly CompiledTable[], log?: (message: string) => void, options?: EnsureOptions): Promise<EnsureOutcome>;
159
159
  /**
160
160
  * What actually went wrong, rather than what the ORM said about it.
161
161
  *
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Enum labels the database holds and the collections no longer declare.
2
+ * Enum labels the database holds and the tables no longer declare.
3
3
  *
4
4
  * PostgreSQL has no `ALTER TYPE … DROP VALUE`, and Atlas plans nothing for a
5
5
  * removed label — `db push` reported success while the database kept the old
@@ -9,18 +9,18 @@
9
9
  * refusal — the push stays what boot would do — but the push says it, with the
10
10
  * real way to retire a label.
11
11
  */
12
- import { type CollectionConfig } from "@rebasepro/types";
12
+ import { type CompiledTable } from "@rebasepro/types";
13
13
  import type { EnumPlan } from "./plan/types.js";
14
- import { type Queryable } from "./ensure-collection-tables.js";
14
+ import { type Queryable } from "./ensure-tables.js";
15
15
  export interface KeptEnumLabels {
16
16
  /** `schema.type`, as the catalogue names it. */
17
17
  type: string;
18
- /** Labels in the database that no collection declares, in the type's order. */
18
+ /** Labels in the database that no table declares, in the type's order. */
19
19
  labels: string[];
20
20
  }
21
21
  /** Pure: the declared enums against the catalogue's labels, keyed `schema.type`. */
22
22
  export declare function findKeptEnumLabels(declared: Pick<EnumPlan, "qualified" | "labels">[], existing: ReadonlyMap<string, string[]>): KeptEnumLabels[];
23
- /** Plans the collections and reads the catalogue's enum labels. */
24
- export declare function keptEnumLabels(client: Queryable, collections: CollectionConfig[]): Promise<KeptEnumLabels[]>;
23
+ /** Plans the tables and reads the catalogue's enum labels. */
24
+ export declare function keptEnumLabels(client: Queryable, tables: readonly CompiledTable[]): Promise<KeptEnumLabels[]>;
25
25
  /** What the push prints: which labels stay, and how one is actually retired. */
26
26
  export declare function formatKeptEnumLabelsNotice(kept: KeptEnumLabels[]): string;
@@ -11,10 +11,10 @@
11
11
  * `validation.unique`, and each disagreeing with the other two about something.
12
12
  * See `schema/plan/types.ts`.
13
13
  */
14
- import type { CollectionConfig } from "@rebasepro/types";
14
+ import type { CompiledTable } from "@rebasepro/types";
15
15
  import { type DrizzleRenderOptions } from "./plan/render-drizzle.js";
16
16
  /**
17
- * The generated Drizzle schema for a set of collections.
17
+ * The generated Drizzle schema for a set of tables.
18
18
  *
19
19
  * Synchronous, and takes an options object. It was `async` with nothing to
20
20
  * await and a positional `stripPolicies` boolean — `generateSchema(c, true)`,
@@ -25,4 +25,4 @@ import { type DrizzleRenderOptions } from "./plan/render-drizzle.js";
25
25
  * against the file on disk, so with the sort in the writer only, a project
26
26
  * whose file order differed from its slug order was reported stale forever.
27
27
  */
28
- export declare const generateSchema: (allCollections: CollectionConfig[], options?: DrizzleRenderOptions) => string;
28
+ export declare const generateSchema: (tables: readonly CompiledTable[], options?: DrizzleRenderOptions) => string;
@@ -1,6 +1,6 @@
1
1
  import { createRequire as __createRequire } from "module";
2
2
  __createRequire(import.meta.url);
3
- import { t as main } from "../generate-drizzle-schema-DcrFr7YX.js";
3
+ import { t as main } from "../generate-drizzle-schema-SJMXxzPI.js";
4
4
  //#region src/schema/bin/generate-drizzle-schema.ts
5
5
  /**
6
6
  * The built entry point for `generate-drizzle-schema`.
@@ -4,12 +4,12 @@
4
4
  * They used to exist only as scripts, each its own `tsx` process: the driver
5
5
  * (itself a `tsx` process) spawned one for the Drizzle schema and then one for
6
6
  * the DDL, and each paid a Node start, tsx's loader and an import of the whole
7
- * server package before reading a single collection — about 0.5 s apiece, a
7
+ * server package before reading a single table — about 0.5 s apiece, a
8
8
  * second per push. The driver process is one-shot, so a fresh module graph per
9
- * generation bought nothing: the collections cannot change under it.
9
+ * generation bought nothing: the tables cannot change under it.
10
10
  *
11
11
  * The scripts remain (`generate-drizzle-schema.ts`, `generate-postgres-ddl.ts`)
12
- * for `--watch`, which re-imports the collections on every save and does need a
12
+ * for `--watch`, which re-imports the tables on every save and does need a
13
13
  * process of its own — Node's module cache would serve it the first version
14
14
  * forever.
15
15
  *
@@ -24,8 +24,8 @@ export declare class GenerationFailed extends Error {
24
24
  });
25
25
  }
26
26
  export interface GenerateFileOptions {
27
- /** The collections directory (or single module), resolved against the cwd. */
28
- collectionsPath: string;
27
+ /** The schema directory (`backend/schema`: its index exports the tables), resolved against the cwd. */
28
+ schemaDir: string;
29
29
  /** Where to write. Absent: print to stdout instead. */
30
30
  outputPath?: string;
31
31
  /**
@@ -35,7 +35,7 @@ export interface GenerateFileOptions {
35
35
  */
36
36
  nextStep?: boolean;
37
37
  }
38
- /** `src/schema.generated.ts`, from the collections. */
38
+ /** `src/schema.generated.ts`, from the tables. */
39
39
  export declare function writeDrizzleSchema(options: GenerateFileOptions): Promise<void>;
40
40
  /**
41
41
  * `schema.sql` (Atlas's desired state) and, beside it, `policies.sql`,
@@ -5,21 +5,21 @@
5
5
  * reads the collections into a {@link SchemaPlan} and `schema/plan/render-ddl.ts`
6
6
  * writes the files; what remains here is the public entry points those two are
7
7
  * reached through, plus the smaller plans (`planRelationalColumns`,
8
- * `planJunctionTables`, `planCollectionPolicies`) that other modules ask for as
8
+ * `planJunctionTables`, `planTablePolicies`) that other modules ask for as
9
9
  * slices of the same plan.
10
10
  *
11
11
  * It used to hold `getSqlColumnType` and a `CREATE TABLE` walk with its own
12
12
  * reading of relations, junctions, enums and search — one of three such
13
13
  * readings. See `schema/plan/types.ts` for what that cost.
14
14
  */
15
- import { CollectionConfig, SecurityRule } from "@rebasepro/types";
15
+ import { type CompiledTable, type SecurityRule, type TableDescriptor } from "@rebasepro/types";
16
+ import { type ResolvePolicyTable } from "@rebasepro/common";
16
17
  import { quoteSqlLiteral, defaultBelongsToOnDelete } from "./plan/plan-schema.js";
17
18
  import { type DdlRenderOptions } from "./plan/render-ddl.js";
18
19
  import type { ForeignKeyPlan } from "./plan/types.js";
19
20
  import type { GeneratedColumnDependency } from "./generated-column-conflicts.js";
20
21
  export { quoteSqlLiteral, defaultBelongsToOnDelete };
21
22
  export type { ForeignKeyPlan };
22
- type ResolveCollection = (slug: string) => CollectionConfig | undefined;
23
23
  /**
24
24
  * The individual SQL statements a single security rule compiles to: a
25
25
  * `DROP POLICY IF EXISTS` / `CREATE POLICY` pair per operation, each a complete
@@ -28,8 +28,11 @@ type ResolveCollection = (slug: string) => CollectionConfig | undefined;
28
28
  * This is the primitive the boot-time RLS applier runs one statement at a time
29
29
  * (the runtime's DB handle speaks the extended query protocol, which forbids
30
30
  * multiple commands in one execute), while `db push` writes the joined string.
31
+ *
32
+ * `resolveTable` answers the tables a rule's `existsIn` reaches; by default
33
+ * only the table itself.
31
34
  */
32
- export declare const generatePolicyStatements: (collection: CollectionConfig, rule: SecurityRule, resolveCollection: ResolveCollection) => string[];
35
+ export declare const generatePolicyStatements: (table: TableDescriptor, rule: SecurityRule, resolveTable?: ResolvePolicyTable) => string[];
33
36
  /**
34
37
  * `.rebase/sql/schema.sql` — the desired state Atlas diffs the database against.
35
38
  *
@@ -38,9 +41,9 @@ export declare const generatePolicyStatements: (collection: CollectionConfig, ru
38
41
  * for no reason and made the one place that forgot to await it silently compare
39
42
  * `[object Promise]`.
40
43
  */
41
- export declare const generatePostgresDdl: (allCollections: CollectionConfig[], options?: DdlRenderOptions) => string;
44
+ export declare const generatePostgresDdl: (tables: readonly CompiledTable[], options?: DdlRenderOptions) => string;
42
45
  /** `.rebase/sql/policies.sql` — the RLS policies. Atlas has no model for a policy. */
43
- export declare const generatePostgresPoliciesDdl: (allCollections: CollectionConfig[]) => string;
46
+ export declare const generatePostgresPoliciesDdl: (tables: readonly CompiledTable[]) => string;
44
47
  /**
45
48
  * `.rebase/sql/search.sql` — everything a `search` block needs, as a file Rebase
46
49
  * applies itself.
@@ -60,7 +63,7 @@ export declare const generatePostgresPoliciesDdl: (allCollections: CollectionCon
60
63
  *
61
64
  * Empty when nothing opted in — the caller writes no file then.
62
65
  */
63
- export declare const generatePostgresSearchDdl: (allCollections: CollectionConfig[]) => string;
66
+ export declare const generatePostgresSearchDdl: (tables: readonly CompiledTable[]) => string;
64
67
  /**
65
68
  * Glob patterns telling Atlas to leave the search column and its index alone.
66
69
  *
@@ -68,7 +71,7 @@ export declare const generatePostgresSearchDdl: (allCollections: CollectionConfi
68
71
  * instruction to drop the column — taking the index and the whole search
69
72
  * feature with it on the next push.
70
73
  */
71
- export declare const searchExcludePatterns: (allCollections: CollectionConfig[]) => string[];
74
+ export declare const searchExcludePatterns: (tables: readonly CompiledTable[]) => string[];
72
75
  /**
73
76
  * `.rebase/sql/vector.sql` — the `vector` columns, their ANN indexes and, when a
74
77
  * database declared it, the extension.
@@ -80,11 +83,11 @@ export declare const searchExcludePatterns: (allCollections: CollectionConfig[])
80
83
  * run — so `VECTOR(384)` resolves against a database that structurally cannot
81
84
  * have pgvector, and every push dies with `type "vector" does not exist`.
82
85
  */
83
- export declare const generatePostgresVectorDdl: (allCollections: CollectionConfig[], options?: {
86
+ export declare const generatePostgresVectorDdl: (tables: readonly CompiledTable[], options?: {
84
87
  extensions?: readonly string[];
85
88
  }) => string;
86
89
  /** @see searchExcludePatterns */
87
- export declare const vectorExcludePatterns: (allCollections: CollectionConfig[]) => string[];
90
+ export declare const vectorExcludePatterns: (tables: readonly CompiledTable[]) => string[];
88
91
  /**
89
92
  * `.rebase/sql/triggers.sql` — the `BEFORE UPDATE` triggers behind
90
93
  * `autoValue: "on_update"`, and the one function they share.
@@ -93,15 +96,15 @@ export declare const vectorExcludePatterns: (allCollections: CollectionConfig[])
93
96
  * for the first of the two reasons search is. Empty when no property declares
94
97
  * `on_update` — the caller writes no file then, and removes a stale one.
95
98
  */
96
- export declare const generatePostgresTriggersDdl: (allCollections: CollectionConfig[]) => string;
99
+ export declare const generatePostgresTriggersDdl: (tables: readonly CompiledTable[]) => string;
97
100
  /**
98
101
  * `.rebase/sql/views.sql` — the views of the collections that declare `view`,
99
102
  * which Atlas's free tier does not manage. Empty when none does — the caller
100
103
  * writes no file then, and removes a stale one.
101
104
  */
102
- export declare const generatePostgresViewsDdl: (allCollections: CollectionConfig[]) => string;
105
+ export declare const generatePostgresViewsDdl: (tables: readonly CompiledTable[]) => string;
103
106
  /** @see searchExcludePatterns */
104
- export declare const triggerExcludePatterns: (allCollections: CollectionConfig[]) => string[];
107
+ export declare const triggerExcludePatterns: (tables: readonly CompiledTable[]) => string[];
105
108
  /** A column a `relation` or `reference` property owns on its own table. */
106
109
  export interface RelationalColumnPlan {
107
110
  schema: string;
@@ -149,7 +152,7 @@ export interface JunctionTablePlan {
149
152
  * the `CREATE TABLE` one, which is how boot-ensure came to add every relation
150
153
  * column bare while `db push` made the same column `NOT NULL`.
151
154
  */
152
- export declare const planRelationalColumns: (allCollections: CollectionConfig[]) => RelationalColumnPlan[];
155
+ export declare const planRelationalColumns: (tables: readonly CompiledTable[]) => RelationalColumnPlan[];
153
156
  /**
154
157
  * The junction tables a bundle's many-to-many relations imply.
155
158
  *
@@ -157,8 +160,8 @@ export declare const planRelationalColumns: (allCollections: CollectionConfig[])
157
160
  * here always has policies planned for it — a junction with row-level security
158
161
  * left off is readable and writable by every signed-in user.
159
162
  */
160
- export declare const planJunctionTables: (allCollections: CollectionConfig[]) => JunctionTablePlan[];
161
- export interface CollectionPolicyPlan {
163
+ export declare const planJunctionTables: (tables: readonly CompiledTable[]) => JunctionTablePlan[];
164
+ export interface TablePolicyPlan {
162
165
  /** The table's schema (e.g. `public`, `rebase`). */
163
166
  schema: string;
164
167
  /** The bare table name, no schema prefix. */
@@ -177,7 +180,7 @@ export interface CollectionPolicyPlan {
177
180
  */
178
181
  policies: PolicyApplyPlan[];
179
182
  }
180
- /** One policy of a {@link CollectionPolicyPlan}, as the statements that make it. */
183
+ /** One policy of a {@link TablePolicyPlan}, as the statements that make it. */
181
184
  export interface PolicyApplyPlan {
182
185
  name: string;
183
186
  /** Written `TO rebase_admin` by the compiler's choice (`rls.adminPolicies`). */
@@ -198,7 +201,7 @@ export interface PolicyApplyPlan {
198
201
  * The same policies `policies.sql` carries, from the same plan, so boot and
199
202
  * `db push` produce identical RLS from identical collections.
200
203
  */
201
- export declare const planCollectionPolicies: (allCollections: CollectionConfig[], options?: {
204
+ export declare const planTablePolicies: (tables: readonly CompiledTable[], options?: {
202
205
  adminRoleAvailable?: boolean;
203
206
  /**
204
207
  * The boot made `rebase_admin_request`, granted it to the admin request
@@ -207,7 +210,7 @@ export declare const planCollectionPolicies: (allCollections: CollectionConfig[]
207
210
  * are left out, and the boot drops any left in the database.
208
211
  */
209
212
  adminRequestRoleAvailable?: boolean;
210
- }) => CollectionPolicyPlan[];
213
+ }) => TablePolicyPlan[];
211
214
  /**
212
215
  * The `generated column → column it reads` edges a project's `search` blocks
213
216
  * imply, derived from the collections alone.
@@ -218,4 +221,4 @@ export declare const planCollectionPolicies: (allCollections: CollectionConfig[]
218
221
  * A spec's `fields[].column` is the physical column each search field starts
219
222
  * at, which is exactly what the generated expression depends on.
220
223
  */
221
- export declare const searchColumnDependencies: (allCollections: CollectionConfig[]) => GeneratedColumnDependency[];
224
+ export declare const searchColumnDependencies: (tables: readonly CompiledTable[]) => GeneratedColumnDependency[];
@@ -1,20 +1,20 @@
1
1
  import { createRequire as __createRequire } from "module";
2
2
  __createRequire(import.meta.url);
3
- import { r as out } from "../source-fZb92pN8.js";
4
- import { r as writePostgresDdl } from "../generate-files-CsaVzatS.js";
3
+ import { r as out } from "../source-VxbrQojV.js";
4
+ import { r as writePostgresDdl } from "../generate-files-tlJ9_lGI.js";
5
5
  import path from "path";
6
6
  //#region src/schema/generate-postgres-ddl.ts
7
7
  /**
8
8
  * The generator as its own process — what `--watch` runs, because a watch has
9
- * to re-import the collections on every save and Node's module cache would
9
+ * to re-import the tables on every save and Node's module cache would
10
10
  * serve it the first version forever. One-shot generation runs in the driver's
11
11
  * own process instead; see `generate-files.ts`.
12
12
  */
13
- var runGeneration = async (collectionsFilePath, outputPath) => {
14
- if (!collectionsFilePath) throw new Error("No collections file path provided.");
13
+ var runGeneration = async (schemaDir, outputPath) => {
14
+ if (!schemaDir) throw new Error("No schema directory provided.");
15
15
  try {
16
16
  await writePostgresDdl({
17
- collectionsPath: path.resolve(collectionsFilePath),
17
+ schemaDir: path.resolve(schemaDir),
18
18
  outputPath
19
19
  });
20
20
  } catch (error) {
@@ -23,16 +23,16 @@ var runGeneration = async (collectionsFilePath, outputPath) => {
23
23
  }
24
24
  };
25
25
  var main = async () => {
26
- const collectionsFilePathArg = process.argv.find((arg) => arg.startsWith("--collections="));
27
- const collectionsFilePath = collectionsFilePathArg ? collectionsFilePathArg.split("=")[1] : process.argv[2];
26
+ const schemaDirArg = process.argv.find((arg) => arg.startsWith("--schema-dir="));
27
+ const schemaDir = schemaDirArg ? schemaDirArg.split("=")[1] : process.argv[2];
28
28
  const outputPathArg = process.argv.find((arg) => arg.startsWith("--output="));
29
29
  const outputPath = outputPathArg ? outputPathArg.split("=")[1] : void 0;
30
30
  const watch = process.argv.includes("--watch");
31
- if (!collectionsFilePath) {
32
- out("Usage: ts-node generate-postgres-ddl.ts <path-to-collections-file> [--output <path-to-output-file>] [--watch]");
31
+ if (!schemaDir) {
32
+ out("Usage: ts-node generate-postgres-ddl.ts --schema-dir=<backend/schema> [--output=<path-to-output-file>] [--watch]");
33
33
  return;
34
34
  }
35
- const resolvedPath = path.resolve(process.cwd(), collectionsFilePath);
35
+ const resolvedPath = path.resolve(process.cwd(), schemaDir);
36
36
  const resolvedOutputPath = outputPath ? path.resolve(process.cwd(), outputPath) : void 0;
37
37
  if (watch) {
38
38
  out(`Watching for changes in ${resolvedPath}...`);