drizzle-kit 0.19.4-befd1c5 → 0.19.5-0b8d69c
Sign up to get free protection for your applications and to get access to all the features.
- package/index.cjs +531 -157
- package/package.json +2 -2
- package/utils.js +110 -25
package/index.cjs
CHANGED
@@ -4189,7 +4189,7 @@ var require_hanji = __commonJS({
|
|
4189
4189
|
}
|
4190
4190
|
};
|
4191
4191
|
exports.TaskTerminal = TaskTerminal;
|
4192
|
-
function
|
4192
|
+
function render7(view) {
|
4193
4193
|
const { stdin, stdout, closable } = (0, readline_1.prepareReadLine)();
|
4194
4194
|
if (view instanceof Prompt3) {
|
4195
4195
|
const terminal = new Terminal(view, stdin, stdout, closable);
|
@@ -4201,7 +4201,7 @@ var require_hanji = __commonJS({
|
|
4201
4201
|
closable.close();
|
4202
4202
|
return;
|
4203
4203
|
}
|
4204
|
-
exports.render =
|
4204
|
+
exports.render = render7;
|
4205
4205
|
function renderWithTask4(view, task) {
|
4206
4206
|
return __awaiter(this, void 0, void 0, function* () {
|
4207
4207
|
const terminal = new TaskTerminal(view, process.stdout);
|
@@ -4656,7 +4656,8 @@ var init_mysqlSchema = __esm({
|
|
4656
4656
|
columns: recordType(stringType(), column),
|
4657
4657
|
indexes: recordType(stringType(), stringType()),
|
4658
4658
|
foreignKeys: recordType(stringType(), stringType()),
|
4659
|
-
compositePrimaryKeys: recordType(stringType(), stringType())
|
4659
|
+
compositePrimaryKeys: recordType(stringType(), stringType()),
|
4660
|
+
uniqueConstraints: recordType(stringType(), stringType()).default({})
|
4660
4661
|
}).strict();
|
4661
4662
|
schemaSquashed = objectType({
|
4662
4663
|
version: literalType("5"),
|
@@ -5142,7 +5143,7 @@ var init_pgSchema = __esm({
|
|
5142
5143
|
});
|
5143
5144
|
|
5144
5145
|
// src/serializer/sqliteSchema.ts
|
5145
|
-
var index3, fk3, compositePK3, column3, tableV33, table3, dialect2, schemaHash3, schemaInternalV32, schemaInternalV42, latestVersion, schemaInternal2, schemaV32, schemaV42, schema3, tableSquashed3, schemaSquashed2, SQLiteSquasher, squashSqliteScheme, drySQLite, sqliteSchemaV3, sqliteSchemaV4, sqliteSchema, backwardCompatibleSqliteSchema;
|
5146
|
+
var index3, fk3, compositePK3, column3, tableV33, uniqueConstraint3, table3, dialect2, schemaHash3, schemaInternalV32, schemaInternalV42, latestVersion, schemaInternal2, schemaV32, schemaV42, schema3, tableSquashed3, schemaSquashed2, SQLiteSquasher, squashSqliteScheme, drySQLite, sqliteSchemaV3, sqliteSchemaV4, sqliteSchema, backwardCompatibleSqliteSchema;
|
5146
5147
|
var init_sqliteSchema = __esm({
|
5147
5148
|
"src/serializer/sqliteSchema.ts"() {
|
5148
5149
|
init_global();
|
@@ -5180,12 +5181,17 @@ var init_sqliteSchema = __esm({
|
|
5180
5181
|
indexes: recordType(stringType(), index3),
|
5181
5182
|
foreignKeys: recordType(stringType(), fk3)
|
5182
5183
|
}).strict();
|
5184
|
+
uniqueConstraint3 = objectType({
|
5185
|
+
name: stringType(),
|
5186
|
+
columns: stringType().array()
|
5187
|
+
}).strict();
|
5183
5188
|
table3 = objectType({
|
5184
5189
|
name: stringType(),
|
5185
5190
|
columns: recordType(stringType(), column3),
|
5186
5191
|
indexes: recordType(stringType(), index3),
|
5187
5192
|
foreignKeys: recordType(stringType(), fk3),
|
5188
|
-
compositePrimaryKeys: recordType(stringType(), compositePK3)
|
5193
|
+
compositePrimaryKeys: recordType(stringType(), compositePK3),
|
5194
|
+
uniqueConstraints: recordType(stringType(), uniqueConstraint3).default({})
|
5189
5195
|
}).strict();
|
5190
5196
|
dialect2 = enumType(["sqlite"]);
|
5191
5197
|
schemaHash3 = objectType({
|
@@ -5223,7 +5229,8 @@ var init_sqliteSchema = __esm({
|
|
5223
5229
|
columns: recordType(stringType(), column3),
|
5224
5230
|
indexes: recordType(stringType(), stringType()),
|
5225
5231
|
foreignKeys: recordType(stringType(), stringType()),
|
5226
|
-
compositePrimaryKeys: recordType(stringType(), stringType())
|
5232
|
+
compositePrimaryKeys: recordType(stringType(), stringType()),
|
5233
|
+
uniqueConstraints: recordType(stringType(), stringType()).default({})
|
5227
5234
|
}).strict();
|
5228
5235
|
schemaSquashed2 = objectType({
|
5229
5236
|
version: latestVersion,
|
@@ -5246,6 +5253,13 @@ var init_sqliteSchema = __esm({
|
|
5246
5253
|
});
|
5247
5254
|
return result;
|
5248
5255
|
},
|
5256
|
+
squashUnique: (unq) => {
|
5257
|
+
return `${unq.name};${unq.columns.join(",")}`;
|
5258
|
+
},
|
5259
|
+
unsquashUnique: (unq) => {
|
5260
|
+
const [name, columns] = unq.split(";");
|
5261
|
+
return { name, columns: columns.split(",") };
|
5262
|
+
},
|
5249
5263
|
squashFK: (fk4) => {
|
5250
5264
|
return `${fk4.name};${fk4.tableFrom};${fk4.columnsFrom.join(",")};${fk4.tableTo};${fk4.columnsTo.join(",")};${fk4.onUpdate ?? ""};${fk4.onDelete ?? ""}`;
|
5251
5265
|
},
|
@@ -5289,6 +5303,9 @@ var init_sqliteSchema = __esm({
|
|
5289
5303
|
const squashedPKs = mapValues(it[1].compositePrimaryKeys, (pk) => {
|
5290
5304
|
return SQLiteSquasher.squashPK(pk);
|
5291
5305
|
});
|
5306
|
+
const squashedUniqueConstraints = mapValues(it[1].uniqueConstraints, (unq) => {
|
5307
|
+
return SQLiteSquasher.squashUnique(unq);
|
5308
|
+
});
|
5292
5309
|
return [
|
5293
5310
|
it[0],
|
5294
5311
|
{
|
@@ -5296,7 +5313,8 @@ var init_sqliteSchema = __esm({
|
|
5296
5313
|
columns: it[1].columns,
|
5297
5314
|
indexes: squashedIndexes,
|
5298
5315
|
foreignKeys: squashedFKs,
|
5299
|
-
compositePrimaryKeys: squashedPKs
|
5316
|
+
compositePrimaryKeys: squashedPKs,
|
5317
|
+
uniqueConstraints: squashedUniqueConstraints
|
5300
5318
|
}
|
5301
5319
|
];
|
5302
5320
|
})
|
@@ -11368,6 +11386,71 @@ var init_mysqlImports = __esm({
|
|
11368
11386
|
}
|
11369
11387
|
});
|
11370
11388
|
|
11389
|
+
// src/cli/validations/outputs.ts
|
11390
|
+
var withStyle, outputs;
|
11391
|
+
var init_outputs = __esm({
|
11392
|
+
"src/cli/validations/outputs.ts"() {
|
11393
|
+
init_source();
|
11394
|
+
withStyle = {
|
11395
|
+
error: (str) => `${source_default.red(`${source_default.white.bgRed(" Invalid input ")} ${str}`)}`,
|
11396
|
+
warning: (str) => `${source_default.white.bgGray(" Warning ")} ${str}`,
|
11397
|
+
errorWarning: (str) => `${source_default.red(`${source_default.white.bgRed(" Warning ")} ${str}`)}`,
|
11398
|
+
fullWarning: (str) => `${source_default.black.bgYellow("[Warning]")} ${source_default.bold(str)}`
|
11399
|
+
};
|
11400
|
+
outputs = {
|
11401
|
+
studio: {
|
11402
|
+
drivers: (param) => withStyle.error(
|
11403
|
+
`"${param}" is not a valid driver. Available drivers: "pg", "mysql2", "better-sqlite", "libsql", "turso". You can read more about drizzle.config: https://orm.drizzle.team/kit-docs/config-reference`
|
11404
|
+
),
|
11405
|
+
noCredentials: () => withStyle.error(
|
11406
|
+
`You need to specify a "dbCredentials" param in you config. It will help drizzle to know how to query you database. You can read more about drizzle.config: https://orm.drizzle.team/kit-docs/config-reference`
|
11407
|
+
),
|
11408
|
+
noDriver: () => withStyle.error(
|
11409
|
+
`You need to specify a "driver" param in you config. It will help drizzle to know how to query you database. You can read more about drizzle.config: https://orm.drizzle.team/kit-docs/config-reference`
|
11410
|
+
)
|
11411
|
+
},
|
11412
|
+
common: {
|
11413
|
+
ambiguousParams: (command) => withStyle.error(
|
11414
|
+
`You can't use both --config and other cli options for ${command} command`
|
11415
|
+
),
|
11416
|
+
schema: (command) => withStyle.error(`"--schema" is a required field for ${command} command`),
|
11417
|
+
schemaConfig: (command) => withStyle.error(
|
11418
|
+
`"schema" is a required field in drizzle.config for ${command} command`
|
11419
|
+
)
|
11420
|
+
},
|
11421
|
+
postgres: {
|
11422
|
+
connection: {
|
11423
|
+
driver: () => withStyle.error(`Only "pg" is available options for "--driver"`),
|
11424
|
+
required: () => withStyle.error(
|
11425
|
+
`Either "connectionString" or "host", "database" are required for database connection`
|
11426
|
+
)
|
11427
|
+
}
|
11428
|
+
},
|
11429
|
+
mysql: {
|
11430
|
+
connection: {
|
11431
|
+
driver: () => withStyle.error(`Only "mysql2" is available options for "--driver"`),
|
11432
|
+
required: () => withStyle.error(
|
11433
|
+
`Either "connectionString" or "host", "database" are required for database connection`
|
11434
|
+
)
|
11435
|
+
}
|
11436
|
+
},
|
11437
|
+
sqlite: {
|
11438
|
+
connection: {
|
11439
|
+
driver: () => withStyle.error(
|
11440
|
+
`Either "turso", "libsql", "better-sqlite" are available options for "--driver"`
|
11441
|
+
),
|
11442
|
+
url: (driver) => withStyle.error(`"url" is a required option for driver "${driver}". You can read more about drizzle.config: https://orm.drizzle.team/kit-docs/config-reference`),
|
11443
|
+
authToken: (driver) => withStyle.error(
|
11444
|
+
`"authToken" is a required option for driver "${driver}". You can read more about drizzle.config: https://orm.drizzle.team/kit-docs/config-reference`
|
11445
|
+
)
|
11446
|
+
},
|
11447
|
+
introspect: {},
|
11448
|
+
push: {}
|
11449
|
+
}
|
11450
|
+
};
|
11451
|
+
}
|
11452
|
+
});
|
11453
|
+
|
11371
11454
|
// src/serializer/mysqlSerializer.ts
|
11372
11455
|
var mysqlSerializer_exports = {};
|
11373
11456
|
__export(mysqlSerializer_exports, {
|
@@ -11400,6 +11483,8 @@ var init_mysqlSerializer = __esm({
|
|
11400
11483
|
import_mysql_core3 = require("drizzle-orm/mysql-core");
|
11401
11484
|
import_drizzle_orm3 = require("drizzle-orm");
|
11402
11485
|
init_serializer();
|
11486
|
+
init_outputs();
|
11487
|
+
init_source();
|
11403
11488
|
dialect3 = new import_mysql_core2.MySqlDialect();
|
11404
11489
|
indexName = (tableName, columns) => {
|
11405
11490
|
return `${tableName}_${columns.join("_")}_index`;
|
@@ -11442,6 +11527,24 @@ var init_mysqlSerializer = __esm({
|
|
11442
11527
|
// : undefined,
|
11443
11528
|
};
|
11444
11529
|
if (column7.isUnique) {
|
11530
|
+
const existingUnique = uniqueConstraintObject[column7.uniqueName];
|
11531
|
+
if (typeof existingUnique !== "undefined") {
|
11532
|
+
console.log(
|
11533
|
+
`
|
11534
|
+
${withStyle.errorWarning(`We've found duplicated unique constraint names in ${source_default.underline.blue(
|
11535
|
+
tableName
|
11536
|
+
)} table.
|
11537
|
+
The unique constraint ${source_default.underline.blue(
|
11538
|
+
column7.uniqueName
|
11539
|
+
)} on the ${source_default.underline.blue(
|
11540
|
+
column7.name
|
11541
|
+
)} column is confilcting with a unique constraint name already defined for ${source_default.underline.blue(
|
11542
|
+
existingUnique.columns.join(",")
|
11543
|
+
)} columns
|
11544
|
+
`)}`
|
11545
|
+
);
|
11546
|
+
process.exit(1);
|
11547
|
+
}
|
11445
11548
|
uniqueConstraintObject[column7.uniqueName] = {
|
11446
11549
|
name: column7.uniqueName,
|
11447
11550
|
columns: [columnToSet.name]
|
@@ -11483,9 +11586,29 @@ var init_mysqlSerializer = __esm({
|
|
11483
11586
|
columnsObject[column7.name].notNull = true;
|
11484
11587
|
}
|
11485
11588
|
});
|
11486
|
-
uniqueConstraints.map((unq) => {
|
11589
|
+
uniqueConstraints == null ? void 0 : uniqueConstraints.map((unq) => {
|
11487
11590
|
const columnNames = unq.columns.map((c) => c.name);
|
11488
11591
|
const name = unq.name ?? (0, import_mysql_core2.uniqueKeyName)(table4, columnNames);
|
11592
|
+
const existingUnique = uniqueConstraintObject[name];
|
11593
|
+
if (typeof existingUnique !== "undefined") {
|
11594
|
+
console.log(
|
11595
|
+
`
|
11596
|
+
${withStyle.errorWarning(
|
11597
|
+
`We've found duplicated unique constraint names in ${source_default.underline.blue(
|
11598
|
+
tableName
|
11599
|
+
)} table.
|
11600
|
+
The unique constraint ${source_default.underline.blue(
|
11601
|
+
name
|
11602
|
+
)} on the ${source_default.underline.blue(
|
11603
|
+
columnNames.join(",")
|
11604
|
+
)} columns is confilcting with a unique constraint name already defined for ${source_default.underline.blue(
|
11605
|
+
existingUnique.columns.join(",")
|
11606
|
+
)} columns
|
11607
|
+
`
|
11608
|
+
)}`
|
11609
|
+
);
|
11610
|
+
process.exit(1);
|
11611
|
+
}
|
11489
11612
|
uniqueConstraintObject[name] = {
|
11490
11613
|
name: unq.name,
|
11491
11614
|
columns: columnNames
|
@@ -11618,7 +11741,7 @@ var init_mysqlSerializer = __esm({
|
|
11618
11741
|
onUpdate = true;
|
11619
11742
|
}
|
11620
11743
|
const newColumn = {
|
11621
|
-
default: columnDefault === null ? void 0 : /^-?[\d.]+(?:e-?\d+)?$/.test(columnDefault) ? Number(columnDefault) : isDefaultAnExpression ? clearDefaults(columnDefault, collation) : `'${columnDefault}'`,
|
11744
|
+
default: columnDefault === null ? void 0 : /^-?[\d.]+(?:e-?\d+)?$/.test(columnDefault) && !columnType.startsWith("decimal") ? Number(columnDefault) : isDefaultAnExpression ? clearDefaults(columnDefault, collation) : `'${columnDefault}'`,
|
11622
11745
|
autoincrement: isAutoincrement,
|
11623
11746
|
name: columnName,
|
11624
11747
|
type: changedType,
|
@@ -11635,7 +11758,8 @@ var init_mysqlSerializer = __esm({
|
|
11635
11758
|
},
|
11636
11759
|
compositePrimaryKeys: {},
|
11637
11760
|
indexes: {},
|
11638
|
-
foreignKeys: {}
|
11761
|
+
foreignKeys: {},
|
11762
|
+
uniqueConstraints: {}
|
11639
11763
|
};
|
11640
11764
|
} else {
|
11641
11765
|
result[tableName].columns[columnName] = newColumn;
|
@@ -11734,14 +11858,27 @@ var init_mysqlSerializer = __esm({
|
|
11734
11858
|
if (progressCallback) {
|
11735
11859
|
progressCallback("indexes", indexesCount, "fetching");
|
11736
11860
|
}
|
11737
|
-
if (
|
11738
|
-
tableInResult.
|
11861
|
+
if (isUnique) {
|
11862
|
+
if (typeof tableInResult.uniqueConstraints[constraintName] !== "undefined") {
|
11863
|
+
tableInResult.uniqueConstraints[constraintName].columns.push(
|
11864
|
+
columnName
|
11865
|
+
);
|
11866
|
+
} else {
|
11867
|
+
tableInResult.uniqueConstraints[constraintName] = {
|
11868
|
+
name: constraintName,
|
11869
|
+
columns: [columnName]
|
11870
|
+
};
|
11871
|
+
}
|
11739
11872
|
} else {
|
11740
|
-
tableInResult.indexes[constraintName]
|
11741
|
-
|
11742
|
-
|
11743
|
-
|
11744
|
-
|
11873
|
+
if (typeof tableInResult.indexes[constraintName] !== "undefined") {
|
11874
|
+
tableInResult.indexes[constraintName].columns.push(columnName);
|
11875
|
+
} else {
|
11876
|
+
tableInResult.indexes[constraintName] = {
|
11877
|
+
name: constraintName,
|
11878
|
+
columns: [columnName],
|
11879
|
+
isUnique
|
11880
|
+
};
|
11881
|
+
}
|
11745
11882
|
}
|
11746
11883
|
}
|
11747
11884
|
if (progressCallback) {
|
@@ -11818,6 +11955,8 @@ var init_pgSerializer = __esm({
|
|
11818
11955
|
import_drizzle_orm5 = require("drizzle-orm");
|
11819
11956
|
import_drizzle_orm6 = require("drizzle-orm");
|
11820
11957
|
init_serializer();
|
11958
|
+
init_source();
|
11959
|
+
init_outputs();
|
11821
11960
|
dialect4 = new import_pg_core2.PgDialect();
|
11822
11961
|
indexName2 = (tableName, columns) => {
|
11823
11962
|
return `${tableName}_${columns.join("_")}_index`;
|
@@ -11851,6 +11990,24 @@ var init_pgSerializer = __esm({
|
|
11851
11990
|
notNull
|
11852
11991
|
};
|
11853
11992
|
if (column7.isUnique) {
|
11993
|
+
const existingUnique = uniqueConstraintObject[column7.uniqueName];
|
11994
|
+
if (typeof existingUnique !== "undefined") {
|
11995
|
+
console.log(
|
11996
|
+
`
|
11997
|
+
${withStyle.errorWarning(`We've found duplicated unique constraint names in ${source_default.underline.blue(
|
11998
|
+
tableName
|
11999
|
+
)} table.
|
12000
|
+
The unique constraint ${source_default.underline.blue(
|
12001
|
+
column7.uniqueName
|
12002
|
+
)} on the ${source_default.underline.blue(
|
12003
|
+
column7.name
|
12004
|
+
)} column is confilcting with a unique constraint name already defined for ${source_default.underline.blue(
|
12005
|
+
existingUnique.columns.join(",")
|
12006
|
+
)} columns
|
12007
|
+
`)}`
|
12008
|
+
);
|
12009
|
+
process.exit(1);
|
12010
|
+
}
|
11854
12011
|
uniqueConstraintObject[column7.uniqueName] = {
|
11855
12012
|
name: column7.uniqueName,
|
11856
12013
|
nullsNotDistinct: column7.uniqueType === "not distinct",
|
@@ -11891,9 +12048,27 @@ var init_pgSerializer = __esm({
|
|
11891
12048
|
columns: columnNames
|
11892
12049
|
};
|
11893
12050
|
});
|
11894
|
-
uniqueConstraints.map((unq) => {
|
12051
|
+
uniqueConstraints == null ? void 0 : uniqueConstraints.map((unq) => {
|
11895
12052
|
const columnNames = unq.columns.map((c) => c.name);
|
11896
12053
|
const name = unq.name ?? (0, import_pg_core2.uniqueKeyName)(table4, columnNames);
|
12054
|
+
const existingUnique = uniqueConstraintObject[name];
|
12055
|
+
if (typeof existingUnique !== "undefined") {
|
12056
|
+
console.log(
|
12057
|
+
`
|
12058
|
+
${withStyle.errorWarning(`We've found duplicated unique constraint names in ${source_default.underline.blue(
|
12059
|
+
tableName
|
12060
|
+
)} table.
|
12061
|
+
The unique constraint ${source_default.underline.blue(
|
12062
|
+
name
|
12063
|
+
)} on the ${source_default.underline.blue(
|
12064
|
+
columnNames.join(",")
|
12065
|
+
)} columns is confilcting with a unique constraint name already defined for ${source_default.underline.blue(
|
12066
|
+
existingUnique.columns.join(",")
|
12067
|
+
)} columns
|
12068
|
+
`)}`
|
12069
|
+
);
|
12070
|
+
process.exit(1);
|
12071
|
+
}
|
11897
12072
|
uniqueConstraintObject[name] = {
|
11898
12073
|
name: unq.name,
|
11899
12074
|
nullsNotDistinct: unq.nullsNotDistinct,
|
@@ -12009,6 +12184,7 @@ var init_pgSerializer = __esm({
|
|
12009
12184
|
const indexToReturn = {};
|
12010
12185
|
const foreignKeysToReturn = {};
|
12011
12186
|
const primaryKeys = {};
|
12187
|
+
const uniqueConstrains = {};
|
12012
12188
|
const tableResponse = await db.query(
|
12013
12189
|
`SELECT a.attrelid::regclass::text, a.attname, is_nullable, a.attndims as array_dimensions
|
12014
12190
|
, CASE WHEN a.atttypid = ANY ('{int,int8,int2}'::regtype[])
|
@@ -12102,6 +12278,22 @@ var init_pgSerializer = __esm({
|
|
12102
12278
|
...new Set(foreignKeysToReturn[foreignKeyName].columnsTo)
|
12103
12279
|
];
|
12104
12280
|
}
|
12281
|
+
const uniqueConstrainsRows = tableConstraints.rows.filter(
|
12282
|
+
(mapRow) => mapRow.constraint_type === "UNIQUE"
|
12283
|
+
);
|
12284
|
+
for (const unqs of uniqueConstrainsRows) {
|
12285
|
+
const columnName = unqs.column_name;
|
12286
|
+
const constraintName = unqs.constraint_name;
|
12287
|
+
if (typeof uniqueConstrains[constraintName] !== "undefined") {
|
12288
|
+
uniqueConstrains[constraintName].columns.push(columnName);
|
12289
|
+
} else {
|
12290
|
+
uniqueConstrains[constraintName] = {
|
12291
|
+
columns: [columnName],
|
12292
|
+
nullsNotDistinct: false,
|
12293
|
+
name: constraintName
|
12294
|
+
};
|
12295
|
+
}
|
12296
|
+
}
|
12105
12297
|
for (const columnResponse of tableResponse.rows) {
|
12106
12298
|
const columnName = columnResponse.attname;
|
12107
12299
|
const columnAdditionalDT = columnResponse.additional_dt;
|
@@ -12127,9 +12319,6 @@ var init_pgSerializer = __esm({
|
|
12127
12319
|
columns: cprimaryKey.map((c) => c.column_name)
|
12128
12320
|
};
|
12129
12321
|
}
|
12130
|
-
const uniqueKey = tableConstraints.rows.filter(
|
12131
|
-
(mapRow) => columnName === mapRow.column_name && mapRow.constraint_type === "UNIQUE"
|
12132
|
-
);
|
12133
12322
|
const defaultValue = defaultForColumn(columnResponse);
|
12134
12323
|
const isSerial = columnType === "serial";
|
12135
12324
|
let columnTypeMapped = columnType;
|
@@ -12177,10 +12366,25 @@ var init_pgSerializer = __esm({
|
|
12177
12366
|
t.relname,
|
12178
12367
|
i.relname;`
|
12179
12368
|
);
|
12369
|
+
const dbIndexFromConstraint = await db.query(
|
12370
|
+
`SELECT
|
12371
|
+
idx.indexrelname AS index_name,
|
12372
|
+
idx.relname AS table_name,
|
12373
|
+
con.conname,
|
12374
|
+
CASE WHEN con.conname IS NOT NULL THEN 1 ELSE 0 END AS generated_by_constraint
|
12375
|
+
FROM
|
12376
|
+
pg_stat_user_indexes idx
|
12377
|
+
LEFT JOIN
|
12378
|
+
pg_constraint con ON con.conindid = idx.indexrelid
|
12379
|
+
WHERE idx.relname = '${tableName}';`
|
12380
|
+
);
|
12381
|
+
const idxsInConsteraint = dbIndexFromConstraint.rows.filter((it) => it.generated_by_constraint === 1).map((it) => it.index_name);
|
12180
12382
|
for (const dbIndex of dbIndexes.rows) {
|
12181
12383
|
const indexName4 = dbIndex.index_name;
|
12182
12384
|
const indexColumnName = dbIndex.column_name;
|
12183
12385
|
const indexIsUnique = dbIndex.is_unique;
|
12386
|
+
if (idxsInConsteraint.includes(indexName4))
|
12387
|
+
continue;
|
12184
12388
|
if (typeof indexToReturn[indexName4] !== "undefined") {
|
12185
12389
|
indexToReturn[indexName4].columns.push(indexColumnName);
|
12186
12390
|
} else {
|
@@ -12201,7 +12405,8 @@ var init_pgSerializer = __esm({
|
|
12201
12405
|
columns: columnToReturn,
|
12202
12406
|
indexes: indexToReturn,
|
12203
12407
|
foreignKeys: foreignKeysToReturn,
|
12204
|
-
compositePrimaryKeys: primaryKeys
|
12408
|
+
compositePrimaryKeys: primaryKeys,
|
12409
|
+
uniqueConstraints: uniqueConstrains
|
12205
12410
|
};
|
12206
12411
|
} catch (e) {
|
12207
12412
|
rej(e);
|
@@ -12396,6 +12601,8 @@ var init_sqliteSerializer = __esm({
|
|
12396
12601
|
import_drizzle_orm9 = require("drizzle-orm");
|
12397
12602
|
import_sqlite_core2 = require("drizzle-orm/sqlite-core");
|
12398
12603
|
init_serializer();
|
12604
|
+
init_outputs();
|
12605
|
+
init_source();
|
12399
12606
|
dialect5 = new import_sqlite_core2.SQLiteSyncDialect();
|
12400
12607
|
generateSqliteSnapshot = (tables, enums) => {
|
12401
12608
|
const result = {};
|
@@ -12404,12 +12611,14 @@ var init_sqliteSerializer = __esm({
|
|
12404
12611
|
const indexesObject = {};
|
12405
12612
|
const foreignKeysObject = {};
|
12406
12613
|
const primaryKeysObject = {};
|
12614
|
+
const uniqueConstraintObject = {};
|
12407
12615
|
const {
|
12408
12616
|
name: tableName,
|
12409
12617
|
columns,
|
12410
12618
|
indexes,
|
12411
12619
|
foreignKeys: tableForeignKeys,
|
12412
|
-
primaryKeys
|
12620
|
+
primaryKeys,
|
12621
|
+
uniqueConstraints
|
12413
12622
|
} = (0, import_sqlite_core2.getTableConfig)(table4);
|
12414
12623
|
columns.forEach((column7) => {
|
12415
12624
|
const notNull = column7.notNull;
|
@@ -12429,6 +12638,31 @@ var init_sqliteSerializer = __esm({
|
|
12429
12638
|
}
|
12430
12639
|
}
|
12431
12640
|
columnsObject[column7.name] = columnToSet;
|
12641
|
+
if (column7.isUnique) {
|
12642
|
+
const existingUnique = indexesObject[column7.uniqueName];
|
12643
|
+
if (typeof existingUnique !== "undefined") {
|
12644
|
+
console.log(
|
12645
|
+
`
|
12646
|
+
${withStyle.errorWarning(`We've found duplicated unique constraint names in ${source_default.underline.blue(
|
12647
|
+
tableName
|
12648
|
+
)} table.
|
12649
|
+
The unique constraint ${source_default.underline.blue(
|
12650
|
+
column7.uniqueName
|
12651
|
+
)} on the ${source_default.underline.blue(
|
12652
|
+
column7.name
|
12653
|
+
)} column is confilcting with a unique constraint name already defined for ${source_default.underline.blue(
|
12654
|
+
existingUnique.columns.join(",")
|
12655
|
+
)} columns
|
12656
|
+
`)}`
|
12657
|
+
);
|
12658
|
+
process.exit(1);
|
12659
|
+
}
|
12660
|
+
indexesObject[column7.uniqueName] = {
|
12661
|
+
name: column7.uniqueName,
|
12662
|
+
columns: [columnToSet.name],
|
12663
|
+
isUnique: true
|
12664
|
+
};
|
12665
|
+
}
|
12432
12666
|
});
|
12433
12667
|
const foreignKeys = tableForeignKeys.map((fk4) => {
|
12434
12668
|
const name = fk4.getName();
|
@@ -12476,6 +12710,35 @@ var init_sqliteSerializer = __esm({
|
|
12476
12710
|
where
|
12477
12711
|
};
|
12478
12712
|
});
|
12713
|
+
uniqueConstraints == null ? void 0 : uniqueConstraints.map((unq) => {
|
12714
|
+
const columnNames = unq.columns.map((c) => c.name);
|
12715
|
+
const name = unq.name ?? (0, import_sqlite_core2.uniqueKeyName)(table4, columnNames);
|
12716
|
+
const existingUnique = indexesObject[name];
|
12717
|
+
if (typeof existingUnique !== "undefined") {
|
12718
|
+
console.log(
|
12719
|
+
`
|
12720
|
+
${withStyle.errorWarning(
|
12721
|
+
`We've found duplicated unique constraint names in ${source_default.underline.blue(
|
12722
|
+
tableName
|
12723
|
+
)} table.
|
12724
|
+
The unique constraint ${source_default.underline.blue(
|
12725
|
+
name
|
12726
|
+
)} on the ${source_default.underline.blue(
|
12727
|
+
columnNames.join(",")
|
12728
|
+
)} columns is confilcting with a unique constraint name already defined for ${source_default.underline.blue(
|
12729
|
+
existingUnique.columns.join(",")
|
12730
|
+
)} columns
|
12731
|
+
`
|
12732
|
+
)}`
|
12733
|
+
);
|
12734
|
+
process.exit(1);
|
12735
|
+
}
|
12736
|
+
indexesObject[name] = {
|
12737
|
+
name: unq.name,
|
12738
|
+
columns: columnNames,
|
12739
|
+
isUnique: true
|
12740
|
+
};
|
12741
|
+
});
|
12479
12742
|
primaryKeys.forEach((it) => {
|
12480
12743
|
if (it.columns.length > 1) {
|
12481
12744
|
primaryKeysObject[it.getName()] = {
|
@@ -12490,7 +12753,8 @@ var init_sqliteSerializer = __esm({
|
|
12490
12753
|
columns: columnsObject,
|
12491
12754
|
indexes: indexesObject,
|
12492
12755
|
foreignKeys: foreignKeysObject,
|
12493
|
-
compositePrimaryKeys: primaryKeysObject
|
12756
|
+
compositePrimaryKeys: primaryKeysObject,
|
12757
|
+
uniqueConstraints: uniqueConstraintObject
|
12494
12758
|
};
|
12495
12759
|
}
|
12496
12760
|
return {
|
@@ -12574,7 +12838,8 @@ var init_sqliteSerializer = __esm({
|
|
12574
12838
|
},
|
12575
12839
|
compositePrimaryKeys: {},
|
12576
12840
|
indexes: {},
|
12577
|
-
foreignKeys: {}
|
12841
|
+
foreignKeys: {},
|
12842
|
+
uniqueConstraints: {}
|
12578
12843
|
};
|
12579
12844
|
} else {
|
12580
12845
|
result[tableName].columns[columnName] = newColumn;
|
@@ -12659,7 +12924,7 @@ FROM sqlite_master AS m,
|
|
12659
12924
|
pragma_index_list(m.name) AS il,
|
12660
12925
|
pragma_index_info(il.name) AS ii
|
12661
12926
|
WHERE
|
12662
|
-
m.type = 'table'
|
12927
|
+
m.type = 'table';`
|
12663
12928
|
);
|
12664
12929
|
for (const idxRow of idxs) {
|
12665
12930
|
const tableName = idxRow.tableName;
|
@@ -14630,7 +14895,7 @@ ${sql}
|
|
14630
14895
|
});
|
14631
14896
|
|
14632
14897
|
// src/sqlgenerator.ts
|
14633
|
-
var pgNativeTypes, isPgNativeType, Convertor, PgCreateTableConvertor, MySqlCreateTableConvertor, SQLiteCreateTableConvertor, PgAlterTableAddUniqueConstraintConvertor, PgAlterTableDropUniqueConstraintConvertor, MySQLAlterTableAddUniqueConstraintConvertor, MySQLAlterTableDropUniqueConstraintConvertor, CreateTypeEnumConvertor, AlterTypeAddValueConvertor, PgDropTableConvertor, MySQLDropTableConvertor, SQLiteDropTableConvertor, PgRenameTableConvertor, SqliteRenameTableConvertor, MySqlRenameTableConvertor, PgAlterTableRenameColumnConvertor, MySqlAlterTableRenameColumnConvertor, SQLiteAlterTableRenameColumnConvertor, PgAlterTableDropColumnConvertor, MySqlAlterTableDropColumnConvertor, SQLiteAlterTableDropColumnConvertor, PgAlterTableAddColumnConvertor, MySqlAlterTableAddColumnConvertor, SQLiteAlterTableAddColumnConvertor, PgAlterTableAlterColumnSetTypeConvertor, SQLiteAlterTableAlterColumnSetTypeConvertor, PgAlterTableAlterColumnSetDefaultConvertor, SqliteAlterTableAlterColumnSetDefaultConvertor, PgAlterTableAlterColumnDropDefaultConvertor, MySqlAlterTableAddPk, MySqlAlterTableDropPk, MySqlModifyColumn, SqliteAlterTableAlterColumnDropDefaultConvertor, PgAlterTableCreateCompositePrimaryKeyConvertor, PgAlterTableDeleteCompositePrimaryKeyConvertor, PgAlterTableAlterCompositePrimaryKeyConvertor, MySqlAlterTableCreateCompositePrimaryKeyConvertor, MySqlAlterTableDeleteCompositePrimaryKeyConvertor, MySqlAlterTableAlterCompositePrimaryKeyConvertor, SqliteAlterTableCreateCompositePrimaryKeyConvertor, SqliteAlterTableDeleteCompositePrimaryKeyConvertor, SqliteAlterTableAlterCompositePrimaryKeyConvertor, PgAlterTableAlterColumnSetPrimaryKeyConvertor, PgAlterTableAlterColumnDropPrimaryKeyConvertor, PgAlterTableAlterColumnSetNotNullConvertor, SqliteAlterTableAlterColumnSetNotNullConvertor, SqliteAlterTableAlterColumnSetAutoincrementConvertor, SqliteAlterTableAlterColumnDropAutoincrementConvertor, PgAlterTableAlterColumnDropNotNullConvertor, SqliteAlterTableAlterColumnDropNotNullConvertor, PgCreateForeignKeyConvertor, SqliteCreateForeignKeyConvertor, MySqlCreateForeignKeyConvertor, PgAlterForeignKeyConvertor, SqliteAlterForeignKeyConvertor, PgDeleteForeignKeyConvertor, SqliteDeleteForeignKeyConvertor, MySqlDeleteForeignKeyConvertor, CreatePgIndexConvertor, CreateMySqlIndexConvertor, CreateSqliteIndexConvertor, PgDropIndexConvertor, PgCreateSchemaConvertor, PgRenameSchemaConvertor, PgDropSchemaConvertor, PgAlterTableSetSchemaConvertor, PgAlterTableSetNewSchemaConvertor, PgAlterTableRemoveFromSchemaConvertor, SqliteDropIndexConvertor, MysqlCreateSchemaConvertor, MysqlDropSchemaConvertor, MysqlAlterTableSetSchemaConvertor, MysqlAlterTableSetNewSchemaConvertor, MysqlAlterTableRemoveFromSchemaConvertor, MySqlDropIndexConvertor, convertors, fromJson;
|
14898
|
+
var pgNativeTypes, isPgNativeType, Convertor, PgCreateTableConvertor, MySqlCreateTableConvertor, SQLiteCreateTableConvertor, PgAlterTableAddUniqueConstraintConvertor, PgAlterTableDropUniqueConstraintConvertor, MySQLAlterTableAddUniqueConstraintConvertor, MySQLAlterTableDropUniqueConstraintConvertor, SQLiteAlterTableAddUniqueConstraintConvertor, SQLiteAlterTableDropUniqueConstraintConvertor, CreateTypeEnumConvertor, AlterTypeAddValueConvertor, PgDropTableConvertor, MySQLDropTableConvertor, SQLiteDropTableConvertor, PgRenameTableConvertor, SqliteRenameTableConvertor, MySqlRenameTableConvertor, PgAlterTableRenameColumnConvertor, MySqlAlterTableRenameColumnConvertor, SQLiteAlterTableRenameColumnConvertor, PgAlterTableDropColumnConvertor, MySqlAlterTableDropColumnConvertor, SQLiteAlterTableDropColumnConvertor, PgAlterTableAddColumnConvertor, MySqlAlterTableAddColumnConvertor, SQLiteAlterTableAddColumnConvertor, PgAlterTableAlterColumnSetTypeConvertor, SQLiteAlterTableAlterColumnSetTypeConvertor, PgAlterTableAlterColumnSetDefaultConvertor, SqliteAlterTableAlterColumnSetDefaultConvertor, PgAlterTableAlterColumnDropDefaultConvertor, MySqlAlterTableAddPk, MySqlAlterTableDropPk, MySqlModifyColumn, SqliteAlterTableAlterColumnDropDefaultConvertor, PgAlterTableCreateCompositePrimaryKeyConvertor, PgAlterTableDeleteCompositePrimaryKeyConvertor, PgAlterTableAlterCompositePrimaryKeyConvertor, MySqlAlterTableCreateCompositePrimaryKeyConvertor, MySqlAlterTableDeleteCompositePrimaryKeyConvertor, MySqlAlterTableAlterCompositePrimaryKeyConvertor, SqliteAlterTableCreateCompositePrimaryKeyConvertor, SqliteAlterTableDeleteCompositePrimaryKeyConvertor, SqliteAlterTableAlterCompositePrimaryKeyConvertor, PgAlterTableAlterColumnSetPrimaryKeyConvertor, PgAlterTableAlterColumnDropPrimaryKeyConvertor, PgAlterTableAlterColumnSetNotNullConvertor, SqliteAlterTableAlterColumnSetNotNullConvertor, SqliteAlterTableAlterColumnSetAutoincrementConvertor, SqliteAlterTableAlterColumnDropAutoincrementConvertor, PgAlterTableAlterColumnDropNotNullConvertor, SqliteAlterTableAlterColumnDropNotNullConvertor, PgCreateForeignKeyConvertor, SqliteCreateForeignKeyConvertor, MySqlCreateForeignKeyConvertor, PgAlterForeignKeyConvertor, SqliteAlterForeignKeyConvertor, PgDeleteForeignKeyConvertor, SqliteDeleteForeignKeyConvertor, MySqlDeleteForeignKeyConvertor, CreatePgIndexConvertor, CreateMySqlIndexConvertor, CreateSqliteIndexConvertor, PgDropIndexConvertor, PgCreateSchemaConvertor, PgRenameSchemaConvertor, PgDropSchemaConvertor, PgAlterTableSetSchemaConvertor, PgAlterTableSetNewSchemaConvertor, PgAlterTableRemoveFromSchemaConvertor, SqliteDropIndexConvertor, MysqlCreateSchemaConvertor, MysqlDropSchemaConvertor, MysqlAlterTableSetSchemaConvertor, MysqlAlterTableSetNewSchemaConvertor, MysqlAlterTableRemoveFromSchemaConvertor, MySqlDropIndexConvertor, convertors, fromJson;
|
14634
14899
|
var init_sqlgenerator = __esm({
|
14635
14900
|
"src/sqlgenerator.ts"() {
|
14636
14901
|
init_migrate();
|
@@ -14701,9 +14966,9 @@ var init_sqlgenerator = __esm({
|
|
14701
14966
|
const primaryKeyStatement = column7.primaryKey ? " PRIMARY KEY" : "";
|
14702
14967
|
const notNullStatement = column7.notNull ? " NOT NULL" : "";
|
14703
14968
|
const defaultStatement = column7.default !== void 0 ? ` DEFAULT ${column7.default}` : "";
|
14704
|
-
const
|
14969
|
+
const uniqueConstraint4 = column7.isUnique ? ` CONSTRAINT "${column7.uniqueName}" UNIQUE${column7.nullsNotDistinct ? " NULLS NOT DISTINCT" : ""}` : "";
|
14705
14970
|
const type = isPgNativeType(column7.type) ? column7.type : `"${column7.type}"`;
|
14706
|
-
statement += ` "${column7.name}" ${type}${primaryKeyStatement}${defaultStatement}${notNullStatement}${
|
14971
|
+
statement += ` "${column7.name}" ${type}${primaryKeyStatement}${defaultStatement}${notNullStatement}${uniqueConstraint4}`;
|
14707
14972
|
statement += i === columns.length - 1 ? "" : ",\n";
|
14708
14973
|
}
|
14709
14974
|
if (typeof compositePKs !== "undefined" && compositePKs.length > 0) {
|
@@ -14712,10 +14977,10 @@ var init_sqlgenerator = __esm({
|
|
14712
14977
|
statement += ` CONSTRAINT ${st.compositePkName} PRIMARY KEY("${compositePK4.columns.join(`","`)}")`;
|
14713
14978
|
}
|
14714
14979
|
if (typeof uniqueConstraints !== "undefined" && uniqueConstraints.length > 0) {
|
14715
|
-
for (const
|
14980
|
+
for (const uniqueConstraint4 of uniqueConstraints) {
|
14716
14981
|
statement += ",\n";
|
14717
|
-
const unsquashedUnique = PgSquasher.unsquashUnique(
|
14718
|
-
statement += ` CONSTRAINT ${unsquashedUnique.name} UNIQUE("${unsquashedUnique.columns.join(`","`)}")`;
|
14982
|
+
const unsquashedUnique = PgSquasher.unsquashUnique(uniqueConstraint4);
|
14983
|
+
statement += ` CONSTRAINT "${unsquashedUnique.name}" UNIQUE${unsquashedUnique.nullsNotDistinct ? " NULLS NOT DISTINCT" : ""}("${unsquashedUnique.columns.join(`","`)}")`;
|
14719
14984
|
}
|
14720
14985
|
}
|
14721
14986
|
statement += `
|
@@ -14748,13 +15013,13 @@ var init_sqlgenerator = __esm({
|
|
14748
15013
|
if (typeof compositePKs !== "undefined" && compositePKs.length > 0) {
|
14749
15014
|
statement += ",\n";
|
14750
15015
|
const compositePK4 = MySqlSquasher.unsquashPK(compositePKs[0]);
|
14751
|
-
statement += ` CONSTRAINT
|
15016
|
+
statement += ` CONSTRAINT \`${st.compositePkName}\` PRIMARY KEY(\`${compositePK4.columns.join(`\`,\``)}\`)`;
|
14752
15017
|
}
|
14753
15018
|
if (typeof uniqueConstraints !== "undefined" && uniqueConstraints.length > 0) {
|
14754
|
-
for (const
|
15019
|
+
for (const uniqueConstraint4 of uniqueConstraints) {
|
14755
15020
|
statement += ",\n";
|
14756
|
-
const unsquashedUnique = MySqlSquasher.unsquashUnique(
|
14757
|
-
statement += ` CONSTRAINT
|
15021
|
+
const unsquashedUnique = MySqlSquasher.unsquashUnique(uniqueConstraint4);
|
15022
|
+
statement += ` CONSTRAINT \`${unsquashedUnique.name}\` UNIQUE(\`${unsquashedUnique.columns.join(`\`,\``)}\`)`;
|
14758
15023
|
}
|
14759
15024
|
}
|
14760
15025
|
statement += `
|
@@ -14769,22 +15034,29 @@ var init_sqlgenerator = __esm({
|
|
14769
15034
|
return statement.type === "sqlite_create_table" && dialect6 === "sqlite";
|
14770
15035
|
}
|
14771
15036
|
convert(st) {
|
14772
|
-
const {
|
15037
|
+
const {
|
15038
|
+
tableName,
|
15039
|
+
columns,
|
15040
|
+
referenceData,
|
15041
|
+
compositePKs,
|
15042
|
+
uniqueConstraints
|
15043
|
+
} = st;
|
14773
15044
|
let statement = "";
|
14774
|
-
statement += `CREATE TABLE \`${tableName}\` (
|
15045
|
+
statement += `CREATE TABLE \`${tableName}\` (
|
15046
|
+
`;
|
14775
15047
|
for (let i = 0; i < columns.length; i++) {
|
14776
15048
|
const column7 = columns[i];
|
14777
15049
|
const primaryKeyStatement = column7.primaryKey ? " PRIMARY KEY" : "";
|
14778
15050
|
const notNullStatement = column7.notNull ? " NOT NULL" : "";
|
14779
15051
|
const defaultStatement = column7.default !== void 0 ? ` DEFAULT ${column7.default}` : "";
|
14780
15052
|
const autoincrementStatement = column7.autoincrement ? " AUTOINCREMENT" : "";
|
14781
|
-
statement += "
|
15053
|
+
statement += " ";
|
14782
15054
|
statement += `\`${column7.name}\` ${column7.type}${primaryKeyStatement}${autoincrementStatement}${defaultStatement}${notNullStatement}`;
|
14783
|
-
statement += "
|
15055
|
+
statement += i === columns.length - 1 ? "" : ",\n";
|
14784
15056
|
}
|
14785
15057
|
compositePKs.forEach((it) => {
|
14786
|
-
statement += "
|
14787
|
-
statement += `PRIMARY KEY(${it.map((it2) => `\`${it2}\``).join(", ")})
|
15058
|
+
statement += ",\n ";
|
15059
|
+
statement += `PRIMARY KEY(${it.map((it2) => `\`${it2}\``).join(", ")})`;
|
14788
15060
|
});
|
14789
15061
|
for (let i = 0; i < referenceData.length; i++) {
|
14790
15062
|
const referenceAsString = referenceData[i];
|
@@ -14801,11 +15073,17 @@ var init_sqlgenerator = __esm({
|
|
14801
15073
|
const onUpdateStatement = onUpdate ? ` ON UPDATE ${onUpdate}` : "";
|
14802
15074
|
const fromColumnsString = columnsFrom.map((it) => `\`${it}\``).join(",");
|
14803
15075
|
const toColumnsString = columnsTo.map((it) => `\`${it}\``).join(",");
|
15076
|
+
statement += ",";
|
14804
15077
|
statement += "\n ";
|
14805
15078
|
statement += `FOREIGN KEY (${fromColumnsString}) REFERENCES \`${tableTo}\`(${toColumnsString})${onUpdateStatement}${onDeleteStatement}`;
|
14806
|
-
statement += ",";
|
14807
15079
|
}
|
14808
|
-
|
15080
|
+
if (typeof uniqueConstraints !== "undefined" && uniqueConstraints.length > 0) {
|
15081
|
+
for (const uniqueConstraint4 of uniqueConstraints) {
|
15082
|
+
statement += ",\n";
|
15083
|
+
const unsquashedUnique = MySqlSquasher.unsquashUnique(uniqueConstraint4);
|
15084
|
+
statement += ` CONSTRAINT ${unsquashedUnique.name} UNIQUE(\`${unsquashedUnique.columns.join(`\`,\``)}\`)`;
|
15085
|
+
}
|
15086
|
+
}
|
14809
15087
|
statement += `
|
14810
15088
|
`;
|
14811
15089
|
statement += `);`;
|
@@ -14821,7 +15099,7 @@ var init_sqlgenerator = __esm({
|
|
14821
15099
|
convert(statement) {
|
14822
15100
|
const unsquashed = PgSquasher.unsquashUnique(statement.data);
|
14823
15101
|
const tableNameWithSchema = statement.schema ? `"${statement.schema}"."${statement.tableName}"` : `"${statement.tableName}"`;
|
14824
|
-
return `ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT "${unsquashed.name}" UNIQUE("${unsquashed.columns.join('","')}");`;
|
15102
|
+
return `ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT "${unsquashed.name}" UNIQUE${unsquashed.nullsNotDistinct ? " NULLS NOT DISTINCT" : ""}("${unsquashed.columns.join('","')}");`;
|
14825
15103
|
}
|
14826
15104
|
};
|
14827
15105
|
PgAlterTableDropUniqueConstraintConvertor = class extends Convertor {
|
@@ -14854,6 +15132,32 @@ var init_sqlgenerator = __esm({
|
|
14854
15132
|
return `ALTER TABLE ${tableNameWithSchema} DROP CONSTRAINT \`${unsquashed.name}\`;`;
|
14855
15133
|
}
|
14856
15134
|
};
|
15135
|
+
SQLiteAlterTableAddUniqueConstraintConvertor = class extends Convertor {
|
15136
|
+
can(statement, dialect6) {
|
15137
|
+
return statement.type === "create_unique_constraint" && dialect6 === "sqlite";
|
15138
|
+
}
|
15139
|
+
convert(statement) {
|
15140
|
+
return `/*
|
15141
|
+
SQLite does not support "Adding unique constraint to an existing table" out of the box, we do not generate automatic migration for that, so it has to be done manually
|
15142
|
+
Please refer to: https://www.techonthenet.com/sqlite/unique.php
|
15143
|
+
|
15144
|
+
Due to that we don't generate migration automatically and it has to be done manually
|
15145
|
+
*/`;
|
15146
|
+
}
|
15147
|
+
};
|
15148
|
+
SQLiteAlterTableDropUniqueConstraintConvertor = class extends Convertor {
|
15149
|
+
can(statement, dialect6) {
|
15150
|
+
return statement.type === "delete_unique_constraint" && dialect6 === "sqlite";
|
15151
|
+
}
|
15152
|
+
convert(statement) {
|
15153
|
+
return `/*
|
15154
|
+
SQLite does not support "Dropping unique constraint from an existing table" out of the box, we do not generate automatic migration for that, so it has to be done manually
|
15155
|
+
Please refer to: https://www.techonthenet.com/sqlite/unique.php
|
15156
|
+
|
15157
|
+
Due to that we don't generate migration automatically and it has to be done manually
|
15158
|
+
*/`;
|
15159
|
+
}
|
15160
|
+
};
|
14857
15161
|
CreateTypeEnumConvertor = class extends Convertor {
|
14858
15162
|
can(statement) {
|
14859
15163
|
return statement.type === "create_type_enum";
|
@@ -15847,6 +16151,8 @@ ${BREAKPOINT}ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT ${statement.newCo
|
|
15847
16151
|
convertors.push(new SqliteAlterForeignKeyConvertor());
|
15848
16152
|
convertors.push(new SqliteDeleteForeignKeyConvertor());
|
15849
16153
|
convertors.push(new SqliteCreateForeignKeyConvertor());
|
16154
|
+
convertors.push(new SQLiteAlterTableAddUniqueConstraintConvertor());
|
16155
|
+
convertors.push(new SQLiteAlterTableDropUniqueConstraintConvertor());
|
15850
16156
|
convertors.push(new SqliteAlterTableAlterColumnSetNotNullConvertor());
|
15851
16157
|
convertors.push(new SqliteAlterTableAlterColumnDropNotNullConvertor());
|
15852
16158
|
convertors.push(new SqliteAlterTableAlterColumnSetDefaultConvertor());
|
@@ -15940,7 +16246,7 @@ var init_jsonStatements = __esm({
|
|
15940
16246
|
};
|
15941
16247
|
};
|
15942
16248
|
prepareSQLiteCreateTable = (table4) => {
|
15943
|
-
const { name, columns } = table4;
|
16249
|
+
const { name, columns, uniqueConstraints } = table4;
|
15944
16250
|
const references2 = Object.values(table4.foreignKeys);
|
15945
16251
|
const composites = Object.values(table4.compositePrimaryKeys).map(
|
15946
16252
|
(it) => SQLiteSquasher.unsquashPK(it)
|
@@ -15950,7 +16256,8 @@ var init_jsonStatements = __esm({
|
|
15950
16256
|
tableName: name,
|
15951
16257
|
columns: Object.values(columns),
|
15952
16258
|
referenceData: references2,
|
15953
|
-
compositePKs: composites
|
16259
|
+
compositePKs: composites,
|
16260
|
+
uniqueConstraints: Object.values(uniqueConstraints)
|
15954
16261
|
};
|
15955
16262
|
};
|
15956
16263
|
prepareDropTableJson = (table4) => {
|
@@ -16649,7 +16956,37 @@ var init_snapshotsDiffer = __esm({
|
|
16649
16956
|
}).strict();
|
16650
16957
|
applySnapshotsDiff = async (json1, json2, dialect6, schemasResolver, tablesResolver, columnsResolver, prevFull, curFull) => {
|
16651
16958
|
var _a, _b;
|
16652
|
-
|
16959
|
+
let diffResult;
|
16960
|
+
if (dialect6 === "mysql") {
|
16961
|
+
for (const tableName in json1.tables) {
|
16962
|
+
const table4 = json1.tables[tableName];
|
16963
|
+
for (const indexName4 in table4.indexes) {
|
16964
|
+
const index4 = MySqlSquasher.unsquashIdx(table4.indexes[indexName4]);
|
16965
|
+
if (index4.isUnique) {
|
16966
|
+
table4.uniqueConstraints[indexName4] = MySqlSquasher.squashUnique({
|
16967
|
+
name: index4.name,
|
16968
|
+
columns: index4.columns
|
16969
|
+
});
|
16970
|
+
delete json1.tables[tableName].indexes[index4.name];
|
16971
|
+
}
|
16972
|
+
}
|
16973
|
+
}
|
16974
|
+
for (const tableName in json2.tables) {
|
16975
|
+
const table4 = json2.tables[tableName];
|
16976
|
+
for (const indexName4 in table4.indexes) {
|
16977
|
+
const index4 = MySqlSquasher.unsquashIdx(table4.indexes[indexName4]);
|
16978
|
+
if (index4.isUnique) {
|
16979
|
+
table4.uniqueConstraints[indexName4] = MySqlSquasher.squashUnique({
|
16980
|
+
name: index4.name,
|
16981
|
+
columns: index4.columns
|
16982
|
+
});
|
16983
|
+
delete json2.tables[tableName].indexes[index4.name];
|
16984
|
+
}
|
16985
|
+
}
|
16986
|
+
}
|
16987
|
+
diffResult = applyJsonDiff(json1, json2);
|
16988
|
+
}
|
16989
|
+
diffResult = applyJsonDiff(json1, json2);
|
16653
16990
|
if (Object.keys(diffResult).length === 0) {
|
16654
16991
|
return { statements: [], sqlStatements: [], _meta: void 0 };
|
16655
16992
|
}
|
@@ -16820,7 +17157,6 @@ var init_snapshotsDiffer = __esm({
|
|
16820
17157
|
prevFull
|
16821
17158
|
);
|
16822
17159
|
}
|
16823
|
-
;
|
16824
17160
|
alteredCompositePKs = prepareAlterCompositePrimaryKeyMySql(
|
16825
17161
|
it.name,
|
16826
17162
|
it.alteredCompositePKs,
|
@@ -18271,70 +18607,6 @@ var init_sqliteUtils = __esm({
|
|
18271
18607
|
}
|
18272
18608
|
});
|
18273
18609
|
|
18274
|
-
// src/cli/validations/outputs.ts
|
18275
|
-
var withStyle, outputs;
|
18276
|
-
var init_outputs = __esm({
|
18277
|
-
"src/cli/validations/outputs.ts"() {
|
18278
|
-
init_source();
|
18279
|
-
withStyle = {
|
18280
|
-
error: (str) => `${source_default.red(`${source_default.white.bgRed(" Invalid input ")} ${str}`)}`,
|
18281
|
-
warning: (str) => `${source_default.white.bgGray(" Warning ")} ${str}`,
|
18282
|
-
fullWarning: (str) => `${source_default.black.bgYellow("[Warning]")} ${source_default.bold(str)}`
|
18283
|
-
};
|
18284
|
-
outputs = {
|
18285
|
-
studio: {
|
18286
|
-
drivers: (param) => withStyle.error(
|
18287
|
-
`"${param}" is not a valid driver. Available drivers: "pg", "mysql2", "better-sqlite", "libsql", "turso". You can read more about drizzle.config: https://orm.drizzle.team/kit-docs/config-reference`
|
18288
|
-
),
|
18289
|
-
noCredentials: () => withStyle.error(
|
18290
|
-
`You need to specify a "dbCredentials" param in you config. It will help drizzle to know how to query you database. You can read more about drizzle.config: https://orm.drizzle.team/kit-docs/config-reference`
|
18291
|
-
),
|
18292
|
-
noDriver: () => withStyle.error(
|
18293
|
-
`You need to specify a "driver" param in you config. It will help drizzle to know how to query you database. You can read more about drizzle.config: https://orm.drizzle.team/kit-docs/config-reference`
|
18294
|
-
)
|
18295
|
-
},
|
18296
|
-
common: {
|
18297
|
-
ambiguousParams: (command) => withStyle.error(
|
18298
|
-
`You can't use both --config and other cli options for ${command} command`
|
18299
|
-
),
|
18300
|
-
schema: (command) => withStyle.error(`"--schema" is a required field for ${command} command`),
|
18301
|
-
schemaConfig: (command) => withStyle.error(
|
18302
|
-
`"schema" is a required field in drizzle.config for ${command} command`
|
18303
|
-
)
|
18304
|
-
},
|
18305
|
-
postgres: {
|
18306
|
-
connection: {
|
18307
|
-
driver: () => withStyle.error(`Only "pg" is available options for "--driver"`),
|
18308
|
-
required: () => withStyle.error(
|
18309
|
-
`Either "connectionString" or "host", "database" are required for database connection`
|
18310
|
-
)
|
18311
|
-
}
|
18312
|
-
},
|
18313
|
-
mysql: {
|
18314
|
-
connection: {
|
18315
|
-
driver: () => withStyle.error(`Only "mysql2" is available options for "--driver"`),
|
18316
|
-
required: () => withStyle.error(
|
18317
|
-
`Either "connectionString" or "host", "database" are required for database connection`
|
18318
|
-
)
|
18319
|
-
}
|
18320
|
-
},
|
18321
|
-
sqlite: {
|
18322
|
-
connection: {
|
18323
|
-
driver: () => withStyle.error(
|
18324
|
-
`Either "turso", "libsql", "better-sqlite" are available options for "--driver"`
|
18325
|
-
),
|
18326
|
-
url: (driver) => withStyle.error(`"url" is a required option for driver "${driver}". You can read more about drizzle.config: https://orm.drizzle.team/kit-docs/config-reference`),
|
18327
|
-
authToken: (driver) => withStyle.error(
|
18328
|
-
`"authToken" is a required option for driver "${driver}". You can read more about drizzle.config: https://orm.drizzle.team/kit-docs/config-reference`
|
18329
|
-
)
|
18330
|
-
},
|
18331
|
-
introspect: {},
|
18332
|
-
push: {}
|
18333
|
-
}
|
18334
|
-
};
|
18335
|
-
}
|
18336
|
-
});
|
18337
|
-
|
18338
18610
|
// src/cli/validations/common.ts
|
18339
18611
|
var checkCollisions;
|
18340
18612
|
var init_common = __esm({
|
@@ -35363,7 +35635,7 @@ var require_promise = __commonJS({
|
|
35363
35635
|
});
|
35364
35636
|
|
35365
35637
|
// src/mysql-introspect.ts
|
35366
|
-
var mysqlImportsList, objToStatement2, timeConfig, binaryConfig, importsPatch, relations, withCasing, schemaToTypeScript, isCyclic, isSelf, mapColumnDefault, mapColumnDefaultForJson, column4, createTableColumns, createTableIndexes, createTablePKs, createTableFKs;
|
35638
|
+
var mysqlImportsList, objToStatement2, timeConfig, binaryConfig, importsPatch, relations, withCasing, schemaToTypeScript, isCyclic, isSelf, mapColumnDefault, mapColumnDefaultForJson, column4, createTableColumns, createTableIndexes, createTableUniques, createTablePKs, createTableFKs;
|
35367
35639
|
var init_mysql_introspect = __esm({
|
35368
35640
|
"src/mysql-introspect.ts"() {
|
35369
35641
|
init_utils3();
|
@@ -35463,9 +35735,13 @@ var init_mysql_introspect = __esm({
|
|
35463
35735
|
const pkImports = Object.values(it.compositePrimaryKeys).map(
|
35464
35736
|
(it2) => "primaryKey"
|
35465
35737
|
);
|
35738
|
+
const uniqueImports = Object.values(it.uniqueConstraints).map(
|
35739
|
+
(it2) => "unique"
|
35740
|
+
);
|
35466
35741
|
res.mysql.push(...idxImports);
|
35467
35742
|
res.mysql.push(...fkImpots);
|
35468
35743
|
res.mysql.push(...pkImports);
|
35744
|
+
res.mysql.push(...uniqueImports);
|
35469
35745
|
const columnImports = Object.values(it.columns).map((col) => {
|
35470
35746
|
let patched = importsPatch[col.type] ?? col.type;
|
35471
35747
|
patched = patched.startsWith("varchar(") ? "varchar" : patched;
|
@@ -35512,7 +35788,7 @@ var init_mysql_introspect = __esm({
|
|
35512
35788
|
const filteredFKs = Object.values(table4.foreignKeys).filter((it) => {
|
35513
35789
|
return it.columnsFrom.length > 1 || isSelf(it);
|
35514
35790
|
});
|
35515
|
-
if (Object.keys(table4.indexes).length > 0 || filteredFKs.length > 0 || Object.keys(table4.compositePrimaryKeys).length > 0) {
|
35791
|
+
if (Object.keys(table4.indexes).length > 0 || filteredFKs.length > 0 || Object.keys(table4.compositePrimaryKeys).length > 0 || Object.keys(table4.uniqueConstraints).length > 0) {
|
35516
35792
|
statement += ",\n";
|
35517
35793
|
statement += "(table) => {\n";
|
35518
35794
|
statement += " return {\n";
|
@@ -35526,6 +35802,10 @@ var init_mysql_introspect = __esm({
|
|
35526
35802
|
Object.values(table4.compositePrimaryKeys),
|
35527
35803
|
casing
|
35528
35804
|
);
|
35805
|
+
statement += createTableUniques(
|
35806
|
+
Object.values(table4.uniqueConstraints),
|
35807
|
+
casing
|
35808
|
+
);
|
35529
35809
|
statement += " }\n";
|
35530
35810
|
statement += "}";
|
35531
35811
|
}
|
@@ -35836,6 +36116,19 @@ import { sql } from "drizzle-orm"
|
|
35836
36116
|
statement += `${escapedIndexName})`;
|
35837
36117
|
statement += `.on(${it.columns.map((it2) => `table.${withCasing(it2, casing)}`).join(", ")}),`;
|
35838
36118
|
statement += `
|
36119
|
+
`;
|
36120
|
+
});
|
36121
|
+
return statement;
|
36122
|
+
};
|
36123
|
+
createTableUniques = (unqs, casing) => {
|
36124
|
+
let statement = "";
|
36125
|
+
unqs.forEach((it) => {
|
36126
|
+
const idxKey = withCasing(it.name, casing);
|
36127
|
+
statement += ` ${idxKey}: `;
|
36128
|
+
statement += "unique(";
|
36129
|
+
statement += `"${it.name}")`;
|
36130
|
+
statement += `.on(${it.columns.map((it2) => `table.${withCasing(it2, casing)}`).join(", ")}),`;
|
36131
|
+
statement += `
|
35839
36132
|
`;
|
35840
36133
|
});
|
35841
36134
|
return statement;
|
@@ -37164,10 +37457,10 @@ __export(mysqlIntrospect_exports, {
|
|
37164
37457
|
mysqlIntrospect: () => mysqlIntrospect,
|
37165
37458
|
mysqlPushIntrospect: () => mysqlPushIntrospect
|
37166
37459
|
});
|
37167
|
-
var
|
37460
|
+
var import_hanji6, import_promise, connectToMySQL, mysqlIntrospect, mysqlPushIntrospect;
|
37168
37461
|
var init_mysqlIntrospect = __esm({
|
37169
37462
|
"src/cli/commands/mysqlIntrospect.ts"() {
|
37170
|
-
|
37463
|
+
import_hanji6 = __toESM(require_hanji());
|
37171
37464
|
init_views();
|
37172
37465
|
import_promise = __toESM(require_promise());
|
37173
37466
|
init_mysqlSerializer();
|
@@ -37216,7 +37509,7 @@ var init_mysqlIntrospect = __esm({
|
|
37216
37509
|
return false;
|
37217
37510
|
};
|
37218
37511
|
const progress = new IntrospectProgress();
|
37219
|
-
const res = await (0,
|
37512
|
+
const res = await (0, import_hanji6.renderWithTask)(
|
37220
37513
|
progress,
|
37221
37514
|
fromDatabase(
|
37222
37515
|
client,
|
@@ -37254,7 +37547,7 @@ var init_mysqlIntrospect = __esm({
|
|
37254
37547
|
});
|
37255
37548
|
|
37256
37549
|
// src/sqlite-introspect.ts
|
37257
|
-
var sqliteImportsList, indexName3, objToStatement22, relations2, withCasing2, schemaToTypeScript2, isCyclic2, isSelf2, mapColumnDefault2, column5, createTableColumns2, createTableIndexes2, createTablePKs2, createTableFKs2;
|
37550
|
+
var sqliteImportsList, indexName3, objToStatement22, relations2, withCasing2, schemaToTypeScript2, isCyclic2, isSelf2, mapColumnDefault2, column5, createTableColumns2, createTableIndexes2, createTableUniques2, createTablePKs2, createTableFKs2;
|
37258
37551
|
var init_sqlite_introspect = __esm({
|
37259
37552
|
"src/sqlite-introspect.ts"() {
|
37260
37553
|
init_utils3();
|
@@ -37305,9 +37598,13 @@ var init_sqlite_introspect = __esm({
|
|
37305
37598
|
const pkImports = Object.values(it.compositePrimaryKeys).map(
|
37306
37599
|
(it2) => "primaryKey"
|
37307
37600
|
);
|
37601
|
+
const uniqueImports = Object.values(it.uniqueConstraints).map(
|
37602
|
+
(it2) => "unique"
|
37603
|
+
);
|
37308
37604
|
res.sqlite.push(...idxImports);
|
37309
37605
|
res.sqlite.push(...fkImpots);
|
37310
37606
|
res.sqlite.push(...pkImports);
|
37607
|
+
res.sqlite.push(...uniqueImports);
|
37311
37608
|
const columnImports = Object.values(it.columns).map((col) => {
|
37312
37609
|
return col.type;
|
37313
37610
|
}).filter((type) => {
|
@@ -37340,7 +37637,7 @@ var init_sqlite_introspect = __esm({
|
|
37340
37637
|
const filteredFKs = Object.values(table4.foreignKeys).filter((it) => {
|
37341
37638
|
return it.columnsFrom.length > 1 || isSelf2(it);
|
37342
37639
|
});
|
37343
|
-
if (Object.keys(table4.indexes).length > 0 || filteredFKs.length > 0 || Object.keys(table4.compositePrimaryKeys).length > 0) {
|
37640
|
+
if (Object.keys(table4.indexes).length > 0 || filteredFKs.length > 0 || Object.keys(table4.compositePrimaryKeys).length > 0 || Object.keys(table4.uniqueConstraints).length > 0) {
|
37344
37641
|
statement += ",\n";
|
37345
37642
|
statement += "(table) => {\n";
|
37346
37643
|
statement += " return {\n";
|
@@ -37354,6 +37651,10 @@ var init_sqlite_introspect = __esm({
|
|
37354
37651
|
Object.values(table4.compositePrimaryKeys),
|
37355
37652
|
casing
|
37356
37653
|
);
|
37654
|
+
statement += createTableUniques2(
|
37655
|
+
Object.values(table4.uniqueConstraints),
|
37656
|
+
casing
|
37657
|
+
);
|
37357
37658
|
statement += " }\n";
|
37358
37659
|
statement += "}";
|
37359
37660
|
}
|
@@ -37387,6 +37688,9 @@ import { sql } from "drizzle-orm"
|
|
37387
37688
|
if (typeof defaultValue === "string" && defaultValue.startsWith("(") && defaultValue.endsWith(")")) {
|
37388
37689
|
return `sql\`${defaultValue}\``;
|
37389
37690
|
}
|
37691
|
+
if (defaultValue === "NULL") {
|
37692
|
+
return `sql\`NULL\``;
|
37693
|
+
}
|
37390
37694
|
return defaultValue;
|
37391
37695
|
};
|
37392
37696
|
column5 = (type, name, defaultValue, autoincrement, casing) => {
|
@@ -37473,6 +37777,19 @@ import { sql } from "drizzle-orm"
|
|
37473
37777
|
statement += `${escapedIndexName})`;
|
37474
37778
|
statement += `.on(${it.columns.map((it2) => `table.${withCasing2(it2, casing)}`).join(", ")}),`;
|
37475
37779
|
statement += `
|
37780
|
+
`;
|
37781
|
+
});
|
37782
|
+
return statement;
|
37783
|
+
};
|
37784
|
+
createTableUniques2 = (unqs, casing) => {
|
37785
|
+
let statement = "";
|
37786
|
+
unqs.forEach((it) => {
|
37787
|
+
const idxKey = withCasing2(it.name, casing);
|
37788
|
+
statement += ` ${idxKey}: `;
|
37789
|
+
statement += "unique(";
|
37790
|
+
statement += `"${it.name}")`;
|
37791
|
+
statement += `.on(${it.columns.map((it2) => `table.${withCasing2(it2, casing)}`).join(", ")}),`;
|
37792
|
+
statement += `
|
37476
37793
|
`;
|
37477
37794
|
});
|
37478
37795
|
return statement;
|
@@ -46062,7 +46379,7 @@ __export(sqliteIntrospect_exports, {
|
|
46062
46379
|
sqliteIntrospect: () => sqliteIntrospect,
|
46063
46380
|
sqlitePushIntrospect: () => sqlitePushIntrospect
|
46064
46381
|
});
|
46065
|
-
var
|
46382
|
+
var import_hanji7, SqliteClient, BetterSqlite, TursoSqlite, connectToSQLite, sqliteIntrospect, sqlitePushIntrospect;
|
46066
46383
|
var init_sqliteIntrospect = __esm({
|
46067
46384
|
"src/cli/commands/sqliteIntrospect.ts"() {
|
46068
46385
|
init_views();
|
@@ -46071,7 +46388,7 @@ var init_sqliteIntrospect = __esm({
|
|
46071
46388
|
init_sqlite_introspect();
|
46072
46389
|
init_mjs();
|
46073
46390
|
init_lib_esm2();
|
46074
|
-
|
46391
|
+
import_hanji7 = __toESM(require_hanji());
|
46075
46392
|
SqliteClient = class {
|
46076
46393
|
constructor(db) {
|
46077
46394
|
this.db = db;
|
@@ -46137,7 +46454,7 @@ var init_sqliteIntrospect = __esm({
|
|
46137
46454
|
return false;
|
46138
46455
|
};
|
46139
46456
|
const progress = new IntrospectProgress();
|
46140
|
-
const res = await (0,
|
46457
|
+
const res = await (0, import_hanji7.renderWithTask)(
|
46141
46458
|
progress,
|
46142
46459
|
fromDatabase3(
|
46143
46460
|
client,
|
@@ -50711,7 +51028,7 @@ var require_lib5 = __commonJS({
|
|
50711
51028
|
});
|
50712
51029
|
|
50713
51030
|
// src/introspect.ts
|
50714
|
-
var pgImportsList, objToStatement23, timeConfig2, possibleIntervals, intervalStrToObj, intervalConfig, importsPatch2, relations3, withCasing3, schemaToTypeScript3, isCyclic3, isSelf3, column6, dimensionsInArray, createTableColumns3, createTableIndexes3, createTablePKs3, createTableFKs3;
|
51031
|
+
var pgImportsList, objToStatement23, timeConfig2, possibleIntervals, intervalStrToObj, intervalConfig, importsPatch2, relations3, withCasing3, schemaToTypeScript3, isCyclic3, isSelf3, column6, dimensionsInArray, createTableColumns3, createTableIndexes3, createTablePKs3, createTableUniques3, createTableFKs3;
|
50715
51032
|
var init_introspect = __esm({
|
50716
51033
|
"src/introspect.ts"() {
|
50717
51034
|
init_utils3();
|
@@ -50854,9 +51171,13 @@ var init_introspect = __esm({
|
|
50854
51171
|
const pkImports = Object.values(it.compositePrimaryKeys).map(
|
50855
51172
|
(it2) => "primaryKey"
|
50856
51173
|
);
|
51174
|
+
const uniqueImports = Object.values(it.uniqueConstraints).map(
|
51175
|
+
(it2) => "unique"
|
51176
|
+
);
|
50857
51177
|
res.pg.push(...idxImports);
|
50858
51178
|
res.pg.push(...fkImpots);
|
50859
51179
|
res.pg.push(...pkImports);
|
51180
|
+
res.pg.push(...uniqueImports);
|
50860
51181
|
const columnImports = Object.values(it.columns).map((col) => {
|
50861
51182
|
let patched = importsPatch2[col.type] ?? col.type;
|
50862
51183
|
patched = patched.startsWith("varchar(") ? "varchar" : patched;
|
@@ -50900,7 +51221,7 @@ var init_introspect = __esm({
|
|
50900
51221
|
const filteredFKs = Object.values(table4.foreignKeys).filter((it) => {
|
50901
51222
|
return it.columnsFrom.length > 1 || isSelf3(it);
|
50902
51223
|
});
|
50903
|
-
if (Object.keys(table4.indexes).length > 0 || filteredFKs.length > 0 || Object.keys(table4.compositePrimaryKeys).length > 0) {
|
51224
|
+
if (Object.keys(table4.indexes).length > 0 || filteredFKs.length > 0 || Object.keys(table4.compositePrimaryKeys).length > 0 || Object.keys(table4.uniqueConstraints).length > 0) {
|
50904
51225
|
statement += ",\n";
|
50905
51226
|
statement += "(table) => {\n";
|
50906
51227
|
statement += " return {\n";
|
@@ -50914,6 +51235,10 @@ var init_introspect = __esm({
|
|
50914
51235
|
Object.values(table4.compositePrimaryKeys),
|
50915
51236
|
casing
|
50916
51237
|
);
|
51238
|
+
statement += createTableUniques3(
|
51239
|
+
Object.values(table4.uniqueConstraints),
|
51240
|
+
casing
|
51241
|
+
);
|
50917
51242
|
statement += " }\n";
|
50918
51243
|
statement += "}";
|
50919
51244
|
}
|
@@ -51156,7 +51481,13 @@ var init_introspect = __esm({
|
|
51156
51481
|
return res;
|
51157
51482
|
}, {});
|
51158
51483
|
columns.forEach((it) => {
|
51159
|
-
const columnStatement = column6(
|
51484
|
+
const columnStatement = column6(
|
51485
|
+
it.type,
|
51486
|
+
it.name,
|
51487
|
+
enumTypes,
|
51488
|
+
it.default,
|
51489
|
+
casing
|
51490
|
+
);
|
51160
51491
|
statement += " ";
|
51161
51492
|
statement += columnStatement;
|
51162
51493
|
statement += dimensionsInArray(it.type);
|
@@ -51215,6 +51546,20 @@ var init_introspect = __esm({
|
|
51215
51546
|
}).join(", ")}`;
|
51216
51547
|
statement += ")";
|
51217
51548
|
statement += `
|
51549
|
+
`;
|
51550
|
+
});
|
51551
|
+
return statement;
|
51552
|
+
};
|
51553
|
+
createTableUniques3 = (unqs, casing) => {
|
51554
|
+
let statement = "";
|
51555
|
+
unqs.forEach((it) => {
|
51556
|
+
const idxKey = withCasing3(it.name, casing);
|
51557
|
+
statement += ` ${idxKey}: `;
|
51558
|
+
statement += "unique(";
|
51559
|
+
statement += `"${it.name}")`;
|
51560
|
+
statement += `.on(${it.columns.map((it2) => `table.${withCasing3(it2, casing)}`).join(", ")})`;
|
51561
|
+
statement += it.nullsNotDistinct ? `.nullsNotDistinct()` : "";
|
51562
|
+
statement += `,
|
51218
51563
|
`;
|
51219
51564
|
});
|
51220
51565
|
return statement;
|
@@ -51246,10 +51591,10 @@ var pgIntrospect_exports = {};
|
|
51246
51591
|
__export(pgIntrospect_exports, {
|
51247
51592
|
pgIntrospect: () => pgIntrospect
|
51248
51593
|
});
|
51249
|
-
var
|
51594
|
+
var import_hanji8, import_pg, pgIntrospect;
|
51250
51595
|
var init_pgIntrospect = __esm({
|
51251
51596
|
"src/cli/commands/pgIntrospect.ts"() {
|
51252
|
-
|
51597
|
+
import_hanji8 = __toESM(require_hanji());
|
51253
51598
|
init_views();
|
51254
51599
|
import_pg = __toESM(require_lib5());
|
51255
51600
|
init_pgSerializer();
|
@@ -51272,7 +51617,7 @@ var init_pgIntrospect = __esm({
|
|
51272
51617
|
return false;
|
51273
51618
|
};
|
51274
51619
|
const progress = new IntrospectProgress();
|
51275
|
-
const res = await (0,
|
51620
|
+
const res = await (0, import_hanji8.renderWithTask)(
|
51276
51621
|
progress,
|
51277
51622
|
fromDatabase2(pool, filter2, (stage, count, status) => {
|
51278
51623
|
progress.update(stage, count, status);
|
@@ -51492,7 +51837,7 @@ var checkHandler = (out, dialect6) => {
|
|
51492
51837
|
};
|
51493
51838
|
|
51494
51839
|
// src/cli/index.ts
|
51495
|
-
var
|
51840
|
+
var import_hanji9 = __toESM(require_hanji());
|
51496
51841
|
var import_path7 = __toESM(require("path"));
|
51497
51842
|
|
51498
51843
|
// src/cli/utils.ts
|
@@ -51547,7 +51892,7 @@ init_source();
|
|
51547
51892
|
// package.json
|
51548
51893
|
var package_default = {
|
51549
51894
|
name: "drizzle-kit",
|
51550
|
-
version: "0.19.
|
51895
|
+
version: "0.19.5",
|
51551
51896
|
repository: "https://github.com/drizzle-team/drizzle-kit-mirror",
|
51552
51897
|
author: "Drizzle Team",
|
51553
51898
|
license: "MIT",
|
@@ -51626,7 +51971,7 @@ var package_default = {
|
|
51626
51971
|
"better-sqlite3": "^8.4.0",
|
51627
51972
|
dockerode: "^3.3.4",
|
51628
51973
|
dotenv: "^16.0.3",
|
51629
|
-
"drizzle-orm": "0.27.
|
51974
|
+
"drizzle-orm": "0.27.1-8a21e7b",
|
51630
51975
|
eslint: "^8.29.0",
|
51631
51976
|
"eslint-config-prettier": "^8.5.0",
|
51632
51977
|
"eslint-plugin-prettier": "^4.2.1",
|
@@ -51734,6 +52079,8 @@ init_utils();
|
|
51734
52079
|
|
51735
52080
|
// src/cli/commands/mysqlPushUtils.ts
|
51736
52081
|
init_source();
|
52082
|
+
var import_hanji5 = __toESM(require_hanji());
|
52083
|
+
init_mysqlSchema();
|
51737
52084
|
var filterStatements = (statements) => {
|
51738
52085
|
return statements.filter((statement) => {
|
51739
52086
|
if (statement.type === "alter_table_alter_column_set_type") {
|
@@ -51888,6 +52235,33 @@ var logSuggestionsAndReturn = async ({
|
|
51888
52235
|
shouldAskForApprove = true;
|
51889
52236
|
}
|
51890
52237
|
}
|
52238
|
+
} else if (statement.type === "create_unique_constraint") {
|
52239
|
+
const res = await connection.query(
|
52240
|
+
`select count(*) as count from \`${statement.tableName}\``
|
52241
|
+
);
|
52242
|
+
const count = Number(res[0][0].count);
|
52243
|
+
if (count > 0) {
|
52244
|
+
const unsquashedUnique = MySqlSquasher.unsquashUnique(statement.data);
|
52245
|
+
console.log(
|
52246
|
+
`\xB7 You're about to add ${source_default.underline(
|
52247
|
+
unsquashedUnique.name
|
52248
|
+
)} unique constraint to the table, which contains ${count} items. If this statement fails, you will receive an error from the database. Do you want to truncate ${source_default.underline(
|
52249
|
+
statement.tableName
|
52250
|
+
)} table?
|
52251
|
+
`
|
52252
|
+
);
|
52253
|
+
const { status, data } = await (0, import_hanji5.render)(
|
52254
|
+
new Select([
|
52255
|
+
"No, add the constraint without truncating the table",
|
52256
|
+
`Yes, truncate the table`
|
52257
|
+
])
|
52258
|
+
);
|
52259
|
+
if ((data == null ? void 0 : data.index) === 1) {
|
52260
|
+
tablesToTruncate.push(statement.tableName);
|
52261
|
+
statementsToExecute.push(`truncate table ${statement.tableName};`);
|
52262
|
+
shouldAskForApprove = true;
|
52263
|
+
}
|
52264
|
+
}
|
51891
52265
|
}
|
51892
52266
|
}
|
51893
52267
|
return {
|
@@ -52124,7 +52498,7 @@ var logSuggestionsAndReturn2 = async ({
|
|
52124
52498
|
if (typeof tablesContext[fk4.tableFrom] === "undefined") {
|
52125
52499
|
tablesContext[fk4.tableFrom] = _moveDataStatements(fk4.tableFrom, json2);
|
52126
52500
|
}
|
52127
|
-
} else if (statement.type === "create_composite_pk" || statement.type === "alter_composite_pk" || statement.type === "delete_composite_pk") {
|
52501
|
+
} else if (statement.type === "create_composite_pk" || statement.type === "alter_composite_pk" || statement.type === "delete_composite_pk" || statement.type === "create_unique_constraint" || statement.type === "delete_unique_constraint") {
|
52128
52502
|
if (typeof tablesContext[statement.tableName] === "undefined") {
|
52129
52503
|
tablesContext[statement.tableName] = _moveDataStatements(
|
52130
52504
|
statement.tableName,
|
@@ -52222,14 +52596,14 @@ var generateMysqlCommand = new import_commander.Command("generate:mysql").option
|
|
52222
52596
|
const { prepareAndMigrateMySql: prepareAndMigrateMySql2 } = await Promise.resolve().then(() => (init_migrate(), migrate_exports));
|
52223
52597
|
await prepareAndMigrateMySql2(result);
|
52224
52598
|
});
|
52225
|
-
var Select = class extends
|
52599
|
+
var Select = class extends import_hanji9.Prompt {
|
52226
52600
|
// private readonly spinner: () => string;
|
52227
52601
|
// private timeout: NodeJS.Timer | undefined;
|
52228
52602
|
constructor(items) {
|
52229
52603
|
super();
|
52230
52604
|
this.on("attach", (terminal) => terminal.toggleCursor("hide"));
|
52231
52605
|
this.on("detach", (terminal) => terminal.toggleCursor("show"));
|
52232
|
-
this.data = new
|
52606
|
+
this.data = new import_hanji9.SelectState(
|
52233
52607
|
items.map((it) => ({ label: it, value: `${it}-value` }))
|
52234
52608
|
);
|
52235
52609
|
this.data.bind(this);
|
@@ -52264,7 +52638,7 @@ var dbPushMysqlCommand = new import_commander.Command("push:mysql").option(
|
|
52264
52638
|
);
|
52265
52639
|
const fileNames = prepareFilenames(drizzleConfig.schema);
|
52266
52640
|
if (fileNames.length === 0) {
|
52267
|
-
(0,
|
52641
|
+
(0, import_hanji9.render)(
|
52268
52642
|
`[${source_default.blue("i")}] No schema file in ${drizzleConfig.schema} was found`
|
52269
52643
|
);
|
52270
52644
|
process.exit(0);
|
@@ -52281,7 +52655,7 @@ var dbPushMysqlCommand = new import_commander.Command("push:mysql").option(
|
|
52281
52655
|
try {
|
52282
52656
|
if (typeof statements === "undefined") {
|
52283
52657
|
} else if (statements.sqlStatements.length === 0) {
|
52284
|
-
(0,
|
52658
|
+
(0, import_hanji9.render)(`[${source_default.blue("i")}] No changes detected`);
|
52285
52659
|
} else {
|
52286
52660
|
const filteredStatements = filterStatements(statements.statements);
|
52287
52661
|
const {
|
@@ -52309,11 +52683,11 @@ var dbPushMysqlCommand = new import_commander.Command("push:mysql").option(
|
|
52309
52683
|
}
|
52310
52684
|
if (drizzleConfig.strict) {
|
52311
52685
|
if (!shouldAskForApprove) {
|
52312
|
-
const { status, data } = await (0,
|
52686
|
+
const { status, data } = await (0, import_hanji9.render)(
|
52313
52687
|
new Select(["No, abort", `Yes, I want to execute all statements`])
|
52314
52688
|
);
|
52315
52689
|
if ((data == null ? void 0 : data.index) === 0) {
|
52316
|
-
(0,
|
52690
|
+
(0, import_hanji9.render)(`[${source_default.red("x")}] All changes were aborted`);
|
52317
52691
|
process.exit(0);
|
52318
52692
|
}
|
52319
52693
|
}
|
@@ -52328,14 +52702,14 @@ var dbPushMysqlCommand = new import_commander.Command("push:mysql").option(
|
|
52328
52702
|
)
|
52329
52703
|
);
|
52330
52704
|
console.log(source_default.white("Do you still want to push changes?"));
|
52331
|
-
const { status, data } = await (0,
|
52705
|
+
const { status, data } = await (0, import_hanji9.render)(
|
52332
52706
|
new Select([
|
52333
52707
|
"No, abort",
|
52334
52708
|
`Yes, I want to${tablesToRemove.length > 0 ? ` remove ${tablesToRemove.length} ${tablesToRemove.length > 1 ? "tables" : "table"},` : " "}${columnsToRemove.length > 0 ? ` remove ${columnsToRemove.length} ${columnsToRemove.length > 1 ? "columns" : "column"},` : " "}${tablesToTruncate.length > 0 ? ` truncate ${tablesToTruncate.length} ${tablesToTruncate.length > 1 ? "tables" : "table"}` : ""}`.replace(/(^,)|(,$)/g, "").replace(/ +(?= )/g, "")
|
52335
52709
|
])
|
52336
52710
|
);
|
52337
52711
|
if ((data == null ? void 0 : data.index) === 0) {
|
52338
|
-
(0,
|
52712
|
+
(0, import_hanji9.render)(`[${source_default.red("x")}] All changes were aborted`);
|
52339
52713
|
process.exit(0);
|
52340
52714
|
}
|
52341
52715
|
}
|
@@ -52346,9 +52720,9 @@ var dbPushMysqlCommand = new import_commander.Command("push:mysql").option(
|
|
52346
52720
|
await connection.client.query(statement);
|
52347
52721
|
}
|
52348
52722
|
if (filteredStatements.length > 0) {
|
52349
|
-
(0,
|
52723
|
+
(0, import_hanji9.render)(`[${source_default.green("\u2713")}] Changes applied`);
|
52350
52724
|
} else {
|
52351
|
-
(0,
|
52725
|
+
(0, import_hanji9.render)(`[${source_default.blue("i")}] No changes detected`);
|
52352
52726
|
}
|
52353
52727
|
}
|
52354
52728
|
} catch (e) {
|
@@ -52360,7 +52734,7 @@ var dbPushMysqlCommand = new import_commander.Command("push:mysql").option(
|
|
52360
52734
|
var dbPushSqliteCommand = new import_commander.Command("push:sqlite").option(
|
52361
52735
|
"--config <config>",
|
52362
52736
|
"Path to a config.ts file, drizzle.config.ts by default"
|
52363
|
-
).option("--tableFilters", `Table name filters`).option("--connectionString <connectionString>", "SQLite connection string").option("--driver <driver>", "SQLite database path").option("--url <url>", "SQLite database path").option("--auth-token <authToken>", "SQLite database path").option("--verbose", "Print all statements for each push").option("--strict", "Always ask for confirmation").action(async (options) => {
|
52737
|
+
).option("--schema <schema>", "Path to a schema file or folder").option("--tableFilters", `Table name filters`).option("--connectionString <connectionString>", "SQLite connection string").option("--driver <driver>", "SQLite database path").option("--url <url>", "SQLite database path").option("--auth-token <authToken>", "SQLite database path").option("--verbose", "Print all statements for each push").option("--strict", "Always ask for confirmation").action(async (options) => {
|
52364
52738
|
printVersions();
|
52365
52739
|
assertPackages("drizzle-orm");
|
52366
52740
|
assertOrmCoreVersion();
|
@@ -52368,7 +52742,7 @@ var dbPushSqliteCommand = new import_commander.Command("push:sqlite").option(
|
|
52368
52742
|
const res = await validatePush(options);
|
52369
52743
|
const fileNames = prepareFilenames(res.schema);
|
52370
52744
|
if (fileNames.length === 0) {
|
52371
|
-
(0,
|
52745
|
+
(0, import_hanji9.render)(`[${source_default.blue("i")}] No schema file in ${res.schema} was found`);
|
52372
52746
|
process.exit(0);
|
52373
52747
|
}
|
52374
52748
|
const connection = await connectToSQLite2(res);
|
@@ -52383,7 +52757,7 @@ var dbPushSqliteCommand = new import_commander.Command("push:sqlite").option(
|
|
52383
52757
|
try {
|
52384
52758
|
if (typeof statements === "undefined") {
|
52385
52759
|
} else if (statements.sqlStatements.length === 0) {
|
52386
|
-
(0,
|
52760
|
+
(0, import_hanji9.render)(`
|
52387
52761
|
[${source_default.blue("i")}] No changes detected`);
|
52388
52762
|
} else {
|
52389
52763
|
const {
|
@@ -52411,11 +52785,11 @@ var dbPushSqliteCommand = new import_commander.Command("push:sqlite").option(
|
|
52411
52785
|
}
|
52412
52786
|
if (res.strict) {
|
52413
52787
|
if (!shouldAskForApprove) {
|
52414
|
-
const { status, data } = await (0,
|
52788
|
+
const { status, data } = await (0, import_hanji9.render)(
|
52415
52789
|
new Select(["No, abort", `Yes, I want to execute all statements`])
|
52416
52790
|
);
|
52417
52791
|
if ((data == null ? void 0 : data.index) === 0) {
|
52418
|
-
(0,
|
52792
|
+
(0, import_hanji9.render)(`[${source_default.red("x")}] All changes were aborted`);
|
52419
52793
|
process.exit(0);
|
52420
52794
|
}
|
52421
52795
|
}
|
@@ -52430,21 +52804,21 @@ var dbPushSqliteCommand = new import_commander.Command("push:sqlite").option(
|
|
52430
52804
|
)
|
52431
52805
|
);
|
52432
52806
|
console.log(source_default.white("Do you still want to push changes?"));
|
52433
|
-
const { status, data } = await (0,
|
52807
|
+
const { status, data } = await (0, import_hanji9.render)(
|
52434
52808
|
new Select([
|
52435
52809
|
"No, abort",
|
52436
52810
|
`Yes, I want to${tablesToRemove.length > 0 ? ` remove ${tablesToRemove.length} ${tablesToRemove.length > 1 ? "tables" : "table"},` : " "}${columnsToRemove.length > 0 ? ` remove ${columnsToRemove.length} ${columnsToRemove.length > 1 ? "columns" : "column"},` : " "}${tablesToTruncate.length > 0 ? ` truncate ${tablesToTruncate.length} ${tablesToTruncate.length > 1 ? "tables" : "table"}` : ""}`.trimEnd().replace(/(^,)|(,$)/g, "").replace(/ +(?= )/g, "")
|
52437
52811
|
])
|
52438
52812
|
);
|
52439
52813
|
if ((data == null ? void 0 : data.index) === 0) {
|
52440
|
-
(0,
|
52814
|
+
(0, import_hanji9.render)(`[${source_default.red("x")}] All changes were aborted`);
|
52441
52815
|
process.exit(0);
|
52442
52816
|
}
|
52443
52817
|
}
|
52444
52818
|
for (const dStmnt of statementsToExecute) {
|
52445
52819
|
await connection.client.run(dStmnt);
|
52446
52820
|
}
|
52447
|
-
(0,
|
52821
|
+
(0, import_hanji9.render)(`[${source_default.green("\u2713")}] Changes applied`);
|
52448
52822
|
}
|
52449
52823
|
} catch (e) {
|
52450
52824
|
console.log(e);
|
@@ -52613,13 +52987,13 @@ var introspectPgCommand = new import_commander.Command("introspect:pg").option("
|
|
52613
52987
|
"introspect"
|
52614
52988
|
);
|
52615
52989
|
} else {
|
52616
|
-
(0,
|
52990
|
+
(0, import_hanji9.render)(
|
52617
52991
|
`[${source_default.blue(
|
52618
52992
|
"i"
|
52619
52993
|
)}] No SQL generated, you already have migrations in project`
|
52620
52994
|
);
|
52621
52995
|
}
|
52622
|
-
(0,
|
52996
|
+
(0, import_hanji9.render)(
|
52623
52997
|
`[${source_default.green(
|
52624
52998
|
"\u2713"
|
52625
52999
|
)}] You schema file is ready \u279C ${source_default.bold.underline.blue(
|
@@ -52666,13 +53040,13 @@ var introspectMySqlCommand = new import_commander.Command("introspect:mysql").op
|
|
52666
53040
|
"introspect"
|
52667
53041
|
);
|
52668
53042
|
} else {
|
52669
|
-
(0,
|
53043
|
+
(0, import_hanji9.render)(
|
52670
53044
|
`[${source_default.blue(
|
52671
53045
|
"i"
|
52672
53046
|
)}] No SQL generated, you already have migrations in project`
|
52673
53047
|
);
|
52674
53048
|
}
|
52675
|
-
(0,
|
53049
|
+
(0, import_hanji9.render)(
|
52676
53050
|
`[${source_default.green(
|
52677
53051
|
"\u2713"
|
52678
53052
|
)}] You schema file is ready \u279C ${source_default.bold.underline.blue(
|
@@ -52719,13 +53093,13 @@ var introspectSQLiteCommand = new import_commander.Command("introspect:sqlite").
|
|
52719
53093
|
"introspect"
|
52720
53094
|
);
|
52721
53095
|
} else {
|
52722
|
-
(0,
|
53096
|
+
(0, import_hanji9.render)(
|
52723
53097
|
`[${source_default.blue(
|
52724
53098
|
"i"
|
52725
53099
|
)}] No SQL generated, you already have migrations in project`
|
52726
53100
|
);
|
52727
53101
|
}
|
52728
|
-
(0,
|
53102
|
+
(0, import_hanji9.render)(
|
52729
53103
|
`[${source_default.green(
|
52730
53104
|
"\u2713"
|
52731
53105
|
)}] You schema file is ready \u279C ${source_default.bold.underline.blue(
|