drizzle-kit 0.23.2 → 0.24.0-5df8253
Sign up to get free protection for your applications and to get access to all the features.
- package/api.d.mts +30 -4
- package/api.d.ts +30 -4
- package/api.js +252 -120
- package/api.mjs +252 -120
- package/bin.cjs +439 -251
- package/package.json +2 -1
- package/utils.js +7 -1
- package/utils.mjs +6 -1
package/api.js
CHANGED
@@ -7464,11 +7464,30 @@ var init_mysqlSchema = __esm({
|
|
7464
7464
|
}
|
7465
7465
|
});
|
7466
7466
|
|
7467
|
+
// src/extensions/vector.ts
|
7468
|
+
var vectorOps;
|
7469
|
+
var init_vector = __esm({
|
7470
|
+
"src/extensions/vector.ts"() {
|
7471
|
+
"use strict";
|
7472
|
+
vectorOps = [
|
7473
|
+
"vector_l2_ops",
|
7474
|
+
"vector_ip_ops",
|
7475
|
+
"vector_cosine_ops",
|
7476
|
+
"vector_l1_ops",
|
7477
|
+
"bit_hamming_ops",
|
7478
|
+
"bit_jaccard_ops",
|
7479
|
+
"halfvec_l2_ops",
|
7480
|
+
"sparsevec_l2_ops"
|
7481
|
+
];
|
7482
|
+
}
|
7483
|
+
});
|
7484
|
+
|
7467
7485
|
// src/serializer/pgSchema.ts
|
7468
7486
|
var indexV2, columnV2, tableV2, enumSchemaV1, enumSchema, pgSchemaV2, references, columnV1, tableV1, pgSchemaV1, indexColumn, index2, indexV4, indexV5, indexV6, fk2, sequenceSchema, sequenceSquashed, columnV7, column2, columnSquashed, tableV32, compositePK2, uniqueConstraint2, tableV42, tableV5, tableV6, tableV7, table2, schemaHash2, kitInternals2, pgSchemaInternalV3, pgSchemaInternalV4, pgSchemaInternalV5, pgSchemaInternalV6, pgSchemaExternal, pgSchemaInternalV7, pgSchemaInternal, tableSquashed2, tableSquashedV42, pgSchemaSquashedV4, pgSchemaSquashedV6, pgSchemaSquashed, pgSchemaV3, pgSchemaV4, pgSchemaV5, pgSchemaV6, pgSchemaV7, pgSchema, backwardCompatiblePgSchema, PgSquasher, squashPgScheme, dryPg;
|
7469
7487
|
var init_pgSchema = __esm({
|
7470
7488
|
"src/serializer/pgSchema.ts"() {
|
7471
7489
|
"use strict";
|
7490
|
+
init_vector();
|
7472
7491
|
init_global();
|
7473
7492
|
init_lib();
|
7474
7493
|
indexV2 = objectType({
|
@@ -7715,7 +7734,8 @@ var init_pgSchema = __esm({
|
|
7715
7734
|
objectType({
|
7716
7735
|
isArray: booleanType().optional(),
|
7717
7736
|
dimensions: numberType().optional(),
|
7718
|
-
rawType: stringType().optional()
|
7737
|
+
rawType: stringType().optional(),
|
7738
|
+
isDefaultAnExpression: booleanType().optional()
|
7719
7739
|
}).optional()
|
7720
7740
|
)
|
7721
7741
|
}).optional()
|
@@ -7853,7 +7873,7 @@ var init_pgSchema = __esm({
|
|
7853
7873
|
squashIdx: (idx) => {
|
7854
7874
|
index2.parse(idx);
|
7855
7875
|
return `${idx.name};${idx.columns.map(
|
7856
|
-
(c) => `${c.expression}--${c.isExpression}--${c.asc}--${c.nulls}--${c.opclass}`
|
7876
|
+
(c) => `${c.expression}--${c.isExpression}--${c.asc}--${c.nulls}--${c.opclass && vectorOps.includes(c.opclass) ? c.opclass : ""}`
|
7857
7877
|
).join(",,")};${idx.isUnique};${idx.concurrently};${idx.method};${idx.where};${JSON.stringify(idx.with)}`;
|
7858
7878
|
},
|
7859
7879
|
unsquashIdx: (input) => {
|
@@ -8338,6 +8358,9 @@ var init_sqliteSchema = __esm({
|
|
8338
8358
|
});
|
8339
8359
|
|
8340
8360
|
// src/utils.ts
|
8361
|
+
function isPgArrayType(sqlType) {
|
8362
|
+
return sqlType.match(/.*\[\d*\].*|.*\[\].*/g) !== null;
|
8363
|
+
}
|
8341
8364
|
var copy, prepareMigrationMeta, schemaRenameKey, tableRenameKey, columnRenameKey;
|
8342
8365
|
var init_utils = __esm({
|
8343
8366
|
"src/utils.ts"() {
|
@@ -8711,14 +8734,14 @@ var require_heap = __commonJS({
|
|
8711
8734
|
return item;
|
8712
8735
|
};
|
8713
8736
|
heapify = function(array, cmp) {
|
8714
|
-
var i, _i2,
|
8737
|
+
var i, _i2, _j2, _len, _ref, _ref1, _results, _results1;
|
8715
8738
|
if (cmp == null) {
|
8716
8739
|
cmp = defaultCmp;
|
8717
8740
|
}
|
8718
8741
|
_ref1 = function() {
|
8719
8742
|
_results1 = [];
|
8720
|
-
for (var
|
8721
|
-
_results1.push(
|
8743
|
+
for (var _j3 = 0, _ref2 = floor(array.length / 2); 0 <= _ref2 ? _j3 < _ref2 : _j3 > _ref2; 0 <= _ref2 ? _j3++ : _j3--) {
|
8744
|
+
_results1.push(_j3);
|
8722
8745
|
}
|
8723
8746
|
return _results1;
|
8724
8747
|
}.apply(this).reverse();
|
@@ -8759,7 +8782,7 @@ var require_heap = __commonJS({
|
|
8759
8782
|
return result.sort(cmp).reverse();
|
8760
8783
|
};
|
8761
8784
|
nsmallest = function(array, n, cmp) {
|
8762
|
-
var elem, i, los, result, _i2,
|
8785
|
+
var elem, i, los, result, _i2, _j2, _len, _ref, _ref1, _results;
|
8763
8786
|
if (cmp == null) {
|
8764
8787
|
cmp = defaultCmp;
|
8765
8788
|
}
|
@@ -8782,7 +8805,7 @@ var require_heap = __commonJS({
|
|
8782
8805
|
}
|
8783
8806
|
heapify(array, cmp);
|
8784
8807
|
_results = [];
|
8785
|
-
for (i =
|
8808
|
+
for (i = _j2 = 0, _ref1 = min2(n, array.length); 0 <= _ref1 ? _j2 < _ref1 : _j2 > _ref1; i = 0 <= _ref1 ? ++_j2 : --_j2) {
|
8786
8809
|
_results.push(heappop(array, cmp));
|
8787
8810
|
}
|
8788
8811
|
return _results;
|
@@ -11499,7 +11522,7 @@ var init_sqlgenerator = __esm({
|
|
11499
11522
|
isPgNativeType = (it) => {
|
11500
11523
|
if (pgNativeTypes.has(it)) return true;
|
11501
11524
|
const toCheck = it.replace(/ /g, "");
|
11502
|
-
return toCheck.startsWith("varchar(") || toCheck.startsWith("char(") || toCheck.startsWith("numeric(") || toCheck.startsWith("timestamp(") || toCheck.startsWith("intervalyear(") || toCheck.startsWith("intervalmonth(") || toCheck.startsWith("intervalday(") || toCheck.startsWith("intervalhour(") || toCheck.startsWith("intervalminute(") || toCheck.startsWith("intervalsecond(") || toCheck.startsWith("intervalyeartomonth(") || toCheck.startsWith("intervaldaytohour(") || toCheck.startsWith("intervaldaytominute(") || toCheck.startsWith("intervaldaytosecond(") || toCheck.startsWith("intervalhourtominute(") || toCheck.startsWith("intervalhourtosecond(") || toCheck.startsWith("intervalminutetosecond(") || toCheck.startsWith("vector(") || toCheck.startsWith("geometry(") || /^(\w+)(\[\d*])+$/.test(it);
|
11525
|
+
return toCheck.startsWith("varchar(") || toCheck.startsWith("char(") || toCheck.startsWith("numeric(") || toCheck.startsWith("timestamp(") || toCheck.startsWith("doubleprecision[") || toCheck.startsWith("intervalyear(") || toCheck.startsWith("intervalmonth(") || toCheck.startsWith("intervalday(") || toCheck.startsWith("intervalhour(") || toCheck.startsWith("intervalminute(") || toCheck.startsWith("intervalsecond(") || toCheck.startsWith("intervalyeartomonth(") || toCheck.startsWith("intervaldaytohour(") || toCheck.startsWith("intervaldaytominute(") || toCheck.startsWith("intervaldaytosecond(") || toCheck.startsWith("intervalhourtominute(") || toCheck.startsWith("intervalhourtosecond(") || toCheck.startsWith("intervalminutetosecond(") || toCheck.startsWith("vector(") || toCheck.startsWith("geometry(") || /^(\w+)(\[\d*])+$/.test(it);
|
11503
11526
|
};
|
11504
11527
|
Convertor = class {
|
11505
11528
|
};
|
@@ -17477,7 +17500,7 @@ function getTableName(table4) {
|
|
17477
17500
|
function getTableUniqueName(table4) {
|
17478
17501
|
return `${table4[Schema] ?? "public"}.${table4[TableName]}`;
|
17479
17502
|
}
|
17480
|
-
var TableName, Schema, Columns, ExtraConfigColumns, OriginalName, BaseName, IsAlias, ExtraConfigBuilder, IsDrizzleTable, _a3, _b, _c, _d, _e, _f, _g, _h, _i, Table2;
|
17503
|
+
var TableName, Schema, Columns, ExtraConfigColumns, OriginalName, BaseName, IsAlias, ExtraConfigBuilder, IsDrizzleTable, _a3, _b, _c, _d, _e, _f, _g, _h, _i, _j, Table2;
|
17481
17504
|
var init_table = __esm({
|
17482
17505
|
"../drizzle-orm/dist/table.js"() {
|
17483
17506
|
"use strict";
|
@@ -17491,32 +17514,34 @@ var init_table = __esm({
|
|
17491
17514
|
IsAlias = Symbol.for("drizzle:IsAlias");
|
17492
17515
|
ExtraConfigBuilder = Symbol.for("drizzle:ExtraConfigBuilder");
|
17493
17516
|
IsDrizzleTable = Symbol.for("drizzle:IsDrizzleTable");
|
17494
|
-
|
17517
|
+
_j = entityKind, _i = TableName, _h = OriginalName, _g = Schema, _f = Columns, _e = ExtraConfigColumns, _d = BaseName, _c = IsAlias, _b = IsDrizzleTable, _a3 = ExtraConfigBuilder;
|
17495
17518
|
Table2 = class {
|
17496
17519
|
constructor(name2, schema4, baseName) {
|
17497
17520
|
/**
|
17498
17521
|
* @internal
|
17499
17522
|
* Can be changed if the table is aliased.
|
17500
17523
|
*/
|
17501
|
-
__publicField(this,
|
17524
|
+
__publicField(this, _i);
|
17502
17525
|
/**
|
17503
17526
|
* @internal
|
17504
17527
|
* Used to store the original name of the table, before any aliasing.
|
17505
17528
|
*/
|
17529
|
+
__publicField(this, _h);
|
17530
|
+
/** @internal */
|
17506
17531
|
__publicField(this, _g);
|
17507
17532
|
/** @internal */
|
17508
17533
|
__publicField(this, _f);
|
17509
17534
|
/** @internal */
|
17510
17535
|
__publicField(this, _e);
|
17511
|
-
/** @internal */
|
17512
|
-
__publicField(this, _d);
|
17513
17536
|
/**
|
17514
17537
|
* @internal
|
17515
17538
|
* Used to store the table name before the transformation via the `tableCreator` functions.
|
17516
17539
|
*/
|
17517
|
-
__publicField(this,
|
17540
|
+
__publicField(this, _d);
|
17541
|
+
/** @internal */
|
17542
|
+
__publicField(this, _c, false);
|
17518
17543
|
/** @internal */
|
17519
|
-
__publicField(this, _b,
|
17544
|
+
__publicField(this, _b, true);
|
17520
17545
|
/** @internal */
|
17521
17546
|
__publicField(this, _a3);
|
17522
17547
|
this[TableName] = this[OriginalName] = name2;
|
@@ -17524,7 +17549,7 @@ var init_table = __esm({
|
|
17524
17549
|
this[BaseName] = baseName;
|
17525
17550
|
}
|
17526
17551
|
};
|
17527
|
-
__publicField(Table2,
|
17552
|
+
__publicField(Table2, _j, "Table");
|
17528
17553
|
/** @internal */
|
17529
17554
|
__publicField(Table2, "Symbol", {
|
17530
17555
|
Name: TableName,
|
@@ -18100,7 +18125,7 @@ var version;
|
|
18100
18125
|
var init_version = __esm({
|
18101
18126
|
"../drizzle-orm/dist/version.js"() {
|
18102
18127
|
"use strict";
|
18103
|
-
version = "0.
|
18128
|
+
version = "0.33.0";
|
18104
18129
|
}
|
18105
18130
|
});
|
18106
18131
|
|
@@ -18202,6 +18227,12 @@ function fillPlaceholders(params, values) {
|
|
18202
18227
|
}
|
18203
18228
|
return values[p.name];
|
18204
18229
|
}
|
18230
|
+
if (is(p, Param) && is(p.value, Placeholder)) {
|
18231
|
+
if (!(p.value.name in values)) {
|
18232
|
+
throw new Error(`No value for placeholder "${p.value.name}" was provided`);
|
18233
|
+
}
|
18234
|
+
return p.encoder.mapToDriverValue(values[p.value.name]);
|
18235
|
+
}
|
18205
18236
|
return p;
|
18206
18237
|
});
|
18207
18238
|
}
|
@@ -18315,6 +18346,9 @@ var init_sql = __esm({
|
|
18315
18346
|
};
|
18316
18347
|
}
|
18317
18348
|
if (is(chunk, Param)) {
|
18349
|
+
if (is(chunk.value, Placeholder)) {
|
18350
|
+
return { sql: escapeParam(paramStartIndex.value++, chunk), params: [chunk], typings: ["none"] };
|
18351
|
+
}
|
18318
18352
|
const mappedValue = chunk.value === null ? null : chunk.encoder.mapToDriverValue(chunk.value);
|
18319
18353
|
if (is(mappedValue, _SQL)) {
|
18320
18354
|
return this.buildQueryFromSourceParams([mappedValue], config);
|
@@ -19359,7 +19393,7 @@ function jaccardDistance(column4, value) {
|
|
19359
19393
|
}
|
19360
19394
|
return sql`${column4} <%> ${value}`;
|
19361
19395
|
}
|
19362
|
-
var
|
19396
|
+
var init_vector2 = __esm({
|
19363
19397
|
"../drizzle-orm/dist/sql/functions/vector.js"() {
|
19364
19398
|
"use strict";
|
19365
19399
|
init_sql();
|
@@ -19371,7 +19405,7 @@ var init_functions = __esm({
|
|
19371
19405
|
"../drizzle-orm/dist/sql/functions/index.js"() {
|
19372
19406
|
"use strict";
|
19373
19407
|
init_aggregate();
|
19374
|
-
|
19408
|
+
init_vector2();
|
19375
19409
|
}
|
19376
19410
|
});
|
19377
19411
|
|
@@ -21035,7 +21069,7 @@ var init_sparsevec = __esm({
|
|
21035
21069
|
|
21036
21070
|
// ../drizzle-orm/dist/pg-core/columns/vector_extension/vector.js
|
21037
21071
|
var _a122, _b95, PgVectorBuilder, _a123, _b96, PgVector;
|
21038
|
-
var
|
21072
|
+
var init_vector3 = __esm({
|
21039
21073
|
"../drizzle-orm/dist/pg-core/columns/vector_extension/vector.js"() {
|
21040
21074
|
"use strict";
|
21041
21075
|
init_entity();
|
@@ -21107,7 +21141,7 @@ var init_columns = __esm({
|
|
21107
21141
|
init_bit();
|
21108
21142
|
init_halfvec();
|
21109
21143
|
init_sparsevec();
|
21110
|
-
|
21144
|
+
init_vector3();
|
21111
21145
|
}
|
21112
21146
|
});
|
21113
21147
|
|
@@ -24605,24 +24639,6 @@ var init_pg_core = __esm({
|
|
24605
24639
|
}
|
24606
24640
|
});
|
24607
24641
|
|
24608
|
-
// src/extensions/vector.ts
|
24609
|
-
var vectorOps;
|
24610
|
-
var init_vector3 = __esm({
|
24611
|
-
"src/extensions/vector.ts"() {
|
24612
|
-
"use strict";
|
24613
|
-
vectorOps = [
|
24614
|
-
"vector_l2_ops",
|
24615
|
-
"vector_ip_ops",
|
24616
|
-
"vector_cosine_ops",
|
24617
|
-
"vector_l1_ops",
|
24618
|
-
"bit_hamming_ops",
|
24619
|
-
"bit_jaccard_ops",
|
24620
|
-
"halfvec_l2_ops",
|
24621
|
-
"sparsevec_l2_ops"
|
24622
|
-
];
|
24623
|
-
}
|
24624
|
-
});
|
24625
|
-
|
24626
24642
|
// src/serializer/pgSerializer.ts
|
24627
24643
|
function stringFromIdentityProperty(field) {
|
24628
24644
|
return typeof field === "string" ? field : typeof field === "undefined" ? void 0 : String(field);
|
@@ -24636,7 +24652,31 @@ function minRangeForIdentityBasedOn(columnType) {
|
|
24636
24652
|
function stringFromDatabaseIdentityProperty(field) {
|
24637
24653
|
return typeof field === "string" ? field : typeof field === "undefined" ? void 0 : typeof field === "bigint" ? field.toString() : String(field);
|
24638
24654
|
}
|
24639
|
-
|
24655
|
+
function buildArrayString(array, sqlType) {
|
24656
|
+
sqlType = sqlType.split("[")[0];
|
24657
|
+
const values = array.map((value) => {
|
24658
|
+
if (typeof value === "number" || typeof value === "bigint") {
|
24659
|
+
return value.toString();
|
24660
|
+
} else if (typeof value === "boolean") {
|
24661
|
+
return value ? "true" : "false";
|
24662
|
+
} else if (Array.isArray(value)) {
|
24663
|
+
return buildArrayString(value, sqlType);
|
24664
|
+
} else if (value instanceof Date) {
|
24665
|
+
if (sqlType === "date") {
|
24666
|
+
return `"${value.toISOString().split("T")[0]}"`;
|
24667
|
+
} else if (sqlType === "timestamp") {
|
24668
|
+
return `"${value.toISOString().replace("T", " ").slice(0, 23)}"`;
|
24669
|
+
} else {
|
24670
|
+
return `"${value.toISOString()}"`;
|
24671
|
+
}
|
24672
|
+
} else if (typeof value === "object") {
|
24673
|
+
return `"${JSON.stringify(value).replaceAll('"', '\\"')}"`;
|
24674
|
+
}
|
24675
|
+
return `"${value}"`;
|
24676
|
+
}).join(",");
|
24677
|
+
return `{${values}}`;
|
24678
|
+
}
|
24679
|
+
var dialect4, indexName, generatePgSnapshot, trimChar, fromDatabase, defaultForColumn;
|
24640
24680
|
var init_pgSerializer = __esm({
|
24641
24681
|
"src/serializer/pgSerializer.ts"() {
|
24642
24682
|
"use strict";
|
@@ -24644,8 +24684,9 @@ var init_pgSerializer = __esm({
|
|
24644
24684
|
init_dist();
|
24645
24685
|
init_pg_core();
|
24646
24686
|
init_pg_core();
|
24647
|
-
|
24687
|
+
init_vector();
|
24648
24688
|
init_outputs();
|
24689
|
+
init_utils();
|
24649
24690
|
init_serializer();
|
24650
24691
|
dialect4 = new PgDialect();
|
24651
24692
|
indexName = (tableName, columns) => {
|
@@ -24752,6 +24793,11 @@ ${withStyle.errorWarning(`We've found duplicated unique constraint names in ${so
|
|
24752
24793
|
} else {
|
24753
24794
|
columnToSet.default = `'${column4.default.toISOString()}'`;
|
24754
24795
|
}
|
24796
|
+
} else if (isPgArrayType(sqlTypeLowered) && Array.isArray(column4.default)) {
|
24797
|
+
columnToSet.default = `'${buildArrayString(
|
24798
|
+
column4.default,
|
24799
|
+
sqlTypeLowered
|
24800
|
+
)}'`;
|
24755
24801
|
} else {
|
24756
24802
|
columnToSet.default = column4.default;
|
24757
24803
|
}
|
@@ -25098,7 +25144,7 @@ ${withStyle.errorWarning(
|
|
25098
25144
|
WHEN 'int2'::regtype THEN 'smallserial'
|
25099
25145
|
END
|
25100
25146
|
ELSE format_type(a.atttypid, a.atttypmod)
|
25101
|
-
END AS data_type, INFORMATION_SCHEMA.COLUMNS.table_name,
|
25147
|
+
END AS data_type, INFORMATION_SCHEMA.COLUMNS.table_name, ns.nspname as type_schema,
|
25102
25148
|
pg_get_serial_sequence('"${tableSchema}"."${tableName}"', a.attname)::regclass as seq_name, INFORMATION_SCHEMA.COLUMNS.column_name,
|
25103
25149
|
INFORMATION_SCHEMA.COLUMNS.column_default, INFORMATION_SCHEMA.COLUMNS.data_type as additional_dt,
|
25104
25150
|
INFORMATION_SCHEMA.COLUMNS.udt_name as enum_name,
|
@@ -25109,6 +25155,7 @@ ${withStyle.errorWarning(
|
|
25109
25155
|
INFORMATION_SCHEMA.COLUMNS.identity_cycle
|
25110
25156
|
FROM pg_attribute a
|
25111
25157
|
JOIN INFORMATION_SCHEMA.COLUMNS ON INFORMATION_SCHEMA.COLUMNS.column_name = a.attname
|
25158
|
+
JOIN pg_type t ON t.oid = a.atttypid LEFT JOIN pg_namespace ns ON ns.oid = t.typnamespace
|
25112
25159
|
WHERE a.attrelid = '"${tableSchema}"."${tableName}"'::regclass and INFORMATION_SCHEMA.COLUMNS.table_name = '${tableName}' and INFORMATION_SCHEMA.COLUMNS.table_schema = '${tableSchema}'
|
25113
25160
|
AND a.attnum > 0
|
25114
25161
|
AND NOT a.attisdropped
|
@@ -25128,30 +25175,42 @@ ${withStyle.errorWarning(
|
|
25128
25175
|
}
|
25129
25176
|
const tableForeignKeys = await db.query(
|
25130
25177
|
`SELECT
|
25131
|
-
|
25132
|
-
|
25133
|
-
|
25134
|
-
|
25135
|
-
|
25136
|
-
|
25137
|
-
|
25138
|
-
|
25139
|
-
|
25140
|
-
|
25141
|
-
|
25142
|
-
|
25143
|
-
|
25144
|
-
|
25145
|
-
|
25146
|
-
|
25147
|
-
|
25148
|
-
|
25149
|
-
|
25150
|
-
|
25151
|
-
|
25152
|
-
|
25153
|
-
|
25154
|
-
|
25178
|
+
con.contype AS constraint_type,
|
25179
|
+
nsp.nspname AS constraint_schema,
|
25180
|
+
con.conname AS constraint_name,
|
25181
|
+
rel.relname AS table_name,
|
25182
|
+
att.attname AS column_name,
|
25183
|
+
fnsp.nspname AS foreign_table_schema,
|
25184
|
+
frel.relname AS foreign_table_name,
|
25185
|
+
fatt.attname AS foreign_column_name,
|
25186
|
+
CASE con.confupdtype
|
25187
|
+
WHEN 'a' THEN 'NO ACTION'
|
25188
|
+
WHEN 'r' THEN 'RESTRICT'
|
25189
|
+
WHEN 'n' THEN 'SET NULL'
|
25190
|
+
WHEN 'c' THEN 'CASCADE'
|
25191
|
+
WHEN 'd' THEN 'SET DEFAULT'
|
25192
|
+
END AS update_rule,
|
25193
|
+
CASE con.confdeltype
|
25194
|
+
WHEN 'a' THEN 'NO ACTION'
|
25195
|
+
WHEN 'r' THEN 'RESTRICT'
|
25196
|
+
WHEN 'n' THEN 'SET NULL'
|
25197
|
+
WHEN 'c' THEN 'CASCADE'
|
25198
|
+
WHEN 'd' THEN 'SET DEFAULT'
|
25199
|
+
END AS delete_rule
|
25200
|
+
FROM
|
25201
|
+
pg_catalog.pg_constraint con
|
25202
|
+
JOIN pg_catalog.pg_class rel ON rel.oid = con.conrelid
|
25203
|
+
JOIN pg_catalog.pg_namespace nsp ON nsp.oid = con.connamespace
|
25204
|
+
LEFT JOIN pg_catalog.pg_attribute att ON att.attnum = ANY (con.conkey)
|
25205
|
+
AND att.attrelid = con.conrelid
|
25206
|
+
LEFT JOIN pg_catalog.pg_class frel ON frel.oid = con.confrelid
|
25207
|
+
LEFT JOIN pg_catalog.pg_namespace fnsp ON fnsp.oid = frel.relnamespace
|
25208
|
+
LEFT JOIN pg_catalog.pg_attribute fatt ON fatt.attnum = ANY (con.confkey)
|
25209
|
+
AND fatt.attrelid = con.confrelid
|
25210
|
+
WHERE
|
25211
|
+
nsp.nspname = '${tableSchema}'
|
25212
|
+
AND rel.relname = '${tableName}'
|
25213
|
+
AND con.contype IN ('f');`
|
25155
25214
|
);
|
25156
25215
|
foreignKeysCount += tableForeignKeys.length;
|
25157
25216
|
if (progressCallback) {
|
@@ -25209,6 +25268,8 @@ ${withStyle.errorWarning(
|
|
25209
25268
|
const columnDimensions = columnResponse.array_dimensions;
|
25210
25269
|
const enumType2 = columnResponse.enum_name;
|
25211
25270
|
let columnType = columnResponse.data_type;
|
25271
|
+
const typeSchema = columnResponse.type_schema;
|
25272
|
+
const defaultValueRes = columnResponse.column_default;
|
25212
25273
|
const isGenerated = columnResponse.is_generated === "ALWAYS";
|
25213
25274
|
const generationExpression = columnResponse.generation_expression;
|
25214
25275
|
const isIdentity = columnResponse.is_identity === "YES";
|
@@ -25239,12 +25300,7 @@ ${withStyle.errorWarning(
|
|
25239
25300
|
columns: cprimaryKey.map((c) => c.column_name)
|
25240
25301
|
};
|
25241
25302
|
}
|
25242
|
-
const defaultValue = defaultForColumn(columnResponse);
|
25243
|
-
const isSerial = columnType === "serial";
|
25244
25303
|
let columnTypeMapped = columnType;
|
25245
|
-
if (columnTypeMapped.startsWith("numeric(")) {
|
25246
|
-
columnTypeMapped = columnTypeMapped.replace(",", ", ");
|
25247
|
-
}
|
25248
25304
|
if (columnAdditionalDT === "ARRAY") {
|
25249
25305
|
if (typeof internals.tables[tableName] === "undefined") {
|
25250
25306
|
internals.tables[tableName] = {
|
@@ -25272,6 +25328,34 @@ ${withStyle.errorWarning(
|
|
25272
25328
|
}
|
25273
25329
|
}
|
25274
25330
|
}
|
25331
|
+
const defaultValue = defaultForColumn(
|
25332
|
+
columnResponse,
|
25333
|
+
internals,
|
25334
|
+
tableName
|
25335
|
+
);
|
25336
|
+
if (defaultValue === "NULL" || defaultValueRes && defaultValueRes.startsWith("(") && defaultValueRes.endsWith(")")) {
|
25337
|
+
if (typeof internals.tables[tableName] === "undefined") {
|
25338
|
+
internals.tables[tableName] = {
|
25339
|
+
columns: {
|
25340
|
+
[columnName]: {
|
25341
|
+
isDefaultAnExpression: true
|
25342
|
+
}
|
25343
|
+
}
|
25344
|
+
};
|
25345
|
+
} else {
|
25346
|
+
if (typeof internals.tables[tableName].columns[columnName] === "undefined") {
|
25347
|
+
internals.tables[tableName].columns[columnName] = {
|
25348
|
+
isDefaultAnExpression: true
|
25349
|
+
};
|
25350
|
+
} else {
|
25351
|
+
internals.tables[tableName].columns[columnName].isDefaultAnExpression = true;
|
25352
|
+
}
|
25353
|
+
}
|
25354
|
+
}
|
25355
|
+
const isSerial = columnType === "serial";
|
25356
|
+
if (columnTypeMapped.startsWith("numeric(")) {
|
25357
|
+
columnTypeMapped = columnTypeMapped.replace(",", ", ");
|
25358
|
+
}
|
25275
25359
|
if (columnAdditionalDT === "ARRAY") {
|
25276
25360
|
for (let i = 1; i < Number(columnDimensions); i++) {
|
25277
25361
|
columnTypeMapped += "[]";
|
@@ -25285,7 +25369,7 @@ ${withStyle.errorWarning(
|
|
25285
25369
|
// filter vectors, but in future we should filter any extension that was installed by user
|
25286
25370
|
columnAdditionalDT === "USER-DEFINED" && !["vector", "geometry"].includes(enumType2) ? enumType2 : columnTypeMapped
|
25287
25371
|
),
|
25288
|
-
typeSchema: enumsToReturn[`${
|
25372
|
+
typeSchema: enumsToReturn[`${typeSchema}.${enumType2}`] !== void 0 ? enumsToReturn[`${typeSchema}.${enumType2}`].schema : void 0,
|
25289
25373
|
primaryKey: primaryKey.length === 1 && cprimaryKey.length < 2,
|
25290
25374
|
// default: isSerial ? undefined : defaultValue,
|
25291
25375
|
notNull: columnResponse.is_nullable === "NO",
|
@@ -25456,59 +25540,71 @@ ${withStyle.errorWarning(
|
|
25456
25540
|
internal: internals
|
25457
25541
|
};
|
25458
25542
|
};
|
25459
|
-
|
25460
|
-
|
25461
|
-
|
25462
|
-
// "character varying": "::character varying",
|
25463
|
-
// "double precision": "::double precision",
|
25464
|
-
// "time with time zone": "::time with time zone",
|
25465
|
-
"time without time zone": "::time without time zone",
|
25466
|
-
// "timestamp with time zone": "::timestamp with time zone",
|
25467
|
-
"timestamp without time zone": "::timestamp without time zone",
|
25468
|
-
"timestamp(": "::timestamp without time zone",
|
25469
|
-
// date: "::date",
|
25470
|
-
// interval: "::interval",
|
25471
|
-
// character: "::bpchar",
|
25472
|
-
// macaddr8: "::macaddr8",
|
25473
|
-
// macaddr: "::macaddr",
|
25474
|
-
// inet: "::inet",
|
25475
|
-
// cidr: "::cidr",
|
25476
|
-
// jsonb: "::jsonb",
|
25477
|
-
// json: "::json",
|
25478
|
-
"character(": "::bpchar"
|
25479
|
-
};
|
25480
|
-
defaultForColumn = (column4) => {
|
25543
|
+
defaultForColumn = (column4, internals, tableName) => {
|
25544
|
+
const columnName = column4.attname;
|
25545
|
+
const isArray = internals?.tables[tableName]?.columns[columnName]?.isArray ?? false;
|
25481
25546
|
if (column4.column_default === null) {
|
25482
25547
|
return void 0;
|
25483
25548
|
}
|
25484
25549
|
if (column4.data_type === "serial" || column4.data_type === "smallserial" || column4.data_type === "bigserial") {
|
25485
25550
|
return void 0;
|
25486
25551
|
}
|
25487
|
-
|
25552
|
+
if (column4.column_default.endsWith("[]")) {
|
25553
|
+
column4.column_default = column4.column_default.slice(0, -2);
|
25554
|
+
}
|
25555
|
+
column4.column_default = column4.column_default.replace(/::(.*?)(?<![^\w"])(?=$)/, "");
|
25488
25556
|
const columnDefaultAsString = column4.column_default.toString();
|
25489
|
-
if (
|
25490
|
-
|
25491
|
-
|
25492
|
-
|
25493
|
-
|
25494
|
-
|
25495
|
-
|
25496
|
-
|
25497
|
-
|
25498
|
-
|
25499
|
-
|
25500
|
-
|
25501
|
-
|
25502
|
-
|
25503
|
-
|
25504
|
-
|
25505
|
-
|
25557
|
+
if (isArray) {
|
25558
|
+
return `'{${columnDefaultAsString.slice(2, -2).split(/\s*,\s*/g).map((value) => {
|
25559
|
+
if (["integer", "smallint", "bigint", "double precision", "real"].includes(column4.data_type.slice(0, -2))) {
|
25560
|
+
return value;
|
25561
|
+
} else if (column4.data_type.startsWith("timestamp")) {
|
25562
|
+
return `${value}`;
|
25563
|
+
} else if (column4.data_type.slice(0, -2) === "interval") {
|
25564
|
+
return value.replaceAll('"', `"`);
|
25565
|
+
} else if (column4.data_type.slice(0, -2) === "boolean") {
|
25566
|
+
return value === "t" ? "true" : "false";
|
25567
|
+
} else if (["json", "jsonb"].includes(column4.data_type.slice(0, -2))) {
|
25568
|
+
return JSON.stringify(JSON.stringify(JSON.parse(JSON.parse(value)), null, 0));
|
25569
|
+
} else {
|
25570
|
+
return `"${value}"`;
|
25571
|
+
}
|
25572
|
+
}).join(",")}}'`;
|
25573
|
+
}
|
25574
|
+
if (["integer", "smallint", "bigint", "double precision", "real"].includes(column4.data_type)) {
|
25575
|
+
if (/^-?[\d.]+(?:e-?\d+)?$/.test(columnDefaultAsString)) {
|
25506
25576
|
return Number(columnDefaultAsString);
|
25507
|
-
} else if (column4.data_type === "boolean") {
|
25508
|
-
return column4.column_default === "true";
|
25509
25577
|
} else {
|
25510
|
-
|
25578
|
+
if (typeof internals.tables[tableName] === "undefined") {
|
25579
|
+
internals.tables[tableName] = {
|
25580
|
+
columns: {
|
25581
|
+
[columnName]: {
|
25582
|
+
isDefaultAnExpression: true
|
25583
|
+
}
|
25584
|
+
}
|
25585
|
+
};
|
25586
|
+
} else {
|
25587
|
+
if (typeof internals.tables[tableName].columns[columnName] === "undefined") {
|
25588
|
+
internals.tables[tableName].columns[columnName] = {
|
25589
|
+
isDefaultAnExpression: true
|
25590
|
+
};
|
25591
|
+
} else {
|
25592
|
+
internals.tables[tableName].columns[columnName].isDefaultAnExpression = true;
|
25593
|
+
}
|
25594
|
+
}
|
25595
|
+
return columnDefaultAsString;
|
25511
25596
|
}
|
25597
|
+
} else if (column4.data_type === "json" || column4.data_type === "jsonb") {
|
25598
|
+
const jsonWithoutSpaces = JSON.stringify(JSON.parse(columnDefaultAsString.slice(1, -1)));
|
25599
|
+
return `'${jsonWithoutSpaces}'::${column4.data_type}`;
|
25600
|
+
} else if (column4.data_type === "boolean") {
|
25601
|
+
return column4.column_default === "true";
|
25602
|
+
} else if (columnDefaultAsString === "NULL") {
|
25603
|
+
return `NULL`;
|
25604
|
+
} else if (columnDefaultAsString.startsWith("'") && columnDefaultAsString.endsWith("'")) {
|
25605
|
+
return columnDefaultAsString;
|
25606
|
+
} else {
|
25607
|
+
return `${columnDefaultAsString.replace(/\\/g, "`\\")}`;
|
25512
25608
|
}
|
25513
25609
|
};
|
25514
25610
|
}
|
@@ -29031,7 +29127,7 @@ The unique constraint ${source_default.underline.blue(
|
|
29031
29127
|
primaryKeys.forEach((it) => {
|
29032
29128
|
if (it.columns.length > 1) {
|
29033
29129
|
primaryKeysObject[it.getName()] = {
|
29034
|
-
columns: it.columns.map((it2) => it2.name)
|
29130
|
+
columns: it.columns.map((it2) => it2.name),
|
29035
29131
|
name: it.getName()
|
29036
29132
|
};
|
29037
29133
|
} else {
|
@@ -29156,7 +29252,6 @@ The unique constraint ${source_default.underline.blue(
|
|
29156
29252
|
}
|
29157
29253
|
for (const [key, value] of Object.entries(tableToPk)) {
|
29158
29254
|
if (value.length > 1) {
|
29159
|
-
value.sort();
|
29160
29255
|
result[key].compositePrimaryKeys = {
|
29161
29256
|
[`${key}_${value.join("_")}_pk`]: {
|
29162
29257
|
columns: value,
|
@@ -33600,7 +33695,7 @@ We have encountered a collision between the index name on columns ${source_defau
|
|
33600
33695
|
onUpdate = true;
|
33601
33696
|
}
|
33602
33697
|
const newColumn = {
|
33603
|
-
default: columnDefault === null ? void 0 : /^-?[\d.]+(?:e-?\d+)?$/.test(columnDefault) && !columnType.startsWith(
|
33698
|
+
default: columnDefault === null ? void 0 : /^-?[\d.]+(?:e-?\d+)?$/.test(columnDefault) && !["decimal", "char", "varchar"].some((type) => columnType.startsWith(type)) ? Number(columnDefault) : isDefaultAnExpression ? clearDefaults(columnDefault, collation) : `'${columnDefault}'`,
|
33604
33699
|
autoincrement: isAutoincrement,
|
33605
33700
|
name: columnName,
|
33606
33701
|
type: changedType,
|
@@ -33839,7 +33934,7 @@ var init_cli = __esm({
|
|
33839
33934
|
extensionsFilters: literalType("postgis").array().optional(),
|
33840
33935
|
introspectCasing: casing,
|
33841
33936
|
breakpoints: booleanType().optional().default(true),
|
33842
|
-
|
33937
|
+
migrations: objectType({
|
33843
33938
|
prefix: prefix.optional().default("index")
|
33844
33939
|
}).optional()
|
33845
33940
|
}).passthrough();
|
@@ -34817,6 +34912,37 @@ var updateUpToV6 = (json) => {
|
|
34817
34912
|
enums
|
34818
34913
|
};
|
34819
34914
|
};
|
34915
|
+
var updateUpToV7 = (json) => {
|
34916
|
+
const schema4 = pgSchemaV6.parse(json);
|
34917
|
+
const tables = Object.fromEntries(
|
34918
|
+
Object.entries(schema4.tables).map((it) => {
|
34919
|
+
const table4 = it[1];
|
34920
|
+
const mappedIndexes = Object.fromEntries(
|
34921
|
+
Object.entries(table4.indexes).map((idx) => {
|
34922
|
+
const { columns, ...rest } = idx[1];
|
34923
|
+
const mappedColumns = columns.map((it2) => {
|
34924
|
+
return {
|
34925
|
+
expression: it2,
|
34926
|
+
isExpression: false,
|
34927
|
+
asc: true,
|
34928
|
+
nulls: "last",
|
34929
|
+
opClass: void 0
|
34930
|
+
};
|
34931
|
+
});
|
34932
|
+
return [idx[0], { columns: mappedColumns, with: {}, ...rest }];
|
34933
|
+
})
|
34934
|
+
);
|
34935
|
+
return [it[0], { ...table4, indexes: mappedIndexes }];
|
34936
|
+
})
|
34937
|
+
);
|
34938
|
+
return {
|
34939
|
+
...schema4,
|
34940
|
+
version: "7",
|
34941
|
+
dialect: "postgresql",
|
34942
|
+
sequences: {},
|
34943
|
+
tables
|
34944
|
+
};
|
34945
|
+
};
|
34820
34946
|
|
34821
34947
|
// src/cli/commands/sqliteIntrospect.ts
|
34822
34948
|
var import_hanji6 = __toESM(require_hanji());
|
@@ -35473,7 +35599,13 @@ var pushMySQLSchema = async (imports, drizzleInstance, databaseName) => {
|
|
35473
35599
|
};
|
35474
35600
|
};
|
35475
35601
|
var upPgSnapshot = (snapshot) => {
|
35476
|
-
|
35602
|
+
if (snapshot.version === "5") {
|
35603
|
+
return updateUpToV7(updateUpToV6(snapshot));
|
35604
|
+
}
|
35605
|
+
if (snapshot.version === "6") {
|
35606
|
+
return updateUpToV7(snapshot);
|
35607
|
+
}
|
35608
|
+
return snapshot;
|
35477
35609
|
};
|
35478
35610
|
// Annotate the CommonJS export names for ESM import in node:
|
35479
35611
|
0 && (module.exports = {
|