@rebasepro/server-postgres 0.30.1 → 0.31.0-canary.g902a0ce
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.
- package/README.md +11 -8
- package/dist/{BranchService-CrXvcES2.js → BranchService-USp1AvZB.js} +3 -3
- package/dist/{BranchService-CrXvcES2.js.map → BranchService-USp1AvZB.js.map} +1 -1
- package/dist/PostgresBackendDriver.d.ts +99 -54
- package/dist/PostgresBootstrapper.d.ts +12 -27
- package/dist/auth/ensure-tables.d.ts +16 -5
- package/dist/auth/schema-version.d.ts +2 -2
- package/dist/auth/services.d.ts +2 -3
- package/dist/{auth-users-columns-C72EMoDJ.js → auth-users-columns-BpfgbkxZ.js} +2 -16
- package/dist/auth-users-columns-BpfgbkxZ.js.map +1 -0
- package/dist/{backup-cli-CTKCOLpX.js → backup-cli-DbKyEj6c.js} +4 -4
- package/dist/{backup-cli-CTKCOLpX.js.map → backup-cli-DbKyEj6c.js.map} +1 -1
- package/dist/{boot-ddl-CqGIwSYx.js → boot-ddl-5H2bL_80.js} +2 -2
- package/dist/{boot-ddl-CqGIwSYx.js.map → boot-ddl-5H2bL_80.js.map} +1 -1
- package/dist/{cli-console-DBPw-oAz.js → cli-console-DsRgGSBR.js} +65 -39
- package/dist/cli-console-DsRgGSBR.js.map +1 -0
- package/dist/cli-console.d.ts +16 -13
- package/dist/cli-flags.d.ts +8 -9
- package/dist/cli-helpers.d.ts +15 -11
- package/dist/{cli-errors-DYTxnLbW.js → cli-schema-dir-CiN0ephV.js} +184 -70
- package/dist/cli-schema-dir-CiN0ephV.js.map +1 -0
- package/dist/cli-schema-dir.d.ts +64 -0
- package/dist/cli.js +192 -257
- package/dist/cli.js.map +1 -1
- package/dist/data-transformer.d.ts +50 -19
- package/dist/{database-preflight-iBpT7-vv.js → database-preflight-bfnIBnjM.js} +5 -5
- package/dist/database-preflight-bfnIBnjM.js.map +1 -0
- package/dist/{deferred-index-build-BCU9RoHK.js → deferred-index-build-CcSDA7wE.js} +69 -13
- package/dist/deferred-index-build-CcSDA7wE.js.map +1 -0
- package/dist/{ensure-collection-policies-Bo-_fDAy.js → ensure-policies-rRmXb5bt.js} +31 -31
- package/dist/ensure-policies-rRmXb5bt.js.map +1 -0
- package/dist/{ensure-collection-tables-DCJINkT_.js → ensure-tables-Bvm-F2wW.js} +44 -37
- package/dist/ensure-tables-Bvm-F2wW.js.map +1 -0
- package/dist/{ensure-tables-BPGaGh0y.js → ensure-tables-CC8p_AK3.js} +34 -29
- package/dist/ensure-tables-CC8p_AK3.js.map +1 -0
- package/dist/{enum-labels-kept-YAgOZS4I.js → enum-labels-kept-FlX9SHdf.js} +8 -8
- package/dist/enum-labels-kept-FlX9SHdf.js.map +1 -0
- package/dist/{generate-drizzle-schema-DcrFr7YX.js → generate-drizzle-schema-SJMXxzPI.js} +12 -12
- package/dist/generate-drizzle-schema-SJMXxzPI.js.map +1 -0
- package/dist/{generate-drizzle-schema-logic-LTLZvt6r.js → generate-drizzle-schema-logic-DL7R1rAF.js} +15 -8
- package/dist/generate-drizzle-schema-logic-DL7R1rAF.js.map +1 -0
- package/dist/{generate-files-CsaVzatS.js → generate-files-tlJ9_lGI.js} +23 -30
- package/dist/generate-files-tlJ9_lGI.js.map +1 -0
- package/dist/{generate-next-step-DgK5BlBn.js → generate-next-step-CO09dovd.js} +3 -3
- package/dist/generate-next-step-CO09dovd.js.map +1 -0
- package/dist/{generate-postgres-ddl-logic-Dg0bcENZ.js → generate-postgres-ddl-logic-B8huc03c.js} +51 -21
- package/dist/generate-postgres-ddl-logic-B8huc03c.js.map +1 -0
- package/dist/{generated-schema-diff-By4dxyTH.js → generated-schema-diff-DoT2dYDe.js} +297 -279
- package/dist/generated-schema-diff-DoT2dYDe.js.map +1 -0
- package/dist/{generated-schema-staleness-BvNF3i-s.js → generated-schema-staleness-YBVq2kTn.js} +21 -29
- package/dist/generated-schema-staleness-YBVq2kTn.js.map +1 -0
- package/dist/history/ensure-history-table.d.ts +22 -0
- package/dist/index.d.ts +8 -2
- package/dist/index.es.js +201 -25
- package/dist/index.es.js.map +1 -1
- package/dist/interfaces.d.ts +3 -4
- package/dist/{introspect-db-queries-DevUrzll.js → introspect-db-queries-BgiRQqtR.js} +7 -2
- package/dist/introspect-db-queries-BgiRQqtR.js.map +1 -0
- package/dist/introspect-tables-Cw_A-kk4.js +2086 -0
- package/dist/introspect-tables-Cw_A-kk4.js.map +1 -0
- package/dist/load-tables-B1Re74ng.js +92 -0
- package/dist/load-tables-B1Re74ng.js.map +1 -0
- package/dist/{migrate-baseline-CmWXL7qx.js → migrate-baseline-DZmekgpD.js} +19 -32
- package/dist/migrate-baseline-DZmekgpD.js.map +1 -0
- package/dist/{migrate-policy-stamps-BN_Qad6c.js → migrate-policy-stamps-B_acrUQB.js} +18 -19
- package/dist/migrate-policy-stamps-B_acrUQB.js.map +1 -0
- package/dist/model/PostgresTableRegistry.d.ts +159 -0
- package/dist/model/build-registry.d.ts +25 -0
- package/dist/model/refresh-relational-schema.d.ts +24 -0
- package/dist/model/runtime-table.d.ts +53 -0
- package/dist/{collections → model}/validate-relations.d.ts +15 -21
- package/dist/{open-rebase-40paQfVW.js → open-rebase-4kisUF_k.js} +3946 -3870
- package/dist/open-rebase-4kisUF_k.js.map +1 -0
- package/dist/open-rebase.d.ts +16 -15
- package/dist/{pg-error-utils-DJHjCF7-.js → pg-error-utils-BT5NzGFZ.js} +17 -20
- package/dist/pg-error-utils-BT5NzGFZ.js.map +1 -0
- package/dist/plan-schema-Hbtjhge3.js +1633 -0
- package/dist/plan-schema-Hbtjhge3.js.map +1 -0
- package/dist/{policy-drift-C-m0uWHH.js → policy-drift-BVMyqHSa.js} +29 -29
- package/dist/policy-drift-BVMyqHSa.js.map +1 -0
- package/dist/{push-index-adoption-Cp7oZxSl.js → push-index-adoption-hpHTyXMR.js} +7 -7
- package/dist/push-index-adoption-hpHTyXMR.js.map +1 -0
- package/dist/{push-index-prebuild-DbwKGtQT.js → push-index-prebuild-Bty9F7bD.js} +6 -6
- package/dist/push-index-prebuild-Bty9F7bD.js.map +1 -0
- package/dist/{push-kept-defaults-CLcgsEPt.js → push-kept-defaults-Bst4MDup.js} +13 -16
- package/dist/push-kept-defaults-Bst4MDup.js.map +1 -0
- package/dist/{push-legacy-renames-BthD0E9W.js → push-legacy-renames-bB4bM6br.js} +6 -6
- package/dist/push-legacy-renames-bB4bM6br.js.map +1 -0
- package/dist/{push-policy-plan-BgcrroxQ.js → push-policy-plan-BI8U4BOD.js} +11 -11
- package/dist/push-policy-plan-BI8U4BOD.js.map +1 -0
- package/dist/{render-ddl-Ci3S_SoI.js → render-ddl-D4n86NHz.js} +14 -7
- package/dist/render-ddl-D4n86NHz.js.map +1 -0
- package/dist/{request-role-cli-Dy1EgJU9.js → request-role-cli-BdRzdE87.js} +11 -11
- package/dist/{request-role-cli-Dy1EgJU9.js.map → request-role-cli-BdRzdE87.js.map} +1 -1
- package/dist/{request-role-migration-GHTJnPMV.js → request-role-migration-C8aq_TO3.js} +2 -2
- package/dist/{request-role-migration-GHTJnPMV.js.map → request-role-migration-C8aq_TO3.js.map} +1 -1
- package/dist/{rls-enforcement-Cc_UhOxb.js → rls-enforcement-DB5HHj96.js} +19 -19
- package/dist/rls-enforcement-DB5HHj96.js.map +1 -0
- package/dist/{rls-settings-BCGMIig3.js → rls-settings-CmGK2U0a.js} +2 -2
- package/dist/rls-settings-CmGK2U0a.js.map +1 -0
- package/dist/schema/auth-users-columns.d.ts +1 -11
- package/dist/schema/catalogue-schema.d.ts +33 -29
- package/dist/schema/classify-change.d.ts +23 -16
- package/dist/schema/column-type-drift.d.ts +16 -0
- package/dist/schema/config-relations.d.ts +10 -9
- package/dist/schema/deferred-index-build.d.ts +1 -1
- package/dist/schema/doctor-cli.js +1544 -66
- package/dist/schema/doctor-cli.js.map +1 -1
- package/dist/schema/doctor-database.d.ts +7 -7
- package/dist/schema/doctor-policy-checks.d.ts +4 -4
- package/dist/schema/doctor-search-scale.d.ts +14 -14
- package/dist/schema/doctor.d.ts +27 -27
- package/dist/schema/dynamic-tables.d.ts +6 -5
- package/dist/schema/{ensure-collection-policies.d.ts → ensure-policies.d.ts} +20 -20
- package/dist/schema/{ensure-collection-tables.d.ts → ensure-tables.d.ts} +11 -11
- package/dist/schema/enum-labels-kept.d.ts +6 -6
- package/dist/schema/generate-drizzle-schema-logic.d.ts +3 -3
- package/dist/schema/generate-drizzle-schema.js +1 -1
- package/dist/schema/generate-files.d.ts +6 -6
- package/dist/schema/generate-postgres-ddl-logic.d.ts +23 -20
- package/dist/schema/generate-postgres-ddl.js +11 -11
- package/dist/schema/generate-postgres-ddl.js.map +1 -1
- package/dist/schema/generate-schema-commit.d.ts +13 -8
- package/dist/schema/generated-schema-diff.d.ts +16 -16
- package/dist/schema/generated-schema-staleness.d.ts +11 -11
- package/dist/schema/index-adoption.d.ts +4 -4
- package/dist/schema/introspect-db-customization.d.ts +47 -0
- package/dist/schema/introspect-db-inference.d.ts +30 -9
- package/dist/schema/introspect-db-logic.d.ts +79 -110
- package/dist/schema/introspect-db-project.d.ts +15 -18
- package/dist/schema/introspect-db-queries.d.ts +1 -1
- package/dist/schema/introspect-db-search.d.ts +25 -4
- package/dist/schema/introspect-db-storage.d.ts +4 -74
- package/dist/schema/introspect-db.js +102 -90
- package/dist/schema/introspect-db.js.map +1 -1
- package/dist/schema/introspect-runtime.d.ts +47 -36
- package/dist/schema/introspect-tables.d.ts +182 -0
- package/dist/schema/load-tables.d.ts +55 -0
- package/dist/schema/migrate-policy-stamps.d.ts +4 -4
- package/dist/schema/migration-freshness.d.ts +13 -13
- package/dist/schema/plan/column-order.d.ts +82 -0
- package/dist/schema/plan/diff-plan.d.ts +9 -3
- package/dist/schema/plan/plan-schema.d.ts +55 -52
- package/dist/schema/plan/render-drizzle.d.ts +1 -1
- package/dist/schema/plan/types.d.ts +24 -15
- package/dist/schema/push-index-adoption.d.ts +3 -3
- package/dist/schema/push-index-prebuild.d.ts +3 -3
- package/dist/schema/push-kept-defaults.d.ts +7 -7
- package/dist/schema/push-legacy-renames.d.ts +3 -3
- package/dist/schema/push-policy-plan.d.ts +5 -5
- package/dist/schema/reconcile-schema.d.ts +5 -5
- package/dist/schema/relation-names.d.ts +15 -20
- package/dist/schema/render-outputs.d.ts +76 -0
- package/dist/schema/search-column.d.ts +11 -43
- package/dist/schema/{collection-index.d.ts → table-index.d.ts} +21 -42
- package/dist/schema/{collections-schema-version.d.ts → tables-schema-version.d.ts} +8 -2
- package/dist/schema/vector-index.d.ts +24 -28
- package/dist/{search-column-BM-GV6vH.js → search-column-BO-WND-B.js} +86 -149
- package/dist/search-column-BO-WND-B.js.map +1 -0
- package/dist/security/caller-sql-columns.d.ts +9 -6
- package/dist/security/policy-drift.d.ts +14 -14
- package/dist/security/rls-enforcement.d.ts +19 -25
- package/dist/security/rls-settings.d.ts +2 -2
- package/dist/security/served-table-protection.d.ts +125 -0
- package/dist/services/FetchService.d.ts +22 -133
- package/dist/services/PersistService.d.ts +6 -17
- package/dist/services/RelationService.d.ts +57 -106
- package/dist/services/RelationWriteService.d.ts +59 -66
- package/dist/services/cdc/identity-columns.d.ts +7 -5
- package/dist/services/cdc/junction-tables.d.ts +14 -14
- package/dist/services/collection-helpers.d.ts +52 -95
- package/dist/services/dataService.d.ts +15 -12
- package/dist/services/field-op-sql.d.ts +11 -9
- package/dist/services/field-viewer.d.ts +12 -11
- package/dist/services/hidden-columns.d.ts +30 -0
- package/dist/services/index.d.ts +1 -1
- package/dist/services/junction-writes.d.ts +37 -18
- package/dist/services/nested-path.d.ts +18 -18
- package/dist/services/read-field-access.d.ts +23 -7
- package/dist/services/read-scope.d.ts +10 -9
- package/dist/services/realtimeService.d.ts +25 -10
- package/dist/services/relation-tables.d.ts +97 -0
- package/dist/services/row-pipeline.d.ts +50 -69
- package/dist/services/soft-delete.d.ts +25 -24
- package/dist/services/table-hooks.d.ts +146 -0
- package/dist/services/view-access.d.ts +7 -7
- package/dist/services/write-transaction-scope.d.ts +1 -1
- package/dist/{source-fZb92pN8.js → source-VxbrQojV.js} +111 -79
- package/dist/source-VxbrQojV.js.map +1 -0
- package/dist/{collections-schema-version-D7bDI0PJ.js → tables-schema-version-YvZIBlOP.js} +12 -6
- package/dist/tables-schema-version-YvZIBlOP.js.map +1 -0
- package/dist/utils/drizzle-conditions.d.ts +70 -84
- package/dist/utils/pg-array-null-patch.d.ts +27 -10
- package/dist/utils/pg-error-utils.d.ts +4 -4
- package/dist/{vector-index-DsQ3V2d2.js → vector-index-VSh3ufTd.js} +62 -54
- package/dist/vector-index-VSh3ufTd.js.map +1 -0
- package/dist/{websocket-B7ex6AQM.js → websocket-BevXvwfo.js} +51 -40
- package/dist/websocket-BevXvwfo.js.map +1 -0
- package/dist/websocket.d.ts +2 -2
- package/package.json +7 -7
- package/dist/auth-users-columns-C72EMoDJ.js.map +0 -1
- package/dist/cli-collections-path.d.ts +0 -31
- package/dist/cli-console-DBPw-oAz.js.map +0 -1
- package/dist/cli-errors-DYTxnLbW.js.map +0 -1
- package/dist/collections/PostgresCollectionRegistry.d.ts +0 -47
- package/dist/collections/buildRegistry.d.ts +0 -27
- package/dist/collections-schema-version-D7bDI0PJ.js.map +0 -1
- package/dist/column-plan-helpers-BeSztMor.js +0 -161
- package/dist/column-plan-helpers-BeSztMor.js.map +0 -1
- package/dist/database-preflight-iBpT7-vv.js.map +0 -1
- package/dist/deferred-index-build-BCU9RoHK.js.map +0 -1
- package/dist/doctor-Kg1oUK0Q.js +0 -1458
- package/dist/doctor-Kg1oUK0Q.js.map +0 -1
- package/dist/ensure-collection-policies-Bo-_fDAy.js.map +0 -1
- package/dist/ensure-collection-tables-DCJINkT_.js.map +0 -1
- package/dist/ensure-tables-BPGaGh0y.js.map +0 -1
- package/dist/enum-labels-kept-YAgOZS4I.js.map +0 -1
- package/dist/generate-drizzle-schema-DcrFr7YX.js.map +0 -1
- package/dist/generate-drizzle-schema-logic-LTLZvt6r.js.map +0 -1
- package/dist/generate-files-CsaVzatS.js.map +0 -1
- package/dist/generate-next-step-DgK5BlBn.js.map +0 -1
- package/dist/generate-postgres-ddl-logic-Dg0bcENZ.js.map +0 -1
- package/dist/generated-schema-diff-By4dxyTH.js.map +0 -1
- package/dist/generated-schema-staleness-BvNF3i-s.js.map +0 -1
- package/dist/introspect-db-logic-DWqAEURB.js +0 -2047
- package/dist/introspect-db-logic-DWqAEURB.js.map +0 -1
- package/dist/introspect-db-queries-DevUrzll.js.map +0 -1
- package/dist/migrate-baseline-CmWXL7qx.js.map +0 -1
- package/dist/migrate-policy-stamps-BN_Qad6c.js.map +0 -1
- package/dist/open-rebase-40paQfVW.js.map +0 -1
- package/dist/pg-error-utils-DJHjCF7-.js.map +0 -1
- package/dist/plan-schema-vJd3UEmT.js +0 -1604
- package/dist/plan-schema-vJd3UEmT.js.map +0 -1
- package/dist/policy-drift-C-m0uWHH.js.map +0 -1
- package/dist/push-index-adoption-Cp7oZxSl.js.map +0 -1
- package/dist/push-index-prebuild-DbwKGtQT.js.map +0 -1
- package/dist/push-kept-defaults-CLcgsEPt.js.map +0 -1
- package/dist/push-legacy-renames-BthD0E9W.js.map +0 -1
- package/dist/push-policy-plan-BgcrroxQ.js.map +0 -1
- package/dist/render-ddl-Ci3S_SoI.js.map +0 -1
- package/dist/rls-enforcement-Cc_UhOxb.js.map +0 -1
- package/dist/rls-settings-BCGMIig3.js.map +0 -1
- package/dist/schema/column-plan-helpers.d.ts +0 -161
- package/dist/schema/introspect-db-naming.d.ts +0 -10
- package/dist/search-column-BM-GV6vH.js.map +0 -1
- package/dist/source-fZb92pN8.js.map +0 -1
- package/dist/vector-index-DsQ3V2d2.js.map +0 -1
- package/dist/websocket-B7ex6AQM.js.map +0 -1
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* What a
|
|
2
|
+
* What a table change means for a live database.
|
|
3
3
|
*
|
|
4
4
|
* The live schema editor may only make changes the boot-time ensure path can
|
|
5
5
|
* actually carry out, because that is the one mechanism that changes a schema
|
|
6
|
-
* (see `ensure-
|
|
6
|
+
* (see `ensure-tables.ts`). Its vocabulary is small and deliberately
|
|
7
7
|
* so: create a table, add a column, create an enum *type*, create an index, add
|
|
8
8
|
* a foreign key, and rename a column via the legacy-name path. There is no
|
|
9
9
|
* `ALTER COLUMN TYPE` and no `DROP` of anything.
|
|
@@ -18,10 +18,10 @@
|
|
|
18
18
|
* a database that does not match the configuration and says nothing about it.
|
|
19
19
|
* Two of those exist today and both are documented in the code they come from:
|
|
20
20
|
*
|
|
21
|
-
* - **A required
|
|
21
|
+
* - **A required column added to an existing table.** `ensure` withholds
|
|
22
22
|
* `NOT NULL` on a table that already exists, because the constraint is checked
|
|
23
|
-
* against live rows. The column arrives nullable. The
|
|
24
|
-
* the database does not enforce it.
|
|
23
|
+
* against live rows. The column arrives nullable. The definition says
|
|
24
|
+
* NOT NULL; the database does not enforce it.
|
|
25
25
|
* - **A value added to an existing enum.** `ensure` skips an enum type it
|
|
26
26
|
* already sees — `if (existing.enums.has(name)) continue`. The new value never
|
|
27
27
|
* reaches the database, and the first insert using it fails.
|
|
@@ -30,11 +30,11 @@
|
|
|
30
30
|
* `diverges` is the whole point of this module: an editor that reports them as
|
|
31
31
|
* safe is worse than one that refuses them.
|
|
32
32
|
*
|
|
33
|
-
* ## Read from the plan, not from the
|
|
33
|
+
* ## Read from the plan, not from the definitions
|
|
34
34
|
*
|
|
35
35
|
* Whether an edit changes the database is decided by comparing what
|
|
36
|
-
* `planSchema` — the one reading of a
|
|
37
|
-
* of the
|
|
36
|
+
* `planSchema` — the one reading of a table every emitter renders — makes
|
|
37
|
+
* of the tables before and after it: each table's columns, their types,
|
|
38
38
|
* nullability, defaults, uniqueness and foreign keys, the junction tables,
|
|
39
39
|
* indexes and triggers. It used to be decided by a hand-picked list of property
|
|
40
40
|
* fields, which knew nothing of `validation.integer`, of a string becoming an
|
|
@@ -44,8 +44,10 @@
|
|
|
44
44
|
* of edit either changes the plan, and is classified here from the difference,
|
|
45
45
|
* or it does not change the database.
|
|
46
46
|
*
|
|
47
|
-
* The
|
|
48
|
-
*
|
|
47
|
+
* The field-level reading is still here, for the parts only it can name: a
|
|
48
|
+
* column or relation added or removed, NOT NULL, an enum's values, a key
|
|
49
|
+
* renamed. A field is what the definition names: a column by its key, a
|
|
50
|
+
* relation by its name (a `belongsTo` owns its foreign-key column).
|
|
49
51
|
*
|
|
50
52
|
* ## Why refusing is the right default for the rest
|
|
51
53
|
*
|
|
@@ -54,7 +56,7 @@
|
|
|
54
56
|
* somebody wrote and read. `needs-migration` says exactly that, and naming the
|
|
55
57
|
* change is more useful than attempting it.
|
|
56
58
|
*/
|
|
57
|
-
import {
|
|
59
|
+
import type { CompiledTable, SchemaChange, SchemaChangeKind, SchemaChangeVerdict, ClassifiedSchemaChanges } from "@rebasepro/types";
|
|
58
60
|
/**
|
|
59
61
|
* The vocabulary lives in `@rebasepro/types` so that `@rebasepro/server`, which
|
|
60
62
|
* cannot import this package, can still describe a change. Re-exported here
|
|
@@ -67,7 +69,7 @@ export type ClassifiedChanges = ClassifiedSchemaChanges;
|
|
|
67
69
|
/**
|
|
68
70
|
* Facts about the database a change is destined for.
|
|
69
71
|
*
|
|
70
|
-
* Three of the verdicts below cannot be reached from the
|
|
72
|
+
* Three of the verdicts below cannot be reached from the tables alone:
|
|
71
73
|
* whether a NOT NULL can be added comes down to whether the table holds rows,
|
|
72
74
|
* and whether an enum value will land comes down to which values the type
|
|
73
75
|
* already has. Without these, the classifier answers conservatively — the
|
|
@@ -89,22 +91,27 @@ export interface SchemaFacts {
|
|
|
89
91
|
columnDefaults?: Set<string>;
|
|
90
92
|
}
|
|
91
93
|
/**
|
|
92
|
-
*
|
|
94
|
+
* The classification of a proposal that could not be compiled at all: the
|
|
95
|
+
* compiler's message is what says what to fix.
|
|
96
|
+
*/
|
|
97
|
+
export declare function uncompilableChanges(error: Error, slug: string): ClassifiedChanges;
|
|
98
|
+
/**
|
|
99
|
+
* Classify the difference between two sets of tables.
|
|
93
100
|
*
|
|
94
101
|
* `before` is what the running database was built from; `after` is what the
|
|
95
102
|
* editor is proposing. Order within each array is irrelevant.
|
|
96
103
|
*
|
|
97
104
|
* `facts` is what the database actually looks like. Supplied by the live
|
|
98
|
-
* editor; omitted by callers reasoning about
|
|
105
|
+
* editor; omitted by callers reasoning about tables in the abstract, who
|
|
99
106
|
* get the conservative reading.
|
|
100
107
|
*/
|
|
101
|
-
export declare function
|
|
108
|
+
export declare function classifyTableChanges(before: readonly CompiledTable[], after: readonly CompiledTable[], facts?: SchemaFacts): ClassifiedChanges;
|
|
102
109
|
/**
|
|
103
110
|
* The statements a default change needs that the additive ensure does not
|
|
104
111
|
* plan: it sets a DEFAULT only on a column that has none, and never changes or
|
|
105
112
|
* drops one. Both are metadata-only — a DEFAULT binds future writes and touches
|
|
106
113
|
* no row — so a reviewed change may make them.
|
|
107
114
|
*/
|
|
108
|
-
export declare function defaultChangeStatements(before:
|
|
115
|
+
export declare function defaultChangeStatements(before: readonly CompiledTable[], after: readonly CompiledTable[], existingTables: Map<string, Set<string>>): string[];
|
|
109
116
|
/** A one-line summary, for a log or a refusal message. */
|
|
110
117
|
export declare function summarizeChanges(classified: ClassifiedChanges): string;
|
|
@@ -69,6 +69,22 @@ export declare function typeFamily(raw: string | undefined | null): string | nul
|
|
|
69
69
|
* unknown type is the absence of it.
|
|
70
70
|
*/
|
|
71
71
|
export declare function typesAgree(declared: string, actual: string): boolean;
|
|
72
|
+
/**
|
|
73
|
+
* A type as `format_type` would print it, for comparing a `col.custom()`
|
|
74
|
+
* declaration with the catalogue: lower-case outside quotes, no space after a
|
|
75
|
+
* comma or inside a modifier list, `timestamp` as `timestamp without time
|
|
76
|
+
* zone` and the other common aliases spelled out, a `public.` qualifier
|
|
77
|
+
* dropped (`format_type` prints a type on the search path bare).
|
|
78
|
+
*/
|
|
79
|
+
export declare function normalizeFormatType(raw: string): string;
|
|
80
|
+
/**
|
|
81
|
+
* Whether a `col.custom()` type and the type the catalogue holds
|
|
82
|
+
* (`format_type(atttypid, atttypmod)`) are the same type, as
|
|
83
|
+
* {@link normalizeFormatType} spells both. A custom type is identified by its
|
|
84
|
+
* name, so unlike {@link typesAgree} there is no family to fall back on: two
|
|
85
|
+
* names that differ are two types.
|
|
86
|
+
*/
|
|
87
|
+
export declare function customTypesAgree(declared: string, formatted: string): boolean;
|
|
72
88
|
/**
|
|
73
89
|
* The sentence a boot log says about one drifted column.
|
|
74
90
|
*
|
|
@@ -1,32 +1,33 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Build drizzle `relations()` for declared
|
|
2
|
+
* Build drizzle `relations()` for declared tables, from their descriptors.
|
|
3
3
|
*
|
|
4
4
|
* The heuristic builder in `dynamic-tables.ts` names a relation after the
|
|
5
5
|
* foreign-key column (`author_id` → `author`), which is the only evidence a
|
|
6
6
|
* database offers and is right for BaaS mode. It is wrong for a project that
|
|
7
|
-
* declares its
|
|
7
|
+
* declares its tables: there the relation's name is whatever the author
|
|
8
8
|
* called it, `include=writer` addresses that name, and a relation whose key was
|
|
9
9
|
* guessed from the column simply does not answer to it — the read returns the
|
|
10
10
|
* bare foreign key and no target, silently, which is how a demo lost every
|
|
11
11
|
* relation in its list view while the detail view (a different code path) kept
|
|
12
12
|
* working.
|
|
13
13
|
*
|
|
14
|
-
* So when there are
|
|
14
|
+
* So when there are declared tables, they are the authority for *which* relations
|
|
15
15
|
* exist and what they are called; the live catalogue is the authority for the
|
|
16
16
|
* columns underneath. This is the same pairing `generate-drizzle-schema-logic`
|
|
17
17
|
* emits into `schema.generated.ts` — kind for kind, key for key, and paired by
|
|
18
|
-
* the same {@link
|
|
18
|
+
* the same {@link tableRelationName} — only built against tables read back from
|
|
19
19
|
* `information_schema` rather than against a file.
|
|
20
20
|
*/
|
|
21
21
|
import { type Relations } from "drizzle-orm";
|
|
22
22
|
import type { PgTable } from "drizzle-orm/pg-core";
|
|
23
|
-
import {
|
|
24
|
-
/** A
|
|
23
|
+
import type { TableDescriptor } from "@rebasepro/types";
|
|
24
|
+
/** A table's name with any schema prefix stripped — as the DDL creates it. */
|
|
25
25
|
export declare function bareTableName(name: string): string;
|
|
26
26
|
/**
|
|
27
|
-
* Drizzle relations for every declared
|
|
27
|
+
* Drizzle relations for every declared table, keyed `<table>Relations`.
|
|
28
28
|
*
|
|
29
|
-
* @param
|
|
29
|
+
* @param descriptors every declared table backed by a table in `tables`, and
|
|
30
|
+
* the targets of their relations
|
|
30
31
|
* @param tables catalogue-built tables, keyed by bare table name
|
|
31
32
|
*/
|
|
32
|
-
export declare function
|
|
33
|
+
export declare function buildDrizzleRelationsFromTables(descriptors: readonly TableDescriptor[], tables: Record<string, PgTable>): Record<string, Relations>;
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
* on the first boot after an upgrade that adds one to every `belongsTo` in the
|
|
13
13
|
* project, that is every large table at once. So these are planned apart
|
|
14
14
|
* (`DeferredIndexBuild`) and built here, after the boot, one at a time. A
|
|
15
|
-
* UNIQUE one is the exception: `
|
|
15
|
+
* UNIQUE one is the exception: `ensureTables` builds it here too, but
|
|
16
16
|
* before it returns.
|
|
17
17
|
*
|
|
18
18
|
* ## The build
|