@rebasepro/server-postgres 0.30.0 → 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,28 +1,23 @@
1
- import { CollectionConfig, ResolvedRelation } from "@rebasepro/types";
1
+ import type { RelationDescriptor, TableDescriptor } from "@rebasepro/types";
2
+ /**
3
+ * The key a SQL column is served under on a table: its column's key, or — for
4
+ * a column the table does not describe — the camelCase of its name, which is
5
+ * the key a foreign key derived from it would get.
6
+ */
7
+ export declare const servedKeyOf: (descriptor: TableDescriptor, sqlColumn: string) => string;
2
8
  /**
3
9
  * The `relationName` both sides of a link must agree on.
4
10
  *
5
11
  * Drizzle pairs an owning `one()` with its inverse `many()` by this string and
6
12
  * by nothing else, and the two sides are computed by different callers holding
7
- * different collections — so the rule has to be derivable from either end. It
8
- * is: name the link after the table that carries the foreign key and the field
9
- * key that column is served under.
10
- *
11
- * owning (belongsTo) → `{thisTable}_{fieldKey(localKey)}`
12
- * inverse (hasMany/hasOne) → `{targetTable}_{fieldKey(foreignKeyOnTarget)}`
13
- *
14
- * Both spellings of `jobs.company` produce `jobs_companyId`. A many-to-many is
15
- * named through its junction wiring and a `via` chain is not a Drizzle relation
16
- * at all, so both keep the local name.
13
+ * different tables — so the rule has to be derivable from either end. It is:
14
+ * name the link after the table that carries the foreign key and the key that
15
+ * column is served under (the key, not the column: the Drizzle object is keyed
16
+ * by the wire name, {@link servedKeyOf}).
17
17
  *
18
- * The field key rather than the column: the Drizzle object is keyed by the wire
19
- * name (`fieldKeyForColumn` is the one definition of it), and a name built from
20
- * the column would differ between a collection that declares `columnName` and
21
- * one that does not, for the same link.
18
+ * owning (belongsTo) → `{thisTable}_{key(localKey)}`
19
+ * inverse (hasMany/hasOne) → `{targetTable}_{key(foreignKey)}`
22
20
  *
23
- * **This is the one definition.** `generate-drizzle-schema-logic.ts` holds a
24
- * private copy (`computeSharedRelationName`) that this was lifted from verbatim;
25
- * the generator should import this instead, so the file it writes and the
26
- * relations the runtime builds from the live catalogue cannot drift apart.
21
+ * A many-to-many and a `via` chain keep the relation's own name.
27
22
  */
28
- export declare function sharedRelationName(relation: ResolvedRelation, sourceCollection: CollectionConfig): string;
23
+ export declare function tableRelationName(relation: RelationDescriptor, source: TableDescriptor, targetOf: (slug: string) => TableDescriptor): string;
@@ -0,0 +1,76 @@
1
+ /**
2
+ * Everything the schema pipeline emits for a set of collections, rendered as
3
+ * text, so two sets can be compared byte for byte.
4
+ *
5
+ * The plan-golden corpus freezes these outputs for every collection set the
6
+ * planner is held to, and the collections-to-tables codemod (`rebase migrate
7
+ * collections-to-tables`) uses the same renderer to prove a migration
8
+ * lossless: the legacy collections and the migrated tables, lowered, must
9
+ * render identically — DDL, policies, search, vector, triggers, views, the
10
+ * Drizzle schema and the boot plans. One renderer, so the proof and the
11
+ * corpus can never disagree about what "the same schema" means.
12
+ */
13
+ import { type CompiledTable } from "@rebasepro/types";
14
+ /**
15
+ * Process state the planner reads besides its arguments.
16
+ *
17
+ * `declaredRlsPolicyShape` reads these three variables and the global database
18
+ * registry, so the same collections plan differently on a host that exports
19
+ * one. Every render runs with all three unset and the registry empty.
20
+ *
21
+ * @group Schema
22
+ */
23
+ export declare const PLANNER_ENV_VARIABLES: readonly ["REBASE_RLS_POLICY_TARGET", "REBASE_RLS_ADMIN_POLICIES", "REBASE_RLS_DEFAULT_POLICIES"];
24
+ /**
25
+ * Run `render` with the planner's ambient inputs pinned, restoring the
26
+ * environment after.
27
+ *
28
+ * @group Schema
29
+ */
30
+ export declare function withPinnedPlannerWorld<T>(render: () => T): T;
31
+ /**
32
+ * A plan or a planned object as stable JSON text.
33
+ *
34
+ * Functions are dropped (a relation's `target` thunk is not data), `Map`s become
35
+ * entry arrays and `Set`s arrays, in insertion order — which is the planner's
36
+ * own order, and is part of what is being compared. A cycle is written as
37
+ * `"[circular]"` rather than thrown on.
38
+ *
39
+ * @group Schema
40
+ */
41
+ export declare function toStableJson(value: unknown, omitTopLevelKeys?: readonly string[]): string;
42
+ /**
43
+ * What {@link renderSchemaOutputs} is planned with — the inputs besides the
44
+ * tables.
45
+ *
46
+ * @group Schema
47
+ */
48
+ export interface RenderSchemaOutputsOptions {
49
+ /**
50
+ * `declaredDatabaseExtensions()` for the boot plan and `plan.json`.
51
+ * `vector.sql` is rendered with and without the extension either way.
52
+ */
53
+ databaseExtensions?: readonly string[];
54
+ }
55
+ /**
56
+ * Everything the schema pipeline emits for one set of tables, by file name.
57
+ *
58
+ * - `schema*.sql`: `generatePostgresDdl` under all eight `DdlRenderOptions`
59
+ * combinations (`schema.sql` is the one `db generate` writes: all three off).
60
+ * - `policies.sql`, `search.sql`, `vector.sql`, `vector+extension.sql`,
61
+ * `triggers.sql`, `views.sql`: the files written beside it.
62
+ * - `schema.generated.ts` / `schema.generated.no-policies.ts`: the Drizzle schema.
63
+ * - `atlas-excludes.json`: the patterns that keep Atlas off the carved-out objects.
64
+ * - `boot-ensure.json`: `planTableSchemaEnsure` against an empty database.
65
+ * - `boot-policies.adminRole-*.adminRequestRole-*.json`: `planTablePolicies`
66
+ * for the four role-availability combinations.
67
+ * - `relational-columns.json`, `junction-tables.json`: the legacy-column slices.
68
+ * - `plan.json`: `planSchema` itself, functions stripped.
69
+ *
70
+ * Planned in slug order, with the planner's environment pinned. An output that
71
+ * throws is recorded as `THROWS: <message>` in its own file, so a refusal is
72
+ * compared like any other output.
73
+ *
74
+ * @group Schema
75
+ */
76
+ export declare function renderSchemaOutputs(tables: readonly CompiledTable[], options?: RenderSchemaOutputsOptions): Record<string, string>;
@@ -1,5 +1,5 @@
1
1
  /**
2
- * The one place a collection's `search` block becomes SQL.
2
+ * The one place a table's `search` block becomes SQL.
3
3
  *
4
4
  * Four things describe a Postgres table in this codebase — the DDL generator,
5
5
  * the Drizzle schema generator, the runtime table builder for BaaS mode, and
@@ -43,7 +43,7 @@
43
43
  * `auditor` and `auditoria` to `auditori` — *different lexemes* — so a query
44
44
  * typed without accents misses every row that carries them.
45
45
  */
46
- import { CollectionConfig, SearchConfig, SearchMode, SearchWeight } from "@rebasepro/types";
46
+ import { SearchMode, SearchWeight, type TableDescriptor } from "@rebasepro/types";
47
47
  /**
48
48
  * Names of the helper functions. Frozen: they are recorded in the stored
49
49
  * generation expression of every search column ever created, so renaming one
@@ -113,28 +113,14 @@ export interface SearchColumnSpec {
113
113
  export declare class SearchConfigError extends Error {
114
114
  constructor(message: string);
115
115
  }
116
- /** The `search` block of a collection, or undefined when it has none. */
117
- export declare const getSearchConfig: (collection: CollectionConfig) => SearchConfig | undefined;
118
116
  /**
119
- * Refuse a `search` block on a collection this engine does not store.
117
+ * The search column a table's `search` block asks for, or `undefined` when
118
+ * it declares none — read from the table descriptor. What the planner calls.
120
119
  *
121
- * The type only permits one on a `PostgresCollectionConfig`, so TypeScript
122
- * already stops the ordinary case. This catches the rest — a JS config, a cast,
123
- * a collection whose `engine` was changed after the block was written — because
124
- * the alternative is the exact failure the block exists to prevent: a developer
125
- * who declared what to index, saw no error, and got the substring fallback.
126
- *
127
- * Called with *every* collection, before the Postgres ones are filtered out.
120
+ * Throws {@link SearchConfigError} on a block that cannot be honoured; the
121
+ * compiler refuses most of them first (`checkSearch`).
128
122
  */
129
- export declare const assertSearchIsPostgresOnly: (collections: CollectionConfig[]) => void;
130
- /**
131
- * Build the full spec for a collection, or undefined when it has not opted in.
132
- *
133
- * Throws {@link SearchConfigError} on a config that cannot be honoured. Callers
134
- * at boot surface that as a startup failure — a search block that half-works is
135
- * worse than one that refuses.
136
- */
137
- export declare const buildSearchColumnSpec: (collection: CollectionConfig) => SearchColumnSpec | undefined;
123
+ export declare const buildTableSearchColumnSpec: (table: TableDescriptor) => SearchColumnSpec | undefined;
138
124
  /**
139
125
  * The IMMUTABLE wrappers the generated expressions call.
140
126
  *
@@ -240,19 +226,14 @@ export declare const searchStampGuards: (spec: SearchColumnSpec) => string[];
240
226
  */
241
227
  export declare const searchIndexNames: (spec: SearchColumnSpec) => string[];
242
228
  /**
243
- * The generated column names a collection's search block adds, if any.
244
- *
245
- * These are physical columns on the table, so `SELECT *` returns them. They are
246
- * an index in column form — a list of lexeme positions, or a concatenation of
247
- * every searchable field on the row — and nothing outside the query planner has
248
- * any use for them. Left in, every list response carries a second, larger copy
249
- * of the row's text.
229
+ * The generated column names a table's search block adds, read from its
230
+ * descriptor: the search columns (`search_vector`, and the fuzzy column when there is one).
250
231
  */
251
- export declare const searchColumnNames: (collection: CollectionConfig) => string[];
232
+ export declare const tableSearchColumnNames: (table: TableDescriptor) => string[];
252
233
  /**
253
234
  * True for a column whose type only ever holds a search index.
254
235
  *
255
- * Independent of any collection config on purpose: an introspected database
236
+ * Independent of any table declaration on purpose: an introspected database
256
237
  * (BaaS mode) can carry a `tsvector` column this framework never created —
257
238
  * Pagila's `film.fulltext` is the canonical one — and it should not be returned
258
239
  * to callers either. `isDerivedIndexColumn` already keeps such a column out of
@@ -261,17 +242,4 @@ export declare const searchColumnNames: (collection: CollectionConfig) => string
261
242
  export declare const isSearchIndexColumn: (column: {
262
243
  getSQLType?: () => string;
263
244
  }) => boolean;
264
- /**
265
- * A drizzle select projection over `table` with the search columns dropped.
266
- *
267
- * Returns undefined when nothing needs dropping, so the common case keeps using
268
- * a plain `select()` and this stays invisible in the generated SQL.
269
- */
270
- export declare const visibleColumnProjection: <C extends {
271
- getSQLType?: () => string;
272
- }>(tableColumns: Record<string, C> | undefined, collection?: CollectionConfig) => Record<string, C> | undefined;
273
- /** The same exclusion as a drizzle `db.query` `columns` denylist. */
274
- export declare const hiddenColumnsOption: (tableColumns: Record<string, {
275
- getSQLType?: () => string;
276
- }> | undefined, collection?: CollectionConfig) => Record<string, false> | undefined;
277
245
  export {};
@@ -1,5 +1,5 @@
1
1
  /**
2
- * The one place a collection's `indexes:` block becomes `CREATE INDEX`.
2
+ * The one place a table's `indexes` become `CREATE INDEX`.
3
3
  *
4
4
  * Like `search-column.ts` and `vector-index.ts`, this module exists so the DDL
5
5
  * generator and the boot-time ensure render the *same* specification rather
@@ -31,9 +31,7 @@
31
31
  * dropped, there is never a window with no index, and drift detection reduces
32
32
  * to a set difference over names.
33
33
  */
34
- import type { CollectionConfig, Property } from "@rebasepro/types";
35
- /** Resolve a property key to its column name. Injected to avoid an import cycle. */
36
- export type ResolveColumnName = (propName: string, prop?: Property | null) => string;
34
+ import type { TableDescriptor } from "@rebasepro/types";
37
35
  export type IndexMethod = "btree" | "gin" | "brin";
38
36
  /** A key column, with the ordering Postgres will actually apply. */
39
37
  export interface ResolvedIndexKey {
@@ -59,7 +57,7 @@ export type ResolvedPredicate = {
59
57
  and: readonly ResolvedPredicate[];
60
58
  };
61
59
  /** One index, fully resolved. The only shape the renderers accept. */
62
- export interface CollectionIndexSpec {
60
+ export interface TableIndexSpec {
63
61
  schema: string;
64
62
  table: string;
65
63
  method: IndexMethod;
@@ -67,8 +65,11 @@ export interface CollectionIndexSpec {
67
65
  keys: ResolvedIndexKey[];
68
66
  include: string[];
69
67
  predicate: ResolvedPredicate | null;
70
- /** The author's one-line justification. Never enters the name. */
71
- reason: string;
68
+ /**
69
+ * The author's one-line justification, when there is one. Never enters
70
+ * the name. A legacy `indexes` entry must state it; a table's may not.
71
+ */
72
+ reason?: string;
72
73
  /** Derived by {@link deriveIndexName}. Frozen — see the module comment. */
73
74
  indexName: string;
74
75
  /**
@@ -89,7 +90,7 @@ export interface CollectionIndexSpec {
89
90
  * the alternative is a `CREATE INDEX` that fails during a push with a Postgres
90
91
  * error mentioning a column the author never wrote.
91
92
  */
92
- export declare class CollectionIndexConfigError extends Error {
93
+ export declare class TableIndexConfigError extends Error {
93
94
  readonly collectionSlug: string;
94
95
  readonly position: number;
95
96
  constructor(collectionSlug: string, position: number, message: string);
@@ -129,7 +130,7 @@ export declare const isRebaseIndexName: (name: string) => boolean;
129
130
  * `v` is the only escape hatch, and it is expensive on purpose: bumping it
130
131
  * renames every index in the field.
131
132
  */
132
- export declare const indexFingerprint: (spec: Omit<CollectionIndexSpec, "indexName">) => string;
133
+ export declare const indexFingerprint: (spec: Omit<TableIndexSpec, "indexName">) => string;
133
134
  /**
134
135
  * `<table>_<columns>_ix_<hash>`, or `_ux_` when unique.
135
136
  *
@@ -140,7 +141,7 @@ export declare const indexFingerprint: (spec: Omit<CollectionIndexSpec, "indexNa
140
141
  * `_fkey` suffix truncated away, so a second foreign key on that table would
141
142
  * derive a byte-identical name.
142
143
  */
143
- export declare const deriveIndexName: (spec: Omit<CollectionIndexSpec, "indexName">) => string;
144
+ export declare const deriveIndexName: (spec: Omit<TableIndexSpec, "indexName">) => string;
144
145
  /** Render a resolved predicate as the body of a `WHERE` clause. */
145
146
  export declare const renderPredicate: (predicate: ResolvedPredicate) => string;
146
147
  /**
@@ -152,44 +153,22 @@ export declare const renderPredicate: (predicate: ResolvedPredicate) => string;
152
153
  * nothing for a UNIQUE index — the rendered text is `CREATE UNIQUE INDEX …`
153
154
  * and the pattern never matches.
154
155
  */
155
- export declare const collectionIndexStatement: (spec: CollectionIndexSpec, options?: {
156
+ export declare const tableIndexStatement: (spec: TableIndexSpec, options?: {
156
157
  concurrently?: boolean;
157
158
  ifNotExists?: boolean;
158
159
  }) => string;
159
- export declare const collectionIndexStatements: (specs: readonly CollectionIndexSpec[], options?: {
160
+ export declare const tableIndexStatements: (specs: readonly TableIndexSpec[], options?: {
160
161
  concurrently?: boolean;
161
162
  ifNotExists?: boolean;
162
163
  }) => string[];
163
164
  /**
164
- * The column a property key indexes.
165
- *
166
- * A `belongsTo` resolves to its `localKey` — `primaryCategory` becomes
167
- * `primary_category_id` — which is the case an index is most often wanted for
168
- * and the case where the property key and the column differ. Everything else
169
- * goes through `resolveColumnName`.
170
- *
171
- * The other relation kinds have no local column at all: the foreign key lives
172
- * on the target's table, or in a junction. Indexing them here is refused
173
- * rather than resolved to a column that does not exist.
174
- */
175
- export declare const resolveIndexableColumn: (collection: CollectionConfig, propKey: string, resolveColumnName: ResolveColumnName, fail: (message: string) => never) => string;
176
- /**
177
- * Every index one collection declares, resolved and named.
178
- *
179
- * Throws {@link CollectionIndexConfigError} rather than dropping a bad entry:
180
- * an index that silently does not exist is the failure mode this whole feature
181
- * is here to remove.
182
- */
183
- export declare const buildCollectionIndexSpecs: (collection: CollectionConfig, resolveColumnName: ResolveColumnName) => CollectionIndexSpec[];
184
- /**
185
- * Every declared index across a set of collections, in a stable order.
165
+ * Every index one table declares (`indexes`), resolved and named, read from
166
+ * its descriptor — what the planner calls, for a table and for a
167
+ * materialized view's stored rows alike.
186
168
  *
187
- * Sorted because the result reaches `schema.sql`, which `doctor` string-
188
- * compares against a regenerated copy — `generatePostgresDdl` does not sort its
189
- * collections, so leaving this in declaration order would make the artifact
190
- * depend on the order files happened to load in.
169
+ * Throws {@link TableIndexConfigError} rather than dropping a bad entry.
191
170
  */
192
- export declare const buildCollectionIndexPlan: (collections: readonly CollectionConfig[], resolveColumnName: ResolveColumnName) => CollectionIndexSpec[];
171
+ export declare const buildTableIndexSpecs: (table: TableDescriptor) => TableIndexSpec[];
193
172
  /**
194
173
  * The stable order every consumer of a set of index specs uses.
195
174
  *
@@ -198,7 +177,7 @@ export declare const buildCollectionIndexPlan: (collections: readonly Collection
198
177
  * exclude list and `schema.sql` do — a second sort written out beside this one
199
178
  * is a second order the moment either is edited.
200
179
  */
201
- export declare const sortIndexSpecs: (specs: readonly CollectionIndexSpec[]) => CollectionIndexSpec[];
180
+ export declare const sortIndexSpecs: (specs: readonly TableIndexSpec[]) => TableIndexSpec[];
202
181
  /**
203
182
  * The `reason` a derived foreign-key index carries. Never part of the name —
204
183
  * see {@link indexFingerprint} — so rewording it renames nothing.
@@ -214,7 +193,7 @@ export declare const FOREIGN_KEY_INDEX_REASON = "Derived for a foreign key: Post
214
193
  * has to reach every row. Nor does GIN or BRIN, which answer different
215
194
  * questions than "the rows whose key is one of these".
216
195
  */
217
- export declare const leadsWithColumn: (spec: Pick<CollectionIndexSpec, "method" | "predicate" | "keys">, column: string) => boolean;
196
+ export declare const leadsWithColumn: (spec: Pick<TableIndexSpec, "method" | "predicate" | "keys">, column: string) => boolean;
218
197
  /**
219
198
  * The btree a foreign-key column gets when nothing else already leads with it.
220
199
  *
@@ -233,4 +212,4 @@ export declare const leadsWithColumn: (spec: Pick<CollectionIndexSpec, "method"
233
212
  * derive. That identity is what makes the derived index and a declared one the
234
213
  * same object rather than two.
235
214
  */
236
- export declare const foreignKeyIndexSpec: (schema: string, table: string, column: string) => CollectionIndexSpec;
215
+ export declare const foreignKeyIndexSpec: (schema: string, table: string, column: string) => TableIndexSpec;
@@ -1,4 +1,10 @@
1
1
  import type { NodePgDatabase } from "drizzle-orm/node-postgres";
2
+ /**
3
+ * The schema the meta table lives in: the runtime's own, `rebase`, whatever
4
+ * schema the tables are in. Shared by the boot (through the bootstrapper),
5
+ * `rebase db push` and the doctor, so all three read and write one row.
6
+ */
7
+ export declare const SCHEMA_META_SCHEMA = "rebase";
2
8
  /**
3
9
  * Anything that can run SQL for us.
4
10
  *
@@ -18,7 +24,7 @@ export interface SchemaMetaQueryable {
18
24
  * `null` instead of a thrown 42P01 — the overwhelmingly common case on a fresh
19
25
  * database is that neither exists yet, and that is not news.
20
26
  */
21
- export declare function readCollectionsSchemaVersion(db: SchemaMetaQueryable | NodePgDatabase, metaSchema: string): Promise<string | null>;
27
+ export declare function readTablesSchemaVersion(db: SchemaMetaQueryable | NodePgDatabase, metaSchema: string): Promise<string | null>;
22
28
  /**
23
29
  * Record the version this runtime just applied.
24
30
  *
@@ -29,4 +35,4 @@ export declare function readCollectionsSchemaVersion(db: SchemaMetaQueryable | N
29
35
  * arranges; it is tolerated here for the same reason it is elsewhere in the boot
30
36
  * path, and the caller treats any failure as a warning rather than a fatal.
31
37
  */
32
- export declare function stampCollectionsSchemaVersion(db: SchemaMetaQueryable | NodePgDatabase, metaSchema: string, version: string): Promise<void>;
38
+ export declare function stampTablesSchemaVersion(db: SchemaMetaQueryable | NodePgDatabase, metaSchema: string, version: string): Promise<void>;
@@ -40,7 +40,25 @@
40
40
  * out: the objects leave `schema.sql`, Atlas is told to exclude them, and
41
41
  * Rebase applies them itself. See `generatePostgresVectorDdl`.
42
42
  */
43
- import type { CollectionConfig, Property, VectorDistance } from "@rebasepro/types";
43
+ import type { TableDescriptor } from "@rebasepro/types";
44
+ /**
45
+ * A pgvector distance as the index plan names it — one operator class each,
46
+ * spelled the way `vectorSearch`'s `distance` spells it.
47
+ */
48
+ export type VectorDistance = "cosine" | "l2" | "inner_product";
49
+ /** How one column's ANN index is built: what a column's `VectorIndexOptions` resolves to. */
50
+ export interface VectorIndexConfig {
51
+ /** `hnsw` (the default) or `ivfflat`. */
52
+ method?: "hnsw" | "ivfflat";
53
+ /** The distance(s) indexed, one index each; `cosine` by default. */
54
+ distance?: VectorDistance | VectorDistance[];
55
+ /** HNSW: connections per node. */
56
+ m?: number;
57
+ /** HNSW: candidate-list size while building. */
58
+ efConstruction?: number;
59
+ /** IVFFlat: number of partitions. */
60
+ lists?: number;
61
+ }
44
62
  /**
45
63
  * The widest `vector` pgvector will build an HNSW or IVFFlat index over.
46
64
  * Storage and exact search are unaffected by this limit.
@@ -76,21 +94,15 @@ export interface VectorIndexPlan {
76
94
  export declare class VectorIndexConfigError extends Error {
77
95
  constructor(message: string);
78
96
  }
79
- /**
80
- * Every ANN index a collection's vector properties call for.
81
- *
82
- * `resolveColumn` is passed in rather than imported so that this module stays
83
- * free of the DDL generator, which imports *it*. Both callers hand it the same
84
- * `resolveColumnName`, and a contract test asserts the names agree.
85
- */
86
- export declare const buildVectorIndexPlan: (collection: CollectionConfig, resolveColumn: (propName: string, prop?: Property | null) => string) => VectorIndexPlan;
97
+ /** Every ANN index a table's vector columns call for, read from its descriptor. */
98
+ export declare const buildTableVectorIndexPlan: (table: TableDescriptor) => VectorIndexPlan;
87
99
  /**
88
100
  * The `CREATE INDEX` for one spec.
89
101
  *
90
102
  * `CONCURRENTLY` is deliberately absent, for the same reason it is absent from
91
103
  * `searchIndexStatements`: this form is replayed as part of a migration, where
92
104
  * a concurrent build is not allowed. The boot-time ensure rewrites it — see
93
- * `ensureCollectionTables`.
105
+ * `ensureTables`.
94
106
  */
95
107
  export declare const vectorIndexStatement: (spec: VectorIndexSpec) => string;
96
108
  /** Every statement for a plan, in a stable order. */
@@ -162,14 +174,8 @@ export interface VectorColumnSpec {
162
174
  /** Rendered after the type, in the generator's order: UNIQUE then NOT NULL. */
163
175
  modifiers: string;
164
176
  }
165
- /**
166
- * Every vector column a collection declares.
167
- *
168
- * Wider than {@link buildVectorIndexPlan} on purpose: that one answers "what
169
- * gets an ANN index", and skips both a property with `index: false` and one too
170
- * wide to index. Either still needs its column.
171
- */
172
- export declare const buildVectorColumnSpecs: (collection: CollectionConfig, resolveColumn: (propName: string, prop?: Property | null) => string) => VectorColumnSpec[];
177
+ /** Every vector column a table declares, read from its descriptor. */
178
+ export declare const buildTableVectorColumnSpecs: (table: TableDescriptor) => VectorColumnSpec[];
173
179
  /** The column type — the one place `VECTOR(n)` is spelled. */
174
180
  export declare const vectorColumnType: (spec: Pick<VectorColumnSpec, "dimensions">) => string;
175
181
  /** The column definition as it appears inside `CREATE TABLE`. */
@@ -196,13 +202,3 @@ export declare const vectorColumnDefinition: (spec: VectorColumnSpec) => string;
196
202
  * column was declared as a bare `vector`, which is drift in the same sense.
197
203
  */
198
204
  export declare const vectorDimensionGuard: (spec: VectorColumnSpec) => string;
199
- /**
200
- * The object names a collection's vector properties own, unqualified.
201
- *
202
- * What Atlas has to be told to exclude. Only the column and the ANN indexes: a
203
- * `UNIQUE` or `NOT NULL` on the column is a property *of* the column, and
204
- * excluding the column takes them with it — measured against Atlas 1.2.3 and
205
- * 1.3.2, where a target carrying `vector(3) NOT NULL UNIQUE` and a `schema.sql`
206
- * carrying neither reported "Schema is synced, no changes to be made".
207
- */
208
- export declare const vectorObjectNames: (collection: CollectionConfig, resolveColumn: (propName: string, prop?: Property | null) => string) => string[];