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