@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,13 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Do the migration files still describe the
|
|
2
|
+
* Do the migration files still describe the declared tables?
|
|
3
3
|
*
|
|
4
4
|
* `rebase db generate` asks Atlas, which needs a dev database to replay the
|
|
5
5
|
* migrations into — seconds of Docker, or the managed PGlite, before it can say
|
|
6
|
-
* a word. `rebase verify` runs after every edit an agent makes to a
|
|
6
|
+
* a word. `rebase verify` runs after every edit an agent makes to a table
|
|
7
7
|
* file and in CI, where neither is acceptable, so this answers the narrower
|
|
8
8
|
* question offline: replay the `CREATE TABLE` / `ALTER TABLE` / `DROP TABLE`
|
|
9
9
|
* statements the migrations contain, and compare the tables and columns that
|
|
10
|
-
* leaves with the ones the schema plan derives from the
|
|
10
|
+
* leaves with the ones the schema plan derives from the tables.
|
|
11
11
|
*
|
|
12
12
|
* Deliberately tables and columns only. A changed type or default is a real
|
|
13
13
|
* drift too, but reading it back out of Atlas's SQL means parsing every type
|
|
@@ -16,23 +16,23 @@
|
|
|
16
16
|
* that breaks a deploy — the runtime queries a column the migrated database
|
|
17
17
|
* does not have — and it is unambiguous in the text.
|
|
18
18
|
*
|
|
19
|
-
* Policies are not compared: the runtime applies a
|
|
19
|
+
* Policies are not compared: the runtime applies a table's policies at
|
|
20
20
|
* boot whether or not a migration carries them.
|
|
21
21
|
*/
|
|
22
|
-
import type {
|
|
23
|
-
/** One difference between the
|
|
22
|
+
import type { CompiledTable } from "@rebasepro/types";
|
|
23
|
+
/** One difference between the declared tables and what the migrations build. */
|
|
24
24
|
export interface UnmigratedChange {
|
|
25
25
|
/**
|
|
26
|
-
* - `missing-table` / `missing-column` — the
|
|
26
|
+
* - `missing-table` / `missing-column` — the tables declare it and no
|
|
27
27
|
* migration creates it.
|
|
28
|
-
* - `removed-column` — a migration creates it, the
|
|
28
|
+
* - `removed-column` — a migration creates it, the table no longer
|
|
29
29
|
* declares it, and no later migration drops it.
|
|
30
30
|
*/
|
|
31
31
|
kind: "missing-table" | "missing-column" | "removed-column";
|
|
32
32
|
/** `schema.table`. */
|
|
33
33
|
table: string;
|
|
34
34
|
column?: string;
|
|
35
|
-
/** The
|
|
35
|
+
/** The slug of the declared table, when one declares it (a junction has none). */
|
|
36
36
|
slug?: string;
|
|
37
37
|
}
|
|
38
38
|
/** A table as the migrations leave it. */
|
|
@@ -44,7 +44,7 @@ interface MigratedTable {
|
|
|
44
44
|
* `IF NOT EXISTS`. The search, vector and trigger DDL `db generate` appends
|
|
45
45
|
* after Atlas's half always says `IF NOT EXISTS`, and the planner keeps
|
|
46
46
|
* those columns out of `TablePlan.columns` — so only these are candidates
|
|
47
|
-
* for "removed from the
|
|
47
|
+
* for "removed from the table".
|
|
48
48
|
*/
|
|
49
49
|
managed: Set<string>;
|
|
50
50
|
}
|
|
@@ -55,8 +55,8 @@ interface MigratedTable {
|
|
|
55
55
|
*/
|
|
56
56
|
export declare function replayMigrationTables(migrations: readonly string[]): Map<string, MigratedTable>;
|
|
57
57
|
/**
|
|
58
|
-
* What the
|
|
59
|
-
* migrations still build that the
|
|
58
|
+
* What the tables declare that the migrations do not build, and what the
|
|
59
|
+
* migrations still build that the tables dropped.
|
|
60
60
|
*
|
|
61
61
|
* `migrations` are the contents of every `.sql` file in the migrations
|
|
62
62
|
* directory, in file-name order — Atlas's order. An empty list is a project
|
|
@@ -65,5 +65,5 @@ export declare function replayMigrationTables(migrations: readonly string[]): Ma
|
|
|
65
65
|
*
|
|
66
66
|
* Throws what {@link planSchema} throws for a configuration it cannot plan.
|
|
67
67
|
*/
|
|
68
|
-
export declare function findUnmigratedSchema(
|
|
68
|
+
export declare function findUnmigratedSchema(tables: readonly CompiledTable[], migrations: readonly string[]): UnmigratedChange[];
|
|
69
69
|
export {};
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The order a table's columns are planned in, read from its descriptor.
|
|
3
|
+
*
|
|
4
|
+
* `TableDescriptor.columns` lists the declared columns in physical order and
|
|
5
|
+
* then the foreign keys the `belongsTo` relations derive. The plan's order —
|
|
6
|
+
* which `schema.sql`, `schema.generated.ts` and every golden are written in —
|
|
7
|
+
* predates the table model, and it places a link where the legacy collection
|
|
8
|
+
* shape listed its relation property:
|
|
9
|
+
*
|
|
10
|
+
* - a declared column a `belongsTo` binds that is **nothing but the foreign
|
|
11
|
+
* key** (its key is the camelCase of the column, its type the target key's,
|
|
12
|
+
* no rule of its own, the constraint kept) is planned *as the link*, at the
|
|
13
|
+
* column's position — {@link isPlainForeignKey};
|
|
14
|
+
* - any other bound column is planned as a column of its own at its position,
|
|
15
|
+
* and its link adds a constraint-only entry (`columnOwnedByProperty`);
|
|
16
|
+
* - those constraint-only entries and the derived foreign keys are placed in
|
|
17
|
+
* relation order among the links: right after the link planned before them in
|
|
18
|
+
* that order, else just before the one after them, else after the declared
|
|
19
|
+
* columns;
|
|
20
|
+
* - an `id` that is exactly the planner's implicit key (`id TEXT PRIMARY KEY
|
|
21
|
+
* DEFAULT gen_random_uuid()::text`, declared first) is left out: the planner
|
|
22
|
+
* adds it back as the implicit key, first in SQL and last in the Drizzle file.
|
|
23
|
+
*
|
|
24
|
+
* Every fact this reads is the descriptor's, and the target's key type is the
|
|
25
|
+
* target descriptor's.
|
|
26
|
+
*/
|
|
27
|
+
import type { ColumnDescriptor, ColumnType, TableDescriptor } from "@rebasepro/types";
|
|
28
|
+
import type { RelationOfKind } from "@rebasepro/common";
|
|
29
|
+
/** A `belongsTo` relation descriptor. */
|
|
30
|
+
export type BelongsToDescriptor = RelationOfKind<"belongsTo">;
|
|
31
|
+
/**
|
|
32
|
+
* One entry of a table's planned columns, in order.
|
|
33
|
+
*
|
|
34
|
+
* - `column`: a column planned from its descriptor;
|
|
35
|
+
* - `link` / `absorbed`: a bound column that is nothing but the foreign key,
|
|
36
|
+
* planned as the link at the column's position;
|
|
37
|
+
* - `link` / `constraint`: the constraint of a link whose bound column is
|
|
38
|
+
* planned on its own (the entry renderers skip as a column);
|
|
39
|
+
* - `link` / `derived`: a foreign-key column the relation derives.
|
|
40
|
+
*/
|
|
41
|
+
export type PlannedColumnEntry = {
|
|
42
|
+
kind: "column";
|
|
43
|
+
column: ColumnDescriptor;
|
|
44
|
+
} | {
|
|
45
|
+
kind: "link";
|
|
46
|
+
form: "absorbed" | "constraint" | "derived";
|
|
47
|
+
relation: BelongsToDescriptor;
|
|
48
|
+
column: ColumnDescriptor;
|
|
49
|
+
};
|
|
50
|
+
/** The implicit key's DEFAULT: a uuid, as text. */
|
|
51
|
+
export declare const IMPLICIT_ID_DEFAULT = "gen_random_uuid()::text";
|
|
52
|
+
/** The type a column pointing at this key must have: a serial read as its plain integer. */
|
|
53
|
+
export declare const referencingColumnType: (type: ColumnType) => ColumnType;
|
|
54
|
+
/**
|
|
55
|
+
* The type of the target's key a link points at, as a column pointing at it
|
|
56
|
+
* holds it; `text` for a target with no key, `undefined` for a composite key.
|
|
57
|
+
*/
|
|
58
|
+
export declare const targetKeyColumnType: (target: TableDescriptor) => ColumnType | undefined;
|
|
59
|
+
/**
|
|
60
|
+
* Whether the table's first column is exactly the key the planner gives a
|
|
61
|
+
* table that declares none, which it adds back itself.
|
|
62
|
+
*/
|
|
63
|
+
export declare function isImplicitIdColumn(descriptor: TableDescriptor): boolean;
|
|
64
|
+
/**
|
|
65
|
+
* Whether a `belongsTo` was written `constraint: false`. The descriptor also
|
|
66
|
+
* records `constraint: false` for a link into a view or out of one, where
|
|
67
|
+
* Postgres refuses a foreign key — that link was not written without one.
|
|
68
|
+
*/
|
|
69
|
+
export declare const writtenWithoutConstraint: (descriptor: TableDescriptor, relation: BelongsToDescriptor, target: TableDescriptor) => boolean;
|
|
70
|
+
/**
|
|
71
|
+
* Whether the column a `belongsTo` binds is nothing but the foreign key the
|
|
72
|
+
* relation would have derived: served under the camelCase of its SQL name (and
|
|
73
|
+
* no relation is named after that column), typed as the target's key, with no
|
|
74
|
+
* rule of its own, and the relation keeps its constraint. Such a column is
|
|
75
|
+
* planned once, as the link.
|
|
76
|
+
*/
|
|
77
|
+
export declare function isPlainForeignKey(descriptor: TableDescriptor, column: ColumnDescriptor, relation: BelongsToDescriptor, target: TableDescriptor): boolean;
|
|
78
|
+
/**
|
|
79
|
+
* A table's planned column entries, in the plan's order (see the module
|
|
80
|
+
* comment). `targetOf` answers a relation target's descriptor by slug.
|
|
81
|
+
*/
|
|
82
|
+
export declare function plannedColumnEntries(descriptor: TableDescriptor, targetOf: (slug: string) => TableDescriptor): PlannedColumnEntry[];
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
*
|
|
19
19
|
* ## What changed when the planner arrived
|
|
20
20
|
*
|
|
21
|
-
* This used to read
|
|
21
|
+
* This used to read the legacy field definitions itself — its own reading of the type, of
|
|
22
22
|
* `validation`, of relations, of enums — and disagreed with `db push` about all
|
|
23
23
|
* of them. The audit found a required `author_id` that was NOT NULL after a
|
|
24
24
|
* push and nullable after a boot, on the one path with no developer in the
|
|
@@ -80,6 +80,12 @@ export interface ExistingSchema {
|
|
|
80
80
|
* `numeric(10,2)`).
|
|
81
81
|
*/
|
|
82
82
|
columnTypes?: Map<string, string>;
|
|
83
|
+
/**
|
|
84
|
+
* `schema.table.column` → `format_type(atttypid, atttypmod)`, the type as
|
|
85
|
+
* Postgres spells it in full. What a `col.custom()` column is compared
|
|
86
|
+
* against.
|
|
87
|
+
*/
|
|
88
|
+
columnFormats?: Map<string, string>;
|
|
83
89
|
/**
|
|
84
90
|
* `schema.table.trigger` of every trigger that already exists, and the
|
|
85
91
|
* same with its arguments — {@link triggerArgumentsKey}.
|
|
@@ -192,7 +198,7 @@ export interface DiffOptions {
|
|
|
192
198
|
* Plan every index a table that already exists needs — declared, search
|
|
193
199
|
* and vector, missing or left INVALID under its name — as a
|
|
194
200
|
* {@link DeferredIndexBuild} rather than an action, as the derived
|
|
195
|
-
* foreign-key indexes always are. `
|
|
201
|
+
* foreign-key indexes always are. `ensureTables` sets it: it
|
|
196
202
|
* hands them to `buildDeferredIndexes`, which builds them on a connection
|
|
197
203
|
* of its own with no `statement_timeout`, and drops and rebuilds a husk.
|
|
198
204
|
*
|
|
@@ -296,7 +302,7 @@ export interface DeferredIndexBuild {
|
|
|
296
302
|
invalid: boolean;
|
|
297
303
|
/**
|
|
298
304
|
* A declared `unique: true` index. Not an optimization but the collection
|
|
299
|
-
* promising two rows cannot share a value, so `
|
|
305
|
+
* promising two rows cannot share a value, so `ensureTables`
|
|
300
306
|
* builds it before it returns — never after the server is serving — and
|
|
301
307
|
* fails when it cannot, as it did when this was an action. Absent is false.
|
|
302
308
|
*/
|
|
@@ -1,28 +1,27 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The only place a
|
|
2
|
+
* The only place a table is read for schema purposes.
|
|
3
3
|
*
|
|
4
4
|
* Everything that used to `switch (prop.type)` — the Drizzle generator, the DDL
|
|
5
5
|
* generator, the boot-time ensure — now renders the {@link SchemaPlan} this
|
|
6
6
|
* produces. See `./types.ts` for why.
|
|
7
7
|
*
|
|
8
|
-
* Pure and synchronous. It reads
|
|
9
|
-
* filesystem, no process-wide registry. The one
|
|
10
|
-
* (which extensions a project's databases gave
|
|
11
|
-
* passed in, because a plan that depended on
|
|
12
|
-
* imported would not be comparable with itself.
|
|
8
|
+
* Pure and synchronous. It reads compiled tables — their descriptors — and
|
|
9
|
+
* nothing else: no database, no filesystem, no process-wide registry. The one
|
|
10
|
+
* fact about the world it needs (which extensions a project's databases gave
|
|
11
|
+
* Rebase leave to install) is passed in, because a plan that depended on
|
|
12
|
+
* whatever module happened to be imported would not be comparable with itself.
|
|
13
13
|
*
|
|
14
14
|
* It **throws** rather than guessing. A configuration no renderer can honour —
|
|
15
|
-
* an empty enum,
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
* Here it lands once, with the collection and the property named.
|
|
15
|
+
* an empty enum, a foreign key into a composite key, an array of documents, a
|
|
16
|
+
* custom type name that leaves its statement — used to fail differently in
|
|
17
|
+
* each of the three emitters, or not at all, and the failure landed at
|
|
18
|
+
* `CREATE TABLE` time on a managed tenant with nobody in the loop. Here it
|
|
19
|
+
* lands once, with the table and the column named.
|
|
21
20
|
*/
|
|
22
|
-
import { type
|
|
21
|
+
import { type SecurityRule, type ColumnType, type CompiledTable, type TableDescriptor } from "@rebasepro/types";
|
|
22
|
+
import { type PolicyTable, type ResolvePolicyTable } from "@rebasepro/common";
|
|
23
23
|
import { SET_UPDATED_AT_FN } from "./updated-at-trigger.js";
|
|
24
24
|
import type { PgType, PlanOptions, PolicyPlan, SchemaPlan, ViewPlan } from "./types.js";
|
|
25
|
-
type ResolveCollection = (slug: string) => CollectionConfig | undefined;
|
|
26
25
|
/**
|
|
27
26
|
* Single-quote escaping for a SQL string literal (PostgreSQL doubles the
|
|
28
27
|
* quote). Enum labels and `defaultValue`s come straight from user-authored
|
|
@@ -51,57 +50,61 @@ export declare const quoteSqlLiteral: (value: string) => string;
|
|
|
51
50
|
* anything else that hung off them.
|
|
52
51
|
*/
|
|
53
52
|
export declare const defaultBelongsToOnDelete: (required: boolean | undefined) => "RESTRICT" | "SET NULL";
|
|
53
|
+
/** Where a defined column lands: what its enum type, if any, is named after. */
|
|
54
|
+
export interface DefinedColumnSite {
|
|
55
|
+
/** The Postgres schema of the table (a junction's is `public`). */
|
|
56
|
+
schema: string;
|
|
57
|
+
/** The table, unqualified — an unnamed enum's type is named after it. */
|
|
58
|
+
table: string;
|
|
59
|
+
/** The table as a refusal names it: its slug, or a junction's table. */
|
|
60
|
+
owner: string;
|
|
61
|
+
/** The column key — an unnamed enum's Drizzle variable is named after it. */
|
|
62
|
+
propName: string;
|
|
63
|
+
/** The SQL column — an unnamed enum's type is named after it. */
|
|
64
|
+
column: string;
|
|
65
|
+
}
|
|
66
|
+
/** The key a link points at: its column key, its SQL column, and the type a column pointing at it has. */
|
|
67
|
+
interface TableKeyTarget {
|
|
68
|
+
key: string;
|
|
69
|
+
column: string;
|
|
70
|
+
type: PgType;
|
|
71
|
+
}
|
|
54
72
|
/**
|
|
55
|
-
* The
|
|
56
|
-
* junction endpoint
|
|
73
|
+
* The single-column key of a table a link points at — a `belongsTo` foreign
|
|
74
|
+
* key, a junction endpoint — and the type the pointing column must have: the
|
|
75
|
+
* key's own type (a serial read as its plain integer, which would otherwise
|
|
76
|
+
* give every referencing column a sequence of its own). A table with no key
|
|
77
|
+
* is pointed at by the implicit `id TEXT`.
|
|
57
78
|
*
|
|
58
|
-
*
|
|
59
|
-
*
|
|
60
|
-
* the key is a constraint waiting to fail. This used to look at the id
|
|
61
|
-
* strategy alone, so `id: { isId: true, columnType: "uuid" }` was referenced by
|
|
62
|
-
* TEXT columns (42804 — the constraint was never created) and a `bigint` key by
|
|
63
|
-
* INTEGER ones, which overflow at 2^31.
|
|
64
|
-
*
|
|
65
|
-
* One exception: a `serial` key owns a sequence, and a column pointing at it is
|
|
66
|
-
* the plain integer of the same width — `SERIAL` there would give every
|
|
67
|
-
* referencing column a sequence of its own.
|
|
68
|
-
*
|
|
69
|
-
* @param via the link asking, named if the collection's key is composite and so
|
|
70
|
-
* cannot be pointed at — see `getPrimaryKeyProp`.
|
|
79
|
+
* @param via the link asking, named if the key is composite and so cannot be
|
|
80
|
+
* pointed at.
|
|
71
81
|
*/
|
|
72
|
-
export declare const
|
|
82
|
+
export declare const tableKeyTarget: (target: TableDescriptor, via: string) => TableKeyTarget;
|
|
83
|
+
export declare const pgTypeOf: (type: ColumnType, site: DefinedColumnSite) => PgType;
|
|
73
84
|
/**
|
|
74
|
-
*
|
|
75
|
-
*
|
|
76
|
-
*
|
|
85
|
+
* One security rule of a table, compiled to its policies — what
|
|
86
|
+
* the legacy `compileSecurityRule` does for a collection, read from the table's
|
|
87
|
+
* {@link PolicyTable} (`policyTableFromDescriptor`, `junctionPolicyTable`).
|
|
77
88
|
*/
|
|
78
|
-
export declare const
|
|
89
|
+
export declare const compileTableSecurityRule: (table: PolicyTable, rule: SecurityRule, resolveTable: ResolvePolicyTable | undefined, injected: boolean, ruleKey?: string) => PolicyPlan[];
|
|
79
90
|
/**
|
|
80
|
-
*
|
|
91
|
+
* Everything a set of tables asks the database for.
|
|
81
92
|
*
|
|
82
|
-
*
|
|
83
|
-
*
|
|
84
|
-
*
|
|
85
|
-
* every write to it discarded with a 201.
|
|
86
|
-
*/
|
|
87
|
-
export declare const columnPgType: (propName: string, prop: Property, collection: CollectionConfig, resolveCollection: ResolveCollection) => PgType;
|
|
88
|
-
/**
|
|
89
|
-
* One security rule, compiled to the clauses a policy is made of.
|
|
93
|
+
* The input is the compiled tables — what `compileSchema` returns and every
|
|
94
|
+
* door (`loadTables`, boot, the CLI) hands over. Planned in the order given:
|
|
95
|
+
* the callers sort by slug first, and the generated files keep that order.
|
|
90
96
|
*
|
|
91
|
-
*
|
|
92
|
-
*
|
|
93
|
-
* DDL and the database agree about who can read a row. What this adds is only
|
|
94
|
-
* the planner's bookkeeping: which rule a policy came from, and whether Rebase
|
|
95
|
-
* injected it.
|
|
97
|
+
* @param compiledTables the compiled tables, in slug order.
|
|
98
|
+
* @param options the planner's world: the extensions it may install.
|
|
96
99
|
*/
|
|
97
|
-
export declare
|
|
98
|
-
export declare function planSchema(allCollections: CollectionConfig[], options?: PlanOptions): SchemaPlan;
|
|
100
|
+
export declare function planSchema(compiledTables: readonly CompiledTable[], options?: PlanOptions): SchemaPlan;
|
|
99
101
|
/**
|
|
100
|
-
* The
|
|
102
|
+
* The views the tables declare (`defineView`), each after the views its query
|
|
103
|
+
* names.
|
|
101
104
|
*
|
|
102
105
|
* Which views a query reads is read off its text — a planned view's name as a
|
|
103
106
|
* whole word — which is enough to order them: a name that appears in a string
|
|
104
107
|
* literal only orders two views that did not need it, never the other way.
|
|
105
108
|
*/
|
|
106
|
-
export declare function planViews(
|
|
109
|
+
export declare function planViews(tables: readonly TableDescriptor[]): ViewPlan[];
|
|
107
110
|
export { SET_UPDATED_AT_FN };
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
* last, from that set. It used to be a fixed roster plus three
|
|
16
16
|
* property-scanning heuristics, so `columnType: "uuid"` on a plain string
|
|
17
17
|
* emitted `uuid(…)` and imported nothing.
|
|
18
|
-
* - **Nothing here reads a
|
|
18
|
+
* - **Nothing here reads a field definition.** Types, defaults, keys and constraints
|
|
19
19
|
* all arrive decided. The Drizzle generator disagreeing with the DDL one is
|
|
20
20
|
* what left `geopoint` with a database column and no Drizzle key.
|
|
21
21
|
*/
|
|
@@ -3,17 +3,17 @@
|
|
|
3
3
|
*
|
|
4
4
|
* ## Why this shape exists
|
|
5
5
|
*
|
|
6
|
-
* Rebase used to compile a
|
|
6
|
+
* Rebase used to compile a field definition into a column in three places:
|
|
7
7
|
* `getDrizzleColumn` (`schema.generated.ts`), `getSqlColumnType` plus the
|
|
8
8
|
* `CREATE TABLE` walk around it (`schema.sql`, what `db push` applies) and
|
|
9
|
-
* `
|
|
9
|
+
* `planTableSchemaEnsure` (what a managed tenant gets at boot, where no
|
|
10
10
|
* `db push` ever runs). Three `switch (prop.type)` statements, three readings
|
|
11
11
|
* of `relations`, of `enum`, of `search`, of `validation.unique`. The audit
|
|
12
12
|
* that produced this module counted twelve open disagreements between them and
|
|
13
13
|
* found that a third of the commits touching those files were
|
|
14
14
|
* re-synchronisations.
|
|
15
15
|
*
|
|
16
|
-
* So a
|
|
16
|
+
* So a table is read exactly once, by {@link planSchema}, into the types
|
|
17
17
|
* below — and the three emitters became renderers of the result. A
|
|
18
18
|
* disagreement now needs someone to write a second interpreter on purpose.
|
|
19
19
|
*
|
|
@@ -30,8 +30,7 @@
|
|
|
30
30
|
* `contracts/derived-names.txt`); they are computed once, here, so the three
|
|
31
31
|
* files cannot name the same object differently.
|
|
32
32
|
*/
|
|
33
|
-
import type {
|
|
34
|
-
import type { CollectionIndexSpec } from "../collection-index.js";
|
|
33
|
+
import type { TableIndexSpec } from "../table-index.js";
|
|
35
34
|
import type { SearchColumnSpec } from "../search-column.js";
|
|
36
35
|
import type { VectorColumnSpec, VectorIndexPlan } from "../vector-index.js";
|
|
37
36
|
/**
|
|
@@ -109,6 +108,18 @@ export type PgType = {
|
|
|
109
108
|
} | {
|
|
110
109
|
kind: "array";
|
|
111
110
|
of: PgType;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* A type no other member names (`col.custom(sqlType)`): `inet`,
|
|
114
|
+
* `interval`, `timestamp`, a range, a PostGIS `geometry(Point, 4326)`, or
|
|
115
|
+
* an array of one (`inet[]`). Written into DDL verbatim — the planner
|
|
116
|
+
* accepts only a type name that cannot leave the statement
|
|
117
|
+
* (`assertCustomSqlType`) — and never created, altered or dropped: an
|
|
118
|
+
* extension or a `CREATE TYPE` the database holds provides it.
|
|
119
|
+
*/
|
|
120
|
+
| {
|
|
121
|
+
kind: "custom";
|
|
122
|
+
sqlType: string;
|
|
112
123
|
};
|
|
113
124
|
/**
|
|
114
125
|
* What a column defaults to, as the thing itself rather than a rendered string.
|
|
@@ -210,7 +221,7 @@ export interface ColumnPlan {
|
|
|
210
221
|
primaryKey: boolean;
|
|
211
222
|
unique: boolean;
|
|
212
223
|
default?: ColumnDefault;
|
|
213
|
-
/** A STORED generated column
|
|
224
|
+
/** A STORED generated column: a search column, or one a definition declares `.generatedAlwaysAs()`. */
|
|
214
225
|
generated?: {
|
|
215
226
|
expression: string;
|
|
216
227
|
stored: true;
|
|
@@ -282,7 +293,7 @@ export interface PolicyPlan {
|
|
|
282
293
|
* Carried here rather than as a policy of the table, so `policies.sql`,
|
|
283
294
|
* migrations and the generated Drizzle schema never hold it: only the boot
|
|
284
295
|
* writes it, and only where it has checked that role is safe
|
|
285
|
-
* (`
|
|
296
|
+
* (`planTablePolicies`'s `adminRequestRoleAvailable`).
|
|
286
297
|
*/
|
|
287
298
|
adminRequestCompanion?: {
|
|
288
299
|
name: string;
|
|
@@ -292,7 +303,7 @@ export interface PolicyPlan {
|
|
|
292
303
|
/**
|
|
293
304
|
* True when Rebase added this rule rather than the author. They are
|
|
294
305
|
* permissive, so they OR with the declared rules and widen the ACL beyond
|
|
295
|
-
* what
|
|
306
|
+
* what the declared rules read like — `policies.sql` says so in a comment.
|
|
296
307
|
*/
|
|
297
308
|
injected: boolean;
|
|
298
309
|
/**
|
|
@@ -373,7 +384,7 @@ export interface TablePlan {
|
|
|
373
384
|
*/
|
|
374
385
|
primaryKey: string[];
|
|
375
386
|
/** The declared `indexes:` block, with its frozen names. */
|
|
376
|
-
indexes:
|
|
387
|
+
indexes: TableIndexSpec[];
|
|
377
388
|
/** The opt-in `search` block's column, helpers and index. */
|
|
378
389
|
search?: SearchColumnSpec;
|
|
379
390
|
/** ANN indexes for the table's `vector` columns, and the ones skipped. */
|
|
@@ -396,7 +407,7 @@ export interface TablePlan {
|
|
|
396
407
|
* One entry in a generated `relations(...)` block.
|
|
397
408
|
*
|
|
398
409
|
* Both sides of a link must carry the same `relationName` or Drizzle cannot
|
|
399
|
-
* pair them; the rule that derives it is `
|
|
410
|
+
* pair them; the rule that derives it is `tableRelationName`, which both sides
|
|
400
411
|
* compute independently from the table that owns the column.
|
|
401
412
|
*/
|
|
402
413
|
export type RelationPlan = OneRelationPlan | ManyRelationPlan;
|
|
@@ -415,9 +426,9 @@ interface RelationPlanBase {
|
|
|
415
426
|
*/
|
|
416
427
|
export interface OneRelationPlan extends RelationPlanBase {
|
|
417
428
|
kind: "one";
|
|
418
|
-
/**
|
|
429
|
+
/** Column keys on this table. */
|
|
419
430
|
fields: string[];
|
|
420
|
-
/**
|
|
431
|
+
/** Column keys on the target table. */
|
|
421
432
|
references: string[];
|
|
422
433
|
/**
|
|
423
434
|
* Set on a `hasOne`, whose `fields` are this table's own key: the target
|
|
@@ -437,7 +448,7 @@ export interface PlanOptions {
|
|
|
437
448
|
*/
|
|
438
449
|
databaseExtensions?: readonly string[];
|
|
439
450
|
}
|
|
440
|
-
/** A
|
|
451
|
+
/** A table's SQL view, as `views.sql` creates it (`defineView`). */
|
|
441
452
|
export interface ViewPlan {
|
|
442
453
|
schema: string;
|
|
443
454
|
name: string;
|
|
@@ -496,8 +507,6 @@ export interface SchemaPlan {
|
|
|
496
507
|
extensions: string[];
|
|
497
508
|
/** `CREATE OR REPLACE FUNCTION …` bodies, deduplicated, in apply order. */
|
|
498
509
|
functions: string[];
|
|
499
|
-
/** The collections this plan was built from, filtered to the SQL ones. */
|
|
500
|
-
collections: CollectionConfig[];
|
|
501
510
|
options: PlanOptions;
|
|
502
511
|
}
|
|
503
512
|
export {};
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* one's name, so the plan finds it there instead of creating a twin beside it.
|
|
5
5
|
* Boot does the same through its own plan (`diffPlanAgainstCatalogue`).
|
|
6
6
|
*/
|
|
7
|
-
import { type
|
|
7
|
+
import { type CompiledTable } from "@rebasepro/types";
|
|
8
8
|
import { type IndexAdoption, type ShapeQueryable } from "./index-adoption.js";
|
|
9
|
-
/** The renames that make the database's identical indexes the
|
|
10
|
-
export declare function pushIndexAdoptions(client: ShapeQueryable,
|
|
9
|
+
/** The renames that make the database's identical indexes the tables' declared ones. */
|
|
10
|
+
export declare function pushIndexAdoptions(client: ShapeQueryable, tables: readonly CompiledTable[]): Promise<IndexAdoption[]>;
|
|
@@ -18,8 +18,8 @@
|
|
|
18
18
|
* Only an index whose columns are already there: a column this push adds is
|
|
19
19
|
* created by Atlas, and its index with it, on a column that holds no values.
|
|
20
20
|
*/
|
|
21
|
-
import { type
|
|
21
|
+
import { type CompiledTable } from "@rebasepro/types";
|
|
22
22
|
import { type DeferredIndexBuild } from "./plan/diff-plan.js";
|
|
23
|
-
import { type Queryable } from "./ensure-
|
|
23
|
+
import { type Queryable } from "./ensure-tables.js";
|
|
24
24
|
/** The derived foreign-key indexes a live table lacks (or holds INVALID) whose columns it already has. */
|
|
25
|
-
export declare function missingForeignKeyIndexes(client: Queryable,
|
|
25
|
+
export declare function missingForeignKeyIndexes(client: Queryable, tables: readonly CompiledTable[]): Promise<DeferredIndexBuild[]>;
|
|
@@ -24,9 +24,9 @@
|
|
|
24
24
|
* database has none of them, and Atlas refuses such a column whether or not
|
|
25
25
|
* it is in `schema.sql`; adding it would only change the error.
|
|
26
26
|
*/
|
|
27
|
-
import { type
|
|
28
|
-
import type { Queryable } from "./ensure-
|
|
29
|
-
/** A column whose DEFAULT the
|
|
27
|
+
import { type CompiledTable } from "@rebasepro/types";
|
|
28
|
+
import type { Queryable } from "./ensure-tables.js";
|
|
29
|
+
/** A column whose DEFAULT the tables leave to the database. */
|
|
30
30
|
export interface DatabaseOwnedDefaultColumn {
|
|
31
31
|
schema: string;
|
|
32
32
|
table: string;
|
|
@@ -37,11 +37,11 @@ export interface KeptDefault extends DatabaseOwnedDefaultColumn {
|
|
|
37
37
|
expression: string;
|
|
38
38
|
}
|
|
39
39
|
/**
|
|
40
|
-
* Every column declared `
|
|
41
|
-
*
|
|
42
|
-
*
|
|
40
|
+
* Every column declared `.dbDefault()` that the planner writes no DEFAULT
|
|
41
|
+
* for. A key strategy or a stamp writes one of its own, and that one is the
|
|
42
|
+
* planner's to keep.
|
|
43
43
|
*/
|
|
44
|
-
export declare function databaseOwnedDefaultColumns(
|
|
44
|
+
export declare function databaseOwnedDefaultColumns(tables: readonly CompiledTable[]): DatabaseOwnedDefaultColumn[];
|
|
45
45
|
/**
|
|
46
46
|
* The live DEFAULTs of `columns` that the desired state must carry so Atlas
|
|
47
47
|
* plans no `DROP DEFAULT`. A column with no DEFAULT, or one Atlas cannot carry,
|
|
@@ -10,11 +10,11 @@
|
|
|
10
10
|
* could not upgrade an aged database at all. Renaming first — the same
|
|
11
11
|
* metadata-only statement boot runs — leaves Atlas nothing to plan.
|
|
12
12
|
*/
|
|
13
|
-
import { type
|
|
13
|
+
import { type CompiledTable } from "@rebasepro/types";
|
|
14
14
|
import { type LegacyForeignKey } from "./plan/diff-plan.js";
|
|
15
|
-
import { type Queryable } from "./ensure-
|
|
15
|
+
import { type Queryable } from "./ensure-tables.js";
|
|
16
16
|
export interface LegacyRename extends LegacyForeignKey {
|
|
17
17
|
/** `ALTER TABLE … RENAME COLUMN …;` */
|
|
18
18
|
sql: string;
|
|
19
19
|
}
|
|
20
|
-
export declare function legacyForeignKeyRenames(client: Queryable,
|
|
20
|
+
export declare function legacyForeignKeyRenames(client: Queryable, tables: readonly CompiledTable[]): Promise<LegacyRename[]>;
|
|
@@ -5,13 +5,13 @@
|
|
|
5
5
|
* So its plan, which was everything `db push --dry-run` showed, never named
|
|
6
6
|
* one. After `schema introspect` on a database whose tables had policies of
|
|
7
7
|
* their own and no admin baseline, the dry run said "No changes: the database
|
|
8
|
-
* already matches these
|
|
8
|
+
* already matches these tables", and the push then created eight
|
|
9
9
|
* `<table>_default_admin_*` policies that let an admin read and write every
|
|
10
10
|
* row.
|
|
11
11
|
*
|
|
12
12
|
* The plan is the push's own steps, read instead of run:
|
|
13
13
|
*
|
|
14
|
-
* - **RLS switched on:** the tables `
|
|
14
|
+
* - **RLS switched on:** the tables `lockTables` switches on
|
|
15
15
|
* ({@link tablesRlsWouldEnable}).
|
|
16
16
|
* - **Policies created and replaced:** `policies.sql`, which DROPs and CREATEs
|
|
17
17
|
* every declared policy, against the database as `checkPolicyDrift` reads
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
* - **Policies dropped and kept:** {@link partitionOrphans}, which is how the
|
|
27
27
|
* push's reconcile step decides.
|
|
28
28
|
*/
|
|
29
|
-
import type {
|
|
29
|
+
import type { CompiledTable } from "@rebasepro/types";
|
|
30
30
|
import { type AdminPoliciesExpectation, type PolicyRef, type Queryable } from "../security/policy-drift.js";
|
|
31
31
|
export interface PolicyPushPlan {
|
|
32
32
|
/** Declared tables in the database with row-level security off, as `schema.table`: the push switches it on. */
|
|
@@ -40,7 +40,7 @@ export interface PolicyPushPlan {
|
|
|
40
40
|
}[];
|
|
41
41
|
/** Policies an earlier push generated from a rule edited since: the push drops them. */
|
|
42
42
|
drop: PolicyRef[];
|
|
43
|
-
/** Policies no
|
|
43
|
+
/** Policies no table describes, which the push leaves in force. */
|
|
44
44
|
keep: PolicyRef[];
|
|
45
45
|
/** Declared policies the database has with no stamp of Rebase's: re-created from their rules, changed or not. */
|
|
46
46
|
unstamped: PolicyRef[];
|
|
@@ -55,7 +55,7 @@ export interface PolicyPushPlan {
|
|
|
55
55
|
* policies (`TO rebase_admin`, or `TO public` where the admin switch is
|
|
56
56
|
* not live); `"detect"` reads it off the database. Left out, as compiled.
|
|
57
57
|
*/
|
|
58
|
-
export declare function planPolicyPush(client: Queryable,
|
|
58
|
+
export declare function planPolicyPush(client: Queryable, compiledTables: readonly CompiledTable[], options?: {
|
|
59
59
|
searchPath?: string;
|
|
60
60
|
adminRoleAvailable?: AdminPoliciesExpectation;
|
|
61
61
|
}): Promise<PolicyPushPlan>;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { CompiledTable, SchemaReconcilePlan } from "@rebasepro/types";
|
|
2
2
|
import { type ExistingSchema } from "./plan/diff-plan.js";
|
|
3
|
-
import { type Queryable } from "./ensure-
|
|
3
|
+
import { type Queryable } from "./ensure-tables.js";
|
|
4
4
|
export interface ReconcileOptions {
|
|
5
|
-
/** Undeclared columns to drop, as `<
|
|
5
|
+
/** Undeclared columns to drop, as `<table slug>.<column>`. */
|
|
6
6
|
drop?: string[];
|
|
7
7
|
}
|
|
8
|
-
export declare function planSchemaReconcile(
|
|
8
|
+
export declare function planSchemaReconcile(compiledTables: readonly CompiledTable[], existing: ExistingSchema, options?: ReconcileOptions): SchemaReconcilePlan;
|
|
9
9
|
/**
|
|
10
10
|
* The identity of a plan: its statements, in order. A caller applies only on
|
|
11
11
|
* the digest it was shown, so the statements that run are the ones read.
|
|
@@ -18,4 +18,4 @@ export declare function reconcileDigest(statements: string[]): string;
|
|
|
18
18
|
* songbuzz_voice_cache.wav" into "drop 12,408 recordings", which is the
|
|
19
19
|
* sentence a person should be agreeing to.
|
|
20
20
|
*/
|
|
21
|
-
export declare function readReconcileFacts(client: Queryable,
|
|
21
|
+
export declare function readReconcileFacts(client: Queryable, tables: readonly CompiledTable[], options?: ReconcileOptions): Promise<SchemaReconcilePlan>;
|