turbine-orm 0.65.0 → 0.66.0
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 +34 -32
- package/dist/adapters/cockroachdb.js +21 -3
- package/dist/adapters/index.d.ts +15 -0
- package/dist/adapters/yugabytedb.js +20 -3
- package/dist/cjs/adapters/cockroachdb.js +21 -3
- package/dist/cjs/adapters/index.d.ts +15 -0
- package/dist/cjs/adapters/yugabytedb.js +20 -3
- package/dist/cjs/cli/destructive.d.ts +18 -4
- package/dist/cjs/cli/destructive.js +230 -122
- package/dist/cjs/cli/index.d.ts +21 -4
- package/dist/cjs/cli/index.js +119 -22
- package/dist/cjs/cli/mcp.d.ts +28 -8
- package/dist/cjs/cli/mcp.js +170 -127
- package/dist/cjs/cli/migrate.d.ts +134 -13
- package/dist/cjs/cli/migrate.js +349 -241
- package/dist/cjs/cli/pii-predicate-guard.d.ts +112 -0
- package/dist/cjs/cli/pii-predicate-guard.js +390 -0
- package/dist/cjs/cli/prisma-resolve.js +75 -4
- package/dist/cjs/cli/prisma-schema.d.ts +17 -1
- package/dist/cjs/cli/prisma-schema.js +83 -17
- package/dist/cjs/cli/sql-statements.d.ts +125 -0
- package/dist/cjs/cli/sql-statements.js +378 -0
- package/dist/cjs/cli/studio.js +49 -118
- package/dist/cjs/cli/ui.d.ts +1 -1
- package/dist/cjs/client.d.ts +43 -0
- package/dist/cjs/client.js +125 -6
- package/dist/cjs/dialect.d.ts +123 -0
- package/dist/cjs/dialect.js +33 -0
- package/dist/cjs/errors.d.ts +74 -1
- package/dist/cjs/errors.js +239 -25
- package/dist/cjs/index-advisor.d.ts +33 -1
- package/dist/cjs/index-advisor.js +32 -1
- package/dist/cjs/introspect.d.ts +48 -0
- package/dist/cjs/introspect.js +222 -91
- package/dist/cjs/mssql.js +43 -1
- package/dist/cjs/mysql.d.ts +5 -2
- package/dist/cjs/mysql.js +202 -17
- package/dist/cjs/nested-write.js +6 -1
- package/dist/cjs/pipeline-submittable.js +17 -3
- package/dist/cjs/pipeline.js +75 -9
- package/dist/cjs/powdb.d.ts +23 -0
- package/dist/cjs/powdb.js +33 -1
- package/dist/cjs/powql.d.ts +61 -9
- package/dist/cjs/powql.js +186 -49
- package/dist/cjs/prisma-compat.js +160 -41
- package/dist/cjs/query/aggregates.d.ts +1 -1
- package/dist/cjs/query/aggregates.js +80 -18
- package/dist/cjs/query/batched-loader.d.ts +10 -0
- package/dist/cjs/query/batched-loader.js +268 -7
- package/dist/cjs/query/builder.d.ts +73 -0
- package/dist/cjs/query/builder.js +225 -28
- package/dist/cjs/query/filters.d.ts +162 -0
- package/dist/cjs/query/filters.js +250 -1
- package/dist/cjs/query/relations.d.ts +10 -10
- package/dist/cjs/query/relations.js +93 -12
- package/dist/cjs/query/types.d.ts +14 -1
- package/dist/cjs/query/utils.d.ts +146 -2
- package/dist/cjs/query/utils.js +210 -4
- package/dist/cjs/query/warn-registry.d.ts +10 -0
- package/dist/cjs/query/warn-registry.js +10 -0
- package/dist/cjs/query/where-compile.d.ts +30 -0
- package/dist/cjs/query/where-compile.js +41 -0
- package/dist/cjs/query/where.d.ts +128 -13
- package/dist/cjs/query/where.js +215 -77
- package/dist/cjs/query/writes.d.ts +1 -1
- package/dist/cjs/query/writes.js +39 -15
- package/dist/cjs/schema-builder.d.ts +2 -1
- package/dist/cjs/schema-sql.d.ts +94 -4
- package/dist/cjs/schema-sql.js +506 -30
- package/dist/cjs/schema.d.ts +3 -1
- package/dist/cjs/sqlite.d.ts +6 -0
- package/dist/cjs/sqlite.js +151 -10
- package/dist/cjs/typed-sql.d.ts +29 -1
- package/dist/cjs/typed-sql.js +30 -12
- package/dist/cli/destructive.d.ts +18 -4
- package/dist/cli/destructive.js +229 -121
- package/dist/cli/index.d.ts +21 -4
- package/dist/cli/index.js +120 -24
- package/dist/cli/mcp.d.ts +28 -8
- package/dist/cli/mcp.js +172 -129
- package/dist/cli/migrate.d.ts +134 -13
- package/dist/cli/migrate.js +347 -238
- package/dist/cli/pii-predicate-guard.d.ts +112 -0
- package/dist/cli/pii-predicate-guard.js +386 -0
- package/dist/cli/prisma-resolve.js +75 -4
- package/dist/cli/prisma-schema.d.ts +17 -1
- package/dist/cli/prisma-schema.js +83 -17
- package/dist/cli/sql-statements.d.ts +125 -0
- package/dist/cli/sql-statements.js +373 -0
- package/dist/cli/studio.js +49 -118
- package/dist/cli/ui.d.ts +1 -1
- package/dist/client.d.ts +43 -0
- package/dist/client.js +126 -7
- package/dist/dialect.d.ts +123 -0
- package/dist/dialect.js +33 -0
- package/dist/errors.d.ts +74 -1
- package/dist/errors.js +228 -19
- package/dist/index-advisor.d.ts +33 -1
- package/dist/index-advisor.js +31 -1
- package/dist/introspect.d.ts +48 -0
- package/dist/introspect.js +221 -91
- package/dist/mssql.js +44 -2
- package/dist/mysql.d.ts +5 -2
- package/dist/mysql.js +203 -18
- package/dist/nested-write.js +7 -2
- package/dist/pipeline-submittable.js +18 -4
- package/dist/pipeline.js +76 -10
- package/dist/powdb.d.ts +23 -0
- package/dist/powdb.js +33 -2
- package/dist/powql.d.ts +61 -9
- package/dist/powql.js +187 -50
- package/dist/prisma-compat.js +160 -41
- package/dist/query/aggregates.d.ts +1 -1
- package/dist/query/aggregates.js +82 -20
- package/dist/query/batched-loader.d.ts +10 -0
- package/dist/query/batched-loader.js +270 -9
- package/dist/query/builder.d.ts +73 -0
- package/dist/query/builder.js +226 -30
- package/dist/query/filters.d.ts +162 -0
- package/dist/query/filters.js +246 -1
- package/dist/query/relations.d.ts +10 -10
- package/dist/query/relations.js +94 -14
- package/dist/query/types.d.ts +14 -1
- package/dist/query/utils.d.ts +146 -2
- package/dist/query/utils.js +204 -3
- package/dist/query/warn-registry.d.ts +10 -0
- package/dist/query/warn-registry.js +10 -0
- package/dist/query/where-compile.d.ts +30 -0
- package/dist/query/where-compile.js +40 -1
- package/dist/query/where.d.ts +128 -13
- package/dist/query/where.js +216 -80
- package/dist/query/writes.d.ts +1 -1
- package/dist/query/writes.js +40 -16
- package/dist/schema-builder.d.ts +2 -1
- package/dist/schema-sql.d.ts +94 -4
- package/dist/schema-sql.js +505 -30
- package/dist/schema.d.ts +3 -1
- package/dist/sqlite.d.ts +6 -0
- package/dist/sqlite.js +151 -10
- package/dist/typed-sql.d.ts +29 -1
- package/dist/typed-sql.js +30 -12
- package/package.json +6 -4
|
@@ -188,7 +188,7 @@ export declare function assertBindableSetValue(qi: BuilderCtx, key: string, valu
|
|
|
188
188
|
* Fingerprint SET clauses for update/updateMany.
|
|
189
189
|
* Captures key names + operator types (set/increment/etc) but not values.
|
|
190
190
|
*/
|
|
191
|
-
export declare function fingerprintSet(
|
|
191
|
+
export declare function fingerprintSet(qi: BuilderCtx, data: Record<string, unknown>): string;
|
|
192
192
|
/**
|
|
193
193
|
* Collect SET params for update/updateMany. Mirrors buildSetClause param order.
|
|
194
194
|
*/
|
package/dist/cjs/query/writes.js
CHANGED
|
@@ -172,7 +172,7 @@ function buildDefaultValuesInsert(qi, rowCount, skipDuplicates) {
|
|
|
172
172
|
function buildCreate(qi, args) {
|
|
173
173
|
assertWritable(qi, 'create');
|
|
174
174
|
assertNoGeneratedColumns(qi, args.data, 'create');
|
|
175
|
-
const entries =
|
|
175
|
+
const entries = writeEntries(qi, args.data);
|
|
176
176
|
const columns = entries.map(([k]) => qi.toSqlColumn(k));
|
|
177
177
|
const params = entries.map(([k, v]) => coerceWriteValue(qi, k, v));
|
|
178
178
|
// Enum columns get an explicit `::"EnumName"` cast (see enumTypeForColumn).
|
|
@@ -233,15 +233,39 @@ function makeCreateReselect(qi, insertSql, insertParams, data) {
|
|
|
233
233
|
};
|
|
234
234
|
}
|
|
235
235
|
/**
|
|
236
|
-
* The
|
|
236
|
+
* The `[key, value]` pairs a write's `data` object actually names, in the
|
|
237
|
+
* table's own column order.
|
|
237
238
|
*
|
|
238
239
|
* A key whose value is `undefined` is NOT named: single-row {@link buildCreate}
|
|
239
240
|
* filters those out of its column list, so the column takes its declared
|
|
240
|
-
* default. `createMany` reads its rows through
|
|
241
|
-
* `{ n: undefined }` and `{}` mean the identical
|
|
241
|
+
* default. `createMany` reads its rows through {@link definedKeys}, which is
|
|
242
|
+
* this function's key half, so `{ n: undefined }` and `{}` mean the identical
|
|
243
|
+
* thing on both paths.
|
|
244
|
+
*
|
|
245
|
+
* THE ORDERING IS A SECURITY BOUND, not tidiness, and it is the whole reason
|
|
246
|
+
* this is one function rather than an `Object.entries` at each site. A write's
|
|
247
|
+
* column list is SQL TEXT: `SET "a" = $1, "b" = $2` and `SET "b" = $1, "a" = $2`
|
|
248
|
+
* are the same write and two different permanently-cached server-side prepared
|
|
249
|
+
* statements. `JSON.parse` preserves insertion order, so
|
|
250
|
+
* `update({ where, data: JSON.parse(reqBody) })` (an ordinary REST handler)
|
|
251
|
+
* lets the request body pick that order, with no array, no arity, and nothing
|
|
252
|
+
* the caller needs to know. Measured on PostgreSQL 16: 720 PATCH bodies
|
|
253
|
+
* carrying the SAME six keys in different orders left 720 prepared statements
|
|
254
|
+
* and 2.8 MB of CachedPlanSource on one connection. See
|
|
255
|
+
* {@link canonicalWriteEntries} for the ordering rule and why duplicates are
|
|
256
|
+
* deliberately preserved.
|
|
257
|
+
*
|
|
258
|
+
* Every consumer of this list must use THIS function: the SET-clause build, the
|
|
259
|
+
* cache fingerprint ({@link fingerprintSet}) and the param collector
|
|
260
|
+
* ({@link collectSetParams}) must enumerate one identical order or the cached
|
|
261
|
+
* statement and its params describe different writes.
|
|
242
262
|
*/
|
|
243
|
-
function
|
|
244
|
-
return Object.
|
|
263
|
+
function writeEntries(qi, data) {
|
|
264
|
+
return (0, utils_js_1.canonicalWriteEntries)(qi.tableMeta, Object.entries(data).filter(([, v]) => v !== undefined));
|
|
265
|
+
}
|
|
266
|
+
/** The key half of {@link writeEntries}, for the paths that need names only. */
|
|
267
|
+
function definedKeys(qi, row) {
|
|
268
|
+
return writeEntries(qi, row).map(([k]) => k);
|
|
245
269
|
}
|
|
246
270
|
/**
|
|
247
271
|
* Refuse a `createMany` whose rows do not all name the SAME fields.
|
|
@@ -271,7 +295,7 @@ function definedKeys(row) {
|
|
|
271
295
|
function assertUniformCreateManyRows(qi, rows, firstKeys) {
|
|
272
296
|
const expected = new Set(firstKeys);
|
|
273
297
|
for (let i = 1; i < rows.length; i++) {
|
|
274
|
-
const rowKeys = definedKeys(rows[i]);
|
|
298
|
+
const rowKeys = definedKeys(qi, rows[i]);
|
|
275
299
|
const unexpected = rowKeys.filter((k) => !expected.has(k));
|
|
276
300
|
// No stranger and the same count means the same set (object keys are unique).
|
|
277
301
|
if (unexpected.length === 0 && rowKeys.length === expected.size)
|
|
@@ -309,7 +333,7 @@ function buildCreateMany(qi, args) {
|
|
|
309
333
|
for (const row of args.data) {
|
|
310
334
|
assertNoGeneratedColumns(qi, row, 'createMany');
|
|
311
335
|
}
|
|
312
|
-
const keys = definedKeys(args.data[0]);
|
|
336
|
+
const keys = definedKeys(qi, args.data[0]);
|
|
313
337
|
assertUniformCreateManyRows(qi, args.data, keys);
|
|
314
338
|
// No column named by the first row: every row is pure defaults (the bulk
|
|
315
339
|
// counterpart of `create({ data: {} })`, see buildDefaultValuesInsert). The
|
|
@@ -417,7 +441,7 @@ function buildUpdate(qi, args) {
|
|
|
417
441
|
const ck = lock ? null : `u:${setFp}|${whereFp}${whereMod.globalFilterCacheSegment(qi)}`;
|
|
418
442
|
const params = [];
|
|
419
443
|
const buildSql = (freshParams) => {
|
|
420
|
-
const setEntries =
|
|
444
|
+
const setEntries = writeEntries(qi, dataObj);
|
|
421
445
|
const setClauses = setEntries.map(([k, v]) => buildSetClause(qi, k, v, freshParams));
|
|
422
446
|
if (lock) {
|
|
423
447
|
const versionCol = qi.toSqlColumn(lock.field);
|
|
@@ -567,7 +591,7 @@ function buildUpsert(qi, args) {
|
|
|
567
591
|
// Prisma compound-unique selector on the conflict target → its member columns.
|
|
568
592
|
const upsertWhere = (0, compound_unique_js_1.expandCompoundUniqueWhere)(qi.tableMeta, args.where);
|
|
569
593
|
// Build the INSERT part from create data
|
|
570
|
-
const createEntries =
|
|
594
|
+
const createEntries = writeEntries(qi, args.create);
|
|
571
595
|
const columns = createEntries.map(([k]) => qi.toSqlColumn(k));
|
|
572
596
|
const createParams = createEntries.map(([k, v]) => coerceWriteValue(qi, k, v));
|
|
573
597
|
// Enum columns get an explicit `::"EnumName"` cast (see enumTypeForColumn).
|
|
@@ -576,7 +600,7 @@ function buildUpsert(qi, args) {
|
|
|
576
600
|
const conflictKeys = Object.keys(upsertWhere).filter((k) => upsertWhere[k] !== undefined);
|
|
577
601
|
const conflictColumns = conflictKeys.map((k) => qi.toSqlColumn(k));
|
|
578
602
|
// Build the UPDATE SET part
|
|
579
|
-
const updateEntries =
|
|
603
|
+
const updateEntries = writeEntries(qi, args.update);
|
|
580
604
|
let paramIdx = createParams.length + 1;
|
|
581
605
|
const setClauses = updateEntries.map(([k]) => {
|
|
582
606
|
const clause = `${qi.toSqlColumn(k)} = ${qi.p(paramIdx)}${whereMod.enumCastSuffix(qi, qi.toColumn(k))}`;
|
|
@@ -654,7 +678,7 @@ function buildUpdateMany(qi, args) {
|
|
|
654
678
|
const ck = `um:${setFp}|${whereFp}${whereMod.globalFilterCacheSegment(qi)}`;
|
|
655
679
|
const params = [];
|
|
656
680
|
const buildSql = (freshParams) => {
|
|
657
|
-
const setEntries =
|
|
681
|
+
const setEntries = writeEntries(qi, dataObj);
|
|
658
682
|
const setClauses = setEntries.map(([k, v]) => buildSetClause(qi, k, v, freshParams));
|
|
659
683
|
const whereClause = whereMod.buildWhereClause(qi, whereObj, freshParams);
|
|
660
684
|
const whereSql = whereClause ? ` WHERE ${whereClause}` : '';
|
|
@@ -979,8 +1003,8 @@ function assertBindableSetValue(qi, key, value) {
|
|
|
979
1003
|
* Fingerprint SET clauses for update/updateMany.
|
|
980
1004
|
* Captures key names + operator types (set/increment/etc) but not values.
|
|
981
1005
|
*/
|
|
982
|
-
function fingerprintSet(
|
|
983
|
-
const entries =
|
|
1006
|
+
function fingerprintSet(qi, data) {
|
|
1007
|
+
const entries = writeEntries(qi, data);
|
|
984
1008
|
const parts = [];
|
|
985
1009
|
for (const [k, v] of entries) {
|
|
986
1010
|
if (v !== null &&
|
|
@@ -1002,7 +1026,7 @@ function fingerprintSet(_qi, data) {
|
|
|
1002
1026
|
* Collect SET params for update/updateMany. Mirrors buildSetClause param order.
|
|
1003
1027
|
*/
|
|
1004
1028
|
function collectSetParams(qi, data, params) {
|
|
1005
|
-
const entries =
|
|
1029
|
+
const entries = writeEntries(qi, data);
|
|
1006
1030
|
for (const [k, v] of entries) {
|
|
1007
1031
|
if (v !== null &&
|
|
1008
1032
|
typeof v === 'object' &&
|
|
@@ -70,7 +70,8 @@ export interface ColumnDef {
|
|
|
70
70
|
* `schemaDefToMetadata` / codegen, onto
|
|
71
71
|
* {@link import('./schema.js').ColumnMetadata.pii}. A PII column is excluded
|
|
72
72
|
* from default projections (read back only via an explicit `select` or
|
|
73
|
-
* `includePii:
|
|
73
|
+
* `includePii: UNSAFE`, the imported sentinel symbol) and redacted by Studio.
|
|
74
|
+
* Introspection never auto-tags PII.
|
|
74
75
|
*/
|
|
75
76
|
pii?: boolean;
|
|
76
77
|
/**
|
package/dist/cjs/schema-sql.d.ts
CHANGED
|
@@ -8,7 +8,7 @@ import { type DestructiveStatement } from './cli/destructive.js';
|
|
|
8
8
|
import { type Dialect } from './dialect.js';
|
|
9
9
|
import { ValidationError } from './errors.js';
|
|
10
10
|
import { type ReferentialAction } from './schema.js';
|
|
11
|
-
import { type ColumnIndexDef, type SchemaDef, type TableDef } from './schema-builder.js';
|
|
11
|
+
import { type ColumnConfig, type ColumnIndexDef, type SchemaDef, type TableDef } from './schema-builder.js';
|
|
12
12
|
export interface SchemaSqlOptions {
|
|
13
13
|
/** SQL dialect used for DDL generation. Defaults to PostgreSQL. */
|
|
14
14
|
dialect?: Dialect;
|
|
@@ -154,13 +154,92 @@ export declare function diffCheckConstraints(table: string, schemaChecks: readon
|
|
|
154
154
|
statements: string[];
|
|
155
155
|
reverseStatements: string[];
|
|
156
156
|
};
|
|
157
|
+
/** Options for {@link schemaDiff} and {@link schemaPush}. */
|
|
158
|
+
export interface SchemaDiffOptions {
|
|
159
|
+
/**
|
|
160
|
+
* Postgres NAMESPACE the diff reads (default `public`).
|
|
161
|
+
*
|
|
162
|
+
* Every catalog read here used to hardcode `'public'` while `generate`,
|
|
163
|
+
* `pull`, `doctor`, and `studio` all honored the configured schema. Against a
|
|
164
|
+
* table in a non-public schema the diff therefore saw nothing and emitted
|
|
165
|
+
* `CREATE TABLE "users"` (a duplicate in public); worse, when a legacy copy of
|
|
166
|
+
* the table still sat in `public` (the usual state after moving to a dedicated
|
|
167
|
+
* schema) it read THAT one and emitted ALTER / DROP COLUMN against the wrong
|
|
168
|
+
* table. Defaults to `public`, so a project with no schema configured emits
|
|
169
|
+
* byte-identical SQL.
|
|
170
|
+
*/
|
|
171
|
+
schema?: string;
|
|
172
|
+
}
|
|
157
173
|
/**
|
|
158
174
|
* Compare a SchemaDef against a live Postgres database and return the diff.
|
|
159
175
|
*
|
|
160
|
-
* Connects to the database, inspects
|
|
161
|
-
* DDL is needed to make the database match the schema definition.
|
|
176
|
+
* Connects to the database, inspects `options.schema` (default `public`), and
|
|
177
|
+
* computes what DDL is needed to make the database match the schema definition.
|
|
162
178
|
*/
|
|
163
|
-
export declare function schemaDiff(schema: SchemaDef, connectionString: string): Promise<DiffResult>;
|
|
179
|
+
export declare function schemaDiff(schema: SchemaDef, connectionString: string, options?: SchemaDiffOptions): Promise<DiffResult>;
|
|
180
|
+
/** The type-relevant subset of {@link DbColumn}, so {@link planTypeChange} stays testable. */
|
|
181
|
+
export interface DbColumnType {
|
|
182
|
+
udtName: string;
|
|
183
|
+
maxLength: number | null;
|
|
184
|
+
numericPrecision: number | null;
|
|
185
|
+
numericScale: number | null;
|
|
186
|
+
/**
|
|
187
|
+
* `format_type(atttypid, atttypmod)` from pg_catalog: the type exactly as
|
|
188
|
+
* Postgres would write it, e.g. `character varying(255)[]`, `vector(3)`,
|
|
189
|
+
* `numeric(10,2)`, `app."Probe"`. Read alongside information_schema because
|
|
190
|
+
* information_schema cannot express an array element's length modifier or a
|
|
191
|
+
* pgvector dimension count, and because it is the only spelling of an
|
|
192
|
+
* unmapped type that is guaranteed to be valid, correctly quoted and
|
|
193
|
+
* correctly schema-qualified DDL. Null only when a caller builds the value by
|
|
194
|
+
* hand (the live diff always populates it).
|
|
195
|
+
*/
|
|
196
|
+
formattedType: string | null;
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* What the diff should do about one column's type.
|
|
200
|
+
*
|
|
201
|
+
* `alter` carries `needsUsing` (see {@link planTypeChange}) and, when the
|
|
202
|
+
* conversion can lose or reject data, a `loss` sentence naming the SPECIFIC
|
|
203
|
+
* loss. `warn` is for a difference the code-first schema cannot express, where
|
|
204
|
+
* emitting DDL would destroy an intentional database-side constraint.
|
|
205
|
+
*/
|
|
206
|
+
export type TypeChangePlan = {
|
|
207
|
+
kind: 'none';
|
|
208
|
+
} | {
|
|
209
|
+
kind: 'alter';
|
|
210
|
+
needsUsing: boolean;
|
|
211
|
+
loss?: string;
|
|
212
|
+
} | {
|
|
213
|
+
kind: 'warn';
|
|
214
|
+
reason: string;
|
|
215
|
+
};
|
|
216
|
+
/**
|
|
217
|
+
* Decide what the diff should emit for one column's type.
|
|
218
|
+
*
|
|
219
|
+
* Two things this deliberately does that the previous `udtName !== expectedUdt`
|
|
220
|
+
* check did not:
|
|
221
|
+
*
|
|
222
|
+
* 1. It compares LENGTH and NUMERIC PRECISION, not just the UDT name. A
|
|
223
|
+
* declared `varchar(10)` against a database `VARCHAR(255)` produced no
|
|
224
|
+
* statement and no warning, so `push` printed "Database is already in
|
|
225
|
+
* sync" for a schema that genuinely differed. The widening direction is
|
|
226
|
+
* the operationally painful one: the schema says 255, the column is 10,
|
|
227
|
+
* push says in sync, and writes fail at runtime with "value too long".
|
|
228
|
+
* 2. It reports `needsUsing` FALSE for a same-family conversion. The old
|
|
229
|
+
* statement always appended `USING col::type`, and an EXPLICIT cast to
|
|
230
|
+
* `varchar(n)` TRUNCATES where the plain assignment cast raises "value too
|
|
231
|
+
* long". Postgres refuses that migration on its own; the generated `USING`
|
|
232
|
+
* converted the refusal into silent data amputation. Same shape for
|
|
233
|
+
* `numeric -> integer` and `timestamptz -> date`. `USING` is emitted only
|
|
234
|
+
* where the conversion genuinely needs it (text to uuid, text to an enum,
|
|
235
|
+
* anything crossing a type family), where no assignment cast exists.
|
|
236
|
+
*
|
|
237
|
+
* Numeric PRECISION drift gets a warning rather than a statement: `defineSchema`
|
|
238
|
+
* has no way to declare `numeric(10, 2)`, so every such column would otherwise
|
|
239
|
+
* get a table-rewriting `ALTER ... TYPE NUMERIC` on every push, discarding a
|
|
240
|
+
* constraint the schema never had the vocabulary to ask for.
|
|
241
|
+
*/
|
|
242
|
+
export declare function planTypeChange(config: ColumnConfig, dbCol: DbColumnType, column: string): TypeChangePlan;
|
|
164
243
|
/**
|
|
165
244
|
* Scan a set of diff statements for data-destroying operations, using the same
|
|
166
245
|
* conservative scanner (`scanDestructiveSql`) that gates `migrate up`/`down`.
|
|
@@ -204,11 +283,22 @@ export declare class DestructivePushRefusal extends ValidationError {
|
|
|
204
283
|
* `allowDestructive: true` is passed. The CLI (`turbine push`) catches this and
|
|
205
284
|
* prompts for the same typed confirmation as `migrate up`; programmatic callers
|
|
206
285
|
* must opt in explicitly.
|
|
286
|
+
*
|
|
287
|
+
* `options.schema` (default `public`) scopes BOTH halves: the diff reads that
|
|
288
|
+
* namespace, and the generated DDL (which names tables unqualified) is executed
|
|
289
|
+
* with a transaction-local `search_path` pinned so the target schema resolves
|
|
290
|
+
* FIRST. Without the second half a diff that correctly found nothing in `app`
|
|
291
|
+
* would still emit `CREATE TABLE "users"` into whatever the connection's
|
|
292
|
+
* search_path happens to resolve to. The pin is unconditional (`public` is a
|
|
293
|
+
* target like any other, since a role's own search_path may not lead there),
|
|
294
|
+
* refuses a schema that does not exist, and APPENDS the connection's existing
|
|
295
|
+
* path so types living elsewhere still resolve. See {@link pinSearchPath}.
|
|
207
296
|
*/
|
|
208
297
|
export declare function schemaPush(schema: SchemaDef, connectionString: string, options?: {
|
|
209
298
|
dryRun?: boolean;
|
|
210
299
|
allowDestructive?: boolean;
|
|
211
300
|
precomputedDiff?: DiffResult;
|
|
301
|
+
schema?: string;
|
|
212
302
|
}): Promise<PushResult>;
|
|
213
303
|
/**
|
|
214
304
|
* Generate the full DDL as a single formatted string.
|