drizzle-kit 0.19.4-befd1c5 → 0.19.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.cjs +490 -150
- package/package.json +2 -2
- package/utils.js +74 -20
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);
|
|
@@ -5142,7 +5142,7 @@ var init_pgSchema = __esm({
|
|
|
5142
5142
|
});
|
|
5143
5143
|
|
|
5144
5144
|
// 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;
|
|
5145
|
+
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
5146
|
var init_sqliteSchema = __esm({
|
|
5147
5147
|
"src/serializer/sqliteSchema.ts"() {
|
|
5148
5148
|
init_global();
|
|
@@ -5180,12 +5180,17 @@ var init_sqliteSchema = __esm({
|
|
|
5180
5180
|
indexes: recordType(stringType(), index3),
|
|
5181
5181
|
foreignKeys: recordType(stringType(), fk3)
|
|
5182
5182
|
}).strict();
|
|
5183
|
+
uniqueConstraint3 = objectType({
|
|
5184
|
+
name: stringType(),
|
|
5185
|
+
columns: stringType().array()
|
|
5186
|
+
}).strict();
|
|
5183
5187
|
table3 = objectType({
|
|
5184
5188
|
name: stringType(),
|
|
5185
5189
|
columns: recordType(stringType(), column3),
|
|
5186
5190
|
indexes: recordType(stringType(), index3),
|
|
5187
5191
|
foreignKeys: recordType(stringType(), fk3),
|
|
5188
|
-
compositePrimaryKeys: recordType(stringType(), compositePK3)
|
|
5192
|
+
compositePrimaryKeys: recordType(stringType(), compositePK3),
|
|
5193
|
+
uniqueConstraints: recordType(stringType(), uniqueConstraint3).default({})
|
|
5189
5194
|
}).strict();
|
|
5190
5195
|
dialect2 = enumType(["sqlite"]);
|
|
5191
5196
|
schemaHash3 = objectType({
|
|
@@ -5246,6 +5251,13 @@ var init_sqliteSchema = __esm({
|
|
|
5246
5251
|
});
|
|
5247
5252
|
return result;
|
|
5248
5253
|
},
|
|
5254
|
+
squashUnique: (unq) => {
|
|
5255
|
+
return `${unq.name};${unq.columns.join(",")}`;
|
|
5256
|
+
},
|
|
5257
|
+
unsquashUnique: (unq) => {
|
|
5258
|
+
const [name, columns] = unq.split(";");
|
|
5259
|
+
return { name, columns: columns.split(",") };
|
|
5260
|
+
},
|
|
5249
5261
|
squashFK: (fk4) => {
|
|
5250
5262
|
return `${fk4.name};${fk4.tableFrom};${fk4.columnsFrom.join(",")};${fk4.tableTo};${fk4.columnsTo.join(",")};${fk4.onUpdate ?? ""};${fk4.onDelete ?? ""}`;
|
|
5251
5263
|
},
|
|
@@ -5289,6 +5301,9 @@ var init_sqliteSchema = __esm({
|
|
|
5289
5301
|
const squashedPKs = mapValues(it[1].compositePrimaryKeys, (pk) => {
|
|
5290
5302
|
return SQLiteSquasher.squashPK(pk);
|
|
5291
5303
|
});
|
|
5304
|
+
const squashedUniqueConstraints = mapValues(it[1].uniqueConstraints, (unq) => {
|
|
5305
|
+
return SQLiteSquasher.squashUnique(unq);
|
|
5306
|
+
});
|
|
5292
5307
|
return [
|
|
5293
5308
|
it[0],
|
|
5294
5309
|
{
|
|
@@ -5296,7 +5311,8 @@ var init_sqliteSchema = __esm({
|
|
|
5296
5311
|
columns: it[1].columns,
|
|
5297
5312
|
indexes: squashedIndexes,
|
|
5298
5313
|
foreignKeys: squashedFKs,
|
|
5299
|
-
compositePrimaryKeys: squashedPKs
|
|
5314
|
+
compositePrimaryKeys: squashedPKs,
|
|
5315
|
+
uniqueConstraints: squashedUniqueConstraints
|
|
5300
5316
|
}
|
|
5301
5317
|
];
|
|
5302
5318
|
})
|
|
@@ -11368,6 +11384,71 @@ var init_mysqlImports = __esm({
|
|
|
11368
11384
|
}
|
|
11369
11385
|
});
|
|
11370
11386
|
|
|
11387
|
+
// src/cli/validations/outputs.ts
|
|
11388
|
+
var withStyle, outputs;
|
|
11389
|
+
var init_outputs = __esm({
|
|
11390
|
+
"src/cli/validations/outputs.ts"() {
|
|
11391
|
+
init_source();
|
|
11392
|
+
withStyle = {
|
|
11393
|
+
error: (str) => `${source_default.red(`${source_default.white.bgRed(" Invalid input ")} ${str}`)}`,
|
|
11394
|
+
warning: (str) => `${source_default.white.bgGray(" Warning ")} ${str}`,
|
|
11395
|
+
errorWarning: (str) => `${source_default.red(`${source_default.white.bgRed(" Warning ")} ${str}`)}`,
|
|
11396
|
+
fullWarning: (str) => `${source_default.black.bgYellow("[Warning]")} ${source_default.bold(str)}`
|
|
11397
|
+
};
|
|
11398
|
+
outputs = {
|
|
11399
|
+
studio: {
|
|
11400
|
+
drivers: (param) => withStyle.error(
|
|
11401
|
+
`"${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`
|
|
11402
|
+
),
|
|
11403
|
+
noCredentials: () => withStyle.error(
|
|
11404
|
+
`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`
|
|
11405
|
+
),
|
|
11406
|
+
noDriver: () => withStyle.error(
|
|
11407
|
+
`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`
|
|
11408
|
+
)
|
|
11409
|
+
},
|
|
11410
|
+
common: {
|
|
11411
|
+
ambiguousParams: (command) => withStyle.error(
|
|
11412
|
+
`You can't use both --config and other cli options for ${command} command`
|
|
11413
|
+
),
|
|
11414
|
+
schema: (command) => withStyle.error(`"--schema" is a required field for ${command} command`),
|
|
11415
|
+
schemaConfig: (command) => withStyle.error(
|
|
11416
|
+
`"schema" is a required field in drizzle.config for ${command} command`
|
|
11417
|
+
)
|
|
11418
|
+
},
|
|
11419
|
+
postgres: {
|
|
11420
|
+
connection: {
|
|
11421
|
+
driver: () => withStyle.error(`Only "pg" is available options for "--driver"`),
|
|
11422
|
+
required: () => withStyle.error(
|
|
11423
|
+
`Either "connectionString" or "host", "database" are required for database connection`
|
|
11424
|
+
)
|
|
11425
|
+
}
|
|
11426
|
+
},
|
|
11427
|
+
mysql: {
|
|
11428
|
+
connection: {
|
|
11429
|
+
driver: () => withStyle.error(`Only "mysql2" is available options for "--driver"`),
|
|
11430
|
+
required: () => withStyle.error(
|
|
11431
|
+
`Either "connectionString" or "host", "database" are required for database connection`
|
|
11432
|
+
)
|
|
11433
|
+
}
|
|
11434
|
+
},
|
|
11435
|
+
sqlite: {
|
|
11436
|
+
connection: {
|
|
11437
|
+
driver: () => withStyle.error(
|
|
11438
|
+
`Either "turso", "libsql", "better-sqlite" are available options for "--driver"`
|
|
11439
|
+
),
|
|
11440
|
+
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`),
|
|
11441
|
+
authToken: (driver) => withStyle.error(
|
|
11442
|
+
`"authToken" is a required option for driver "${driver}". You can read more about drizzle.config: https://orm.drizzle.team/kit-docs/config-reference`
|
|
11443
|
+
)
|
|
11444
|
+
},
|
|
11445
|
+
introspect: {},
|
|
11446
|
+
push: {}
|
|
11447
|
+
}
|
|
11448
|
+
};
|
|
11449
|
+
}
|
|
11450
|
+
});
|
|
11451
|
+
|
|
11371
11452
|
// src/serializer/mysqlSerializer.ts
|
|
11372
11453
|
var mysqlSerializer_exports = {};
|
|
11373
11454
|
__export(mysqlSerializer_exports, {
|
|
@@ -11400,6 +11481,8 @@ var init_mysqlSerializer = __esm({
|
|
|
11400
11481
|
import_mysql_core3 = require("drizzle-orm/mysql-core");
|
|
11401
11482
|
import_drizzle_orm3 = require("drizzle-orm");
|
|
11402
11483
|
init_serializer();
|
|
11484
|
+
init_outputs();
|
|
11485
|
+
init_source();
|
|
11403
11486
|
dialect3 = new import_mysql_core2.MySqlDialect();
|
|
11404
11487
|
indexName = (tableName, columns) => {
|
|
11405
11488
|
return `${tableName}_${columns.join("_")}_index`;
|
|
@@ -11442,6 +11525,24 @@ var init_mysqlSerializer = __esm({
|
|
|
11442
11525
|
// : undefined,
|
|
11443
11526
|
};
|
|
11444
11527
|
if (column7.isUnique) {
|
|
11528
|
+
const existingUnique = uniqueConstraintObject[column7.uniqueName];
|
|
11529
|
+
if (typeof existingUnique !== "undefined") {
|
|
11530
|
+
console.log(
|
|
11531
|
+
`
|
|
11532
|
+
${withStyle.errorWarning(`We've found duplicated unique constraint names in ${source_default.underline.blue(
|
|
11533
|
+
tableName
|
|
11534
|
+
)} table.
|
|
11535
|
+
The unique constraint ${source_default.underline.blue(
|
|
11536
|
+
column7.uniqueName
|
|
11537
|
+
)} on the ${source_default.underline.blue(
|
|
11538
|
+
column7.name
|
|
11539
|
+
)} column is confilcting with a unique constraint name already defined for ${source_default.underline.blue(
|
|
11540
|
+
existingUnique.columns.join(",")
|
|
11541
|
+
)} columns
|
|
11542
|
+
`)}`
|
|
11543
|
+
);
|
|
11544
|
+
process.exit(1);
|
|
11545
|
+
}
|
|
11445
11546
|
uniqueConstraintObject[column7.uniqueName] = {
|
|
11446
11547
|
name: column7.uniqueName,
|
|
11447
11548
|
columns: [columnToSet.name]
|
|
@@ -11483,9 +11584,29 @@ var init_mysqlSerializer = __esm({
|
|
|
11483
11584
|
columnsObject[column7.name].notNull = true;
|
|
11484
11585
|
}
|
|
11485
11586
|
});
|
|
11486
|
-
uniqueConstraints.map((unq) => {
|
|
11587
|
+
uniqueConstraints == null ? void 0 : uniqueConstraints.map((unq) => {
|
|
11487
11588
|
const columnNames = unq.columns.map((c) => c.name);
|
|
11488
11589
|
const name = unq.name ?? (0, import_mysql_core2.uniqueKeyName)(table4, columnNames);
|
|
11590
|
+
const existingUnique = uniqueConstraintObject[name];
|
|
11591
|
+
if (typeof existingUnique !== "undefined") {
|
|
11592
|
+
console.log(
|
|
11593
|
+
`
|
|
11594
|
+
${withStyle.errorWarning(
|
|
11595
|
+
`We've found duplicated unique constraint names in ${source_default.underline.blue(
|
|
11596
|
+
tableName
|
|
11597
|
+
)} table.
|
|
11598
|
+
The unique constraint ${source_default.underline.blue(
|
|
11599
|
+
name
|
|
11600
|
+
)} on the ${source_default.underline.blue(
|
|
11601
|
+
columnNames.join(",")
|
|
11602
|
+
)} columns is confilcting with a unique constraint name already defined for ${source_default.underline.blue(
|
|
11603
|
+
existingUnique.columns.join(",")
|
|
11604
|
+
)} columns
|
|
11605
|
+
`
|
|
11606
|
+
)}`
|
|
11607
|
+
);
|
|
11608
|
+
process.exit(1);
|
|
11609
|
+
}
|
|
11489
11610
|
uniqueConstraintObject[name] = {
|
|
11490
11611
|
name: unq.name,
|
|
11491
11612
|
columns: columnNames
|
|
@@ -11618,7 +11739,7 @@ var init_mysqlSerializer = __esm({
|
|
|
11618
11739
|
onUpdate = true;
|
|
11619
11740
|
}
|
|
11620
11741
|
const newColumn = {
|
|
11621
|
-
default: columnDefault === null ? void 0 : /^-?[\d.]+(?:e-?\d+)?$/.test(columnDefault) ? Number(columnDefault) : isDefaultAnExpression ? clearDefaults(columnDefault, collation) : `'${columnDefault}'`,
|
|
11742
|
+
default: columnDefault === null ? void 0 : /^-?[\d.]+(?:e-?\d+)?$/.test(columnDefault) && !columnType.startsWith("decimal") ? Number(columnDefault) : isDefaultAnExpression ? clearDefaults(columnDefault, collation) : `'${columnDefault}'`,
|
|
11622
11743
|
autoincrement: isAutoincrement,
|
|
11623
11744
|
name: columnName,
|
|
11624
11745
|
type: changedType,
|
|
@@ -11635,7 +11756,8 @@ var init_mysqlSerializer = __esm({
|
|
|
11635
11756
|
},
|
|
11636
11757
|
compositePrimaryKeys: {},
|
|
11637
11758
|
indexes: {},
|
|
11638
|
-
foreignKeys: {}
|
|
11759
|
+
foreignKeys: {},
|
|
11760
|
+
uniqueConstraints: {}
|
|
11639
11761
|
};
|
|
11640
11762
|
} else {
|
|
11641
11763
|
result[tableName].columns[columnName] = newColumn;
|
|
@@ -11734,14 +11856,27 @@ var init_mysqlSerializer = __esm({
|
|
|
11734
11856
|
if (progressCallback) {
|
|
11735
11857
|
progressCallback("indexes", indexesCount, "fetching");
|
|
11736
11858
|
}
|
|
11737
|
-
if (
|
|
11738
|
-
tableInResult.
|
|
11859
|
+
if (isUnique) {
|
|
11860
|
+
if (typeof tableInResult.uniqueConstraints[constraintName] !== "undefined") {
|
|
11861
|
+
tableInResult.uniqueConstraints[constraintName].columns.push(
|
|
11862
|
+
columnName
|
|
11863
|
+
);
|
|
11864
|
+
} else {
|
|
11865
|
+
tableInResult.uniqueConstraints[constraintName] = {
|
|
11866
|
+
name: constraintName,
|
|
11867
|
+
columns: [columnName]
|
|
11868
|
+
};
|
|
11869
|
+
}
|
|
11739
11870
|
} else {
|
|
11740
|
-
tableInResult.indexes[constraintName]
|
|
11741
|
-
|
|
11742
|
-
|
|
11743
|
-
|
|
11744
|
-
|
|
11871
|
+
if (typeof tableInResult.indexes[constraintName] !== "undefined") {
|
|
11872
|
+
tableInResult.indexes[constraintName].columns.push(columnName);
|
|
11873
|
+
} else {
|
|
11874
|
+
tableInResult.indexes[constraintName] = {
|
|
11875
|
+
name: constraintName,
|
|
11876
|
+
columns: [columnName],
|
|
11877
|
+
isUnique
|
|
11878
|
+
};
|
|
11879
|
+
}
|
|
11745
11880
|
}
|
|
11746
11881
|
}
|
|
11747
11882
|
if (progressCallback) {
|
|
@@ -11818,6 +11953,8 @@ var init_pgSerializer = __esm({
|
|
|
11818
11953
|
import_drizzle_orm5 = require("drizzle-orm");
|
|
11819
11954
|
import_drizzle_orm6 = require("drizzle-orm");
|
|
11820
11955
|
init_serializer();
|
|
11956
|
+
init_source();
|
|
11957
|
+
init_outputs();
|
|
11821
11958
|
dialect4 = new import_pg_core2.PgDialect();
|
|
11822
11959
|
indexName2 = (tableName, columns) => {
|
|
11823
11960
|
return `${tableName}_${columns.join("_")}_index`;
|
|
@@ -11851,6 +11988,24 @@ var init_pgSerializer = __esm({
|
|
|
11851
11988
|
notNull
|
|
11852
11989
|
};
|
|
11853
11990
|
if (column7.isUnique) {
|
|
11991
|
+
const existingUnique = uniqueConstraintObject[column7.uniqueName];
|
|
11992
|
+
if (typeof existingUnique !== "undefined") {
|
|
11993
|
+
console.log(
|
|
11994
|
+
`
|
|
11995
|
+
${withStyle.errorWarning(`We've found duplicated unique constraint names in ${source_default.underline.blue(
|
|
11996
|
+
tableName
|
|
11997
|
+
)} table.
|
|
11998
|
+
The unique constraint ${source_default.underline.blue(
|
|
11999
|
+
column7.uniqueName
|
|
12000
|
+
)} on the ${source_default.underline.blue(
|
|
12001
|
+
column7.name
|
|
12002
|
+
)} column is confilcting with a unique constraint name already defined for ${source_default.underline.blue(
|
|
12003
|
+
existingUnique.columns.join(",")
|
|
12004
|
+
)} columns
|
|
12005
|
+
`)}`
|
|
12006
|
+
);
|
|
12007
|
+
process.exit(1);
|
|
12008
|
+
}
|
|
11854
12009
|
uniqueConstraintObject[column7.uniqueName] = {
|
|
11855
12010
|
name: column7.uniqueName,
|
|
11856
12011
|
nullsNotDistinct: column7.uniqueType === "not distinct",
|
|
@@ -11891,9 +12046,27 @@ var init_pgSerializer = __esm({
|
|
|
11891
12046
|
columns: columnNames
|
|
11892
12047
|
};
|
|
11893
12048
|
});
|
|
11894
|
-
uniqueConstraints.map((unq) => {
|
|
12049
|
+
uniqueConstraints == null ? void 0 : uniqueConstraints.map((unq) => {
|
|
11895
12050
|
const columnNames = unq.columns.map((c) => c.name);
|
|
11896
12051
|
const name = unq.name ?? (0, import_pg_core2.uniqueKeyName)(table4, columnNames);
|
|
12052
|
+
const existingUnique = uniqueConstraintObject[name];
|
|
12053
|
+
if (typeof existingUnique !== "undefined") {
|
|
12054
|
+
console.log(
|
|
12055
|
+
`
|
|
12056
|
+
${withStyle.errorWarning(`We've found duplicated unique constraint names in ${source_default.underline.blue(
|
|
12057
|
+
tableName
|
|
12058
|
+
)} table.
|
|
12059
|
+
The unique constraint ${source_default.underline.blue(
|
|
12060
|
+
name
|
|
12061
|
+
)} on the ${source_default.underline.blue(
|
|
12062
|
+
columnNames.join(",")
|
|
12063
|
+
)} columns is confilcting with a unique constraint name already defined for ${source_default.underline.blue(
|
|
12064
|
+
existingUnique.columns.join(",")
|
|
12065
|
+
)} columns
|
|
12066
|
+
`)}`
|
|
12067
|
+
);
|
|
12068
|
+
process.exit(1);
|
|
12069
|
+
}
|
|
11897
12070
|
uniqueConstraintObject[name] = {
|
|
11898
12071
|
name: unq.name,
|
|
11899
12072
|
nullsNotDistinct: unq.nullsNotDistinct,
|
|
@@ -12009,6 +12182,7 @@ var init_pgSerializer = __esm({
|
|
|
12009
12182
|
const indexToReturn = {};
|
|
12010
12183
|
const foreignKeysToReturn = {};
|
|
12011
12184
|
const primaryKeys = {};
|
|
12185
|
+
const uniqueConstrains = {};
|
|
12012
12186
|
const tableResponse = await db.query(
|
|
12013
12187
|
`SELECT a.attrelid::regclass::text, a.attname, is_nullable, a.attndims as array_dimensions
|
|
12014
12188
|
, CASE WHEN a.atttypid = ANY ('{int,int8,int2}'::regtype[])
|
|
@@ -12102,6 +12276,22 @@ var init_pgSerializer = __esm({
|
|
|
12102
12276
|
...new Set(foreignKeysToReturn[foreignKeyName].columnsTo)
|
|
12103
12277
|
];
|
|
12104
12278
|
}
|
|
12279
|
+
const uniqueConstrainsRows = tableConstraints.rows.filter(
|
|
12280
|
+
(mapRow) => mapRow.constraint_type === "UNIQUE"
|
|
12281
|
+
);
|
|
12282
|
+
for (const unqs of uniqueConstrainsRows) {
|
|
12283
|
+
const columnName = unqs.column_name;
|
|
12284
|
+
const constraintName = unqs.constraint_name;
|
|
12285
|
+
if (typeof uniqueConstrains[constraintName] !== "undefined") {
|
|
12286
|
+
uniqueConstrains[constraintName].columns.push(columnName);
|
|
12287
|
+
} else {
|
|
12288
|
+
uniqueConstrains[constraintName] = {
|
|
12289
|
+
columns: [columnName],
|
|
12290
|
+
nullsNotDistinct: false,
|
|
12291
|
+
name: constraintName
|
|
12292
|
+
};
|
|
12293
|
+
}
|
|
12294
|
+
}
|
|
12105
12295
|
for (const columnResponse of tableResponse.rows) {
|
|
12106
12296
|
const columnName = columnResponse.attname;
|
|
12107
12297
|
const columnAdditionalDT = columnResponse.additional_dt;
|
|
@@ -12127,9 +12317,6 @@ var init_pgSerializer = __esm({
|
|
|
12127
12317
|
columns: cprimaryKey.map((c) => c.column_name)
|
|
12128
12318
|
};
|
|
12129
12319
|
}
|
|
12130
|
-
const uniqueKey = tableConstraints.rows.filter(
|
|
12131
|
-
(mapRow) => columnName === mapRow.column_name && mapRow.constraint_type === "UNIQUE"
|
|
12132
|
-
);
|
|
12133
12320
|
const defaultValue = defaultForColumn(columnResponse);
|
|
12134
12321
|
const isSerial = columnType === "serial";
|
|
12135
12322
|
let columnTypeMapped = columnType;
|
|
@@ -12177,10 +12364,25 @@ var init_pgSerializer = __esm({
|
|
|
12177
12364
|
t.relname,
|
|
12178
12365
|
i.relname;`
|
|
12179
12366
|
);
|
|
12367
|
+
const dbIndexFromConstraint = await db.query(
|
|
12368
|
+
`SELECT
|
|
12369
|
+
idx.indexrelname AS index_name,
|
|
12370
|
+
idx.relname AS table_name,
|
|
12371
|
+
con.conname,
|
|
12372
|
+
CASE WHEN con.conname IS NOT NULL THEN 1 ELSE 0 END AS generated_by_constraint
|
|
12373
|
+
FROM
|
|
12374
|
+
pg_stat_user_indexes idx
|
|
12375
|
+
LEFT JOIN
|
|
12376
|
+
pg_constraint con ON con.conindid = idx.indexrelid
|
|
12377
|
+
WHERE idx.relname = '${tableName}';`
|
|
12378
|
+
);
|
|
12379
|
+
const idxsInConsteraint = dbIndexFromConstraint.rows.filter((it) => it.generated_by_constraint === 1).map((it) => it.index_name);
|
|
12180
12380
|
for (const dbIndex of dbIndexes.rows) {
|
|
12181
12381
|
const indexName4 = dbIndex.index_name;
|
|
12182
12382
|
const indexColumnName = dbIndex.column_name;
|
|
12183
12383
|
const indexIsUnique = dbIndex.is_unique;
|
|
12384
|
+
if (idxsInConsteraint.includes(indexName4))
|
|
12385
|
+
continue;
|
|
12184
12386
|
if (typeof indexToReturn[indexName4] !== "undefined") {
|
|
12185
12387
|
indexToReturn[indexName4].columns.push(indexColumnName);
|
|
12186
12388
|
} else {
|
|
@@ -12201,7 +12403,8 @@ var init_pgSerializer = __esm({
|
|
|
12201
12403
|
columns: columnToReturn,
|
|
12202
12404
|
indexes: indexToReturn,
|
|
12203
12405
|
foreignKeys: foreignKeysToReturn,
|
|
12204
|
-
compositePrimaryKeys: primaryKeys
|
|
12406
|
+
compositePrimaryKeys: primaryKeys,
|
|
12407
|
+
uniqueConstraints: uniqueConstrains
|
|
12205
12408
|
};
|
|
12206
12409
|
} catch (e) {
|
|
12207
12410
|
rej(e);
|
|
@@ -12396,6 +12599,8 @@ var init_sqliteSerializer = __esm({
|
|
|
12396
12599
|
import_drizzle_orm9 = require("drizzle-orm");
|
|
12397
12600
|
import_sqlite_core2 = require("drizzle-orm/sqlite-core");
|
|
12398
12601
|
init_serializer();
|
|
12602
|
+
init_outputs();
|
|
12603
|
+
init_source();
|
|
12399
12604
|
dialect5 = new import_sqlite_core2.SQLiteSyncDialect();
|
|
12400
12605
|
generateSqliteSnapshot = (tables, enums) => {
|
|
12401
12606
|
const result = {};
|
|
@@ -12404,12 +12609,14 @@ var init_sqliteSerializer = __esm({
|
|
|
12404
12609
|
const indexesObject = {};
|
|
12405
12610
|
const foreignKeysObject = {};
|
|
12406
12611
|
const primaryKeysObject = {};
|
|
12612
|
+
const uniqueConstraintObject = {};
|
|
12407
12613
|
const {
|
|
12408
12614
|
name: tableName,
|
|
12409
12615
|
columns,
|
|
12410
12616
|
indexes,
|
|
12411
12617
|
foreignKeys: tableForeignKeys,
|
|
12412
|
-
primaryKeys
|
|
12618
|
+
primaryKeys,
|
|
12619
|
+
uniqueConstraints
|
|
12413
12620
|
} = (0, import_sqlite_core2.getTableConfig)(table4);
|
|
12414
12621
|
columns.forEach((column7) => {
|
|
12415
12622
|
const notNull = column7.notNull;
|
|
@@ -12429,6 +12636,31 @@ var init_sqliteSerializer = __esm({
|
|
|
12429
12636
|
}
|
|
12430
12637
|
}
|
|
12431
12638
|
columnsObject[column7.name] = columnToSet;
|
|
12639
|
+
if (column7.isUnique) {
|
|
12640
|
+
const existingUnique = indexesObject[column7.uniqueName];
|
|
12641
|
+
if (typeof existingUnique !== "undefined") {
|
|
12642
|
+
console.log(
|
|
12643
|
+
`
|
|
12644
|
+
${withStyle.errorWarning(`We've found duplicated unique constraint names in ${source_default.underline.blue(
|
|
12645
|
+
tableName
|
|
12646
|
+
)} table.
|
|
12647
|
+
The unique constraint ${source_default.underline.blue(
|
|
12648
|
+
column7.uniqueName
|
|
12649
|
+
)} on the ${source_default.underline.blue(
|
|
12650
|
+
column7.name
|
|
12651
|
+
)} column is confilcting with a unique constraint name already defined for ${source_default.underline.blue(
|
|
12652
|
+
existingUnique.columns.join(",")
|
|
12653
|
+
)} columns
|
|
12654
|
+
`)}`
|
|
12655
|
+
);
|
|
12656
|
+
process.exit(1);
|
|
12657
|
+
}
|
|
12658
|
+
indexesObject[column7.uniqueName] = {
|
|
12659
|
+
name: column7.uniqueName,
|
|
12660
|
+
columns: [columnToSet.name],
|
|
12661
|
+
isUnique: true
|
|
12662
|
+
};
|
|
12663
|
+
}
|
|
12432
12664
|
});
|
|
12433
12665
|
const foreignKeys = tableForeignKeys.map((fk4) => {
|
|
12434
12666
|
const name = fk4.getName();
|
|
@@ -12476,6 +12708,35 @@ var init_sqliteSerializer = __esm({
|
|
|
12476
12708
|
where
|
|
12477
12709
|
};
|
|
12478
12710
|
});
|
|
12711
|
+
uniqueConstraints == null ? void 0 : uniqueConstraints.map((unq) => {
|
|
12712
|
+
const columnNames = unq.columns.map((c) => c.name);
|
|
12713
|
+
const name = unq.name ?? (0, import_sqlite_core2.uniqueKeyName)(table4, columnNames);
|
|
12714
|
+
const existingUnique = indexesObject[name];
|
|
12715
|
+
if (typeof existingUnique !== "undefined") {
|
|
12716
|
+
console.log(
|
|
12717
|
+
`
|
|
12718
|
+
${withStyle.errorWarning(
|
|
12719
|
+
`We've found duplicated unique constraint names in ${source_default.underline.blue(
|
|
12720
|
+
tableName
|
|
12721
|
+
)} table.
|
|
12722
|
+
The unique constraint ${source_default.underline.blue(
|
|
12723
|
+
name
|
|
12724
|
+
)} on the ${source_default.underline.blue(
|
|
12725
|
+
columnNames.join(",")
|
|
12726
|
+
)} columns is confilcting with a unique constraint name already defined for ${source_default.underline.blue(
|
|
12727
|
+
existingUnique.columns.join(",")
|
|
12728
|
+
)} columns
|
|
12729
|
+
`
|
|
12730
|
+
)}`
|
|
12731
|
+
);
|
|
12732
|
+
process.exit(1);
|
|
12733
|
+
}
|
|
12734
|
+
indexesObject[name] = {
|
|
12735
|
+
name: unq.name,
|
|
12736
|
+
columns: columnNames,
|
|
12737
|
+
isUnique: true
|
|
12738
|
+
};
|
|
12739
|
+
});
|
|
12479
12740
|
primaryKeys.forEach((it) => {
|
|
12480
12741
|
if (it.columns.length > 1) {
|
|
12481
12742
|
primaryKeysObject[it.getName()] = {
|
|
@@ -12490,7 +12751,8 @@ var init_sqliteSerializer = __esm({
|
|
|
12490
12751
|
columns: columnsObject,
|
|
12491
12752
|
indexes: indexesObject,
|
|
12492
12753
|
foreignKeys: foreignKeysObject,
|
|
12493
|
-
compositePrimaryKeys: primaryKeysObject
|
|
12754
|
+
compositePrimaryKeys: primaryKeysObject,
|
|
12755
|
+
uniqueConstraints: uniqueConstraintObject
|
|
12494
12756
|
};
|
|
12495
12757
|
}
|
|
12496
12758
|
return {
|
|
@@ -12574,7 +12836,8 @@ var init_sqliteSerializer = __esm({
|
|
|
12574
12836
|
},
|
|
12575
12837
|
compositePrimaryKeys: {},
|
|
12576
12838
|
indexes: {},
|
|
12577
|
-
foreignKeys: {}
|
|
12839
|
+
foreignKeys: {},
|
|
12840
|
+
uniqueConstraints: {}
|
|
12578
12841
|
};
|
|
12579
12842
|
} else {
|
|
12580
12843
|
result[tableName].columns[columnName] = newColumn;
|
|
@@ -12659,7 +12922,7 @@ FROM sqlite_master AS m,
|
|
|
12659
12922
|
pragma_index_list(m.name) AS il,
|
|
12660
12923
|
pragma_index_info(il.name) AS ii
|
|
12661
12924
|
WHERE
|
|
12662
|
-
m.type = 'table'
|
|
12925
|
+
m.type = 'table';`
|
|
12663
12926
|
);
|
|
12664
12927
|
for (const idxRow of idxs) {
|
|
12665
12928
|
const tableName = idxRow.tableName;
|
|
@@ -14630,7 +14893,7 @@ ${sql}
|
|
|
14630
14893
|
});
|
|
14631
14894
|
|
|
14632
14895
|
// 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;
|
|
14896
|
+
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
14897
|
var init_sqlgenerator = __esm({
|
|
14635
14898
|
"src/sqlgenerator.ts"() {
|
|
14636
14899
|
init_migrate();
|
|
@@ -14701,9 +14964,9 @@ var init_sqlgenerator = __esm({
|
|
|
14701
14964
|
const primaryKeyStatement = column7.primaryKey ? " PRIMARY KEY" : "";
|
|
14702
14965
|
const notNullStatement = column7.notNull ? " NOT NULL" : "";
|
|
14703
14966
|
const defaultStatement = column7.default !== void 0 ? ` DEFAULT ${column7.default}` : "";
|
|
14704
|
-
const
|
|
14967
|
+
const uniqueConstraint4 = column7.isUnique ? ` CONSTRAINT "${column7.uniqueName}" UNIQUE${column7.nullsNotDistinct ? " NULLS NOT DISTINCT" : ""}` : "";
|
|
14705
14968
|
const type = isPgNativeType(column7.type) ? column7.type : `"${column7.type}"`;
|
|
14706
|
-
statement += ` "${column7.name}" ${type}${primaryKeyStatement}${defaultStatement}${notNullStatement}${
|
|
14969
|
+
statement += ` "${column7.name}" ${type}${primaryKeyStatement}${defaultStatement}${notNullStatement}${uniqueConstraint4}`;
|
|
14707
14970
|
statement += i === columns.length - 1 ? "" : ",\n";
|
|
14708
14971
|
}
|
|
14709
14972
|
if (typeof compositePKs !== "undefined" && compositePKs.length > 0) {
|
|
@@ -14712,10 +14975,10 @@ var init_sqlgenerator = __esm({
|
|
|
14712
14975
|
statement += ` CONSTRAINT ${st.compositePkName} PRIMARY KEY("${compositePK4.columns.join(`","`)}")`;
|
|
14713
14976
|
}
|
|
14714
14977
|
if (typeof uniqueConstraints !== "undefined" && uniqueConstraints.length > 0) {
|
|
14715
|
-
for (const
|
|
14978
|
+
for (const uniqueConstraint4 of uniqueConstraints) {
|
|
14716
14979
|
statement += ",\n";
|
|
14717
|
-
const unsquashedUnique = PgSquasher.unsquashUnique(
|
|
14718
|
-
statement += ` CONSTRAINT ${unsquashedUnique.name} UNIQUE("${unsquashedUnique.columns.join(`","`)}")`;
|
|
14980
|
+
const unsquashedUnique = PgSquasher.unsquashUnique(uniqueConstraint4);
|
|
14981
|
+
statement += ` CONSTRAINT "${unsquashedUnique.name}" UNIQUE${unsquashedUnique.nullsNotDistinct ? " NULLS NOT DISTINCT" : ""}("${unsquashedUnique.columns.join(`","`)}")`;
|
|
14719
14982
|
}
|
|
14720
14983
|
}
|
|
14721
14984
|
statement += `
|
|
@@ -14748,13 +15011,13 @@ var init_sqlgenerator = __esm({
|
|
|
14748
15011
|
if (typeof compositePKs !== "undefined" && compositePKs.length > 0) {
|
|
14749
15012
|
statement += ",\n";
|
|
14750
15013
|
const compositePK4 = MySqlSquasher.unsquashPK(compositePKs[0]);
|
|
14751
|
-
statement += ` CONSTRAINT
|
|
15014
|
+
statement += ` CONSTRAINT \`${st.compositePkName}\` PRIMARY KEY("${compositePK4.columns.join(`","`)}")`;
|
|
14752
15015
|
}
|
|
14753
15016
|
if (typeof uniqueConstraints !== "undefined" && uniqueConstraints.length > 0) {
|
|
14754
|
-
for (const
|
|
15017
|
+
for (const uniqueConstraint4 of uniqueConstraints) {
|
|
14755
15018
|
statement += ",\n";
|
|
14756
|
-
const unsquashedUnique = MySqlSquasher.unsquashUnique(
|
|
14757
|
-
statement += ` CONSTRAINT
|
|
15019
|
+
const unsquashedUnique = MySqlSquasher.unsquashUnique(uniqueConstraint4);
|
|
15020
|
+
statement += ` CONSTRAINT \`${unsquashedUnique.name}\` UNIQUE(\`${unsquashedUnique.columns.join(`\`,\``)}\`)`;
|
|
14758
15021
|
}
|
|
14759
15022
|
}
|
|
14760
15023
|
statement += `
|
|
@@ -14769,21 +15032,28 @@ var init_sqlgenerator = __esm({
|
|
|
14769
15032
|
return statement.type === "sqlite_create_table" && dialect6 === "sqlite";
|
|
14770
15033
|
}
|
|
14771
15034
|
convert(st) {
|
|
14772
|
-
const {
|
|
15035
|
+
const {
|
|
15036
|
+
tableName,
|
|
15037
|
+
columns,
|
|
15038
|
+
referenceData,
|
|
15039
|
+
compositePKs,
|
|
15040
|
+
uniqueConstraints
|
|
15041
|
+
} = st;
|
|
14773
15042
|
let statement = "";
|
|
14774
|
-
statement += `CREATE TABLE \`${tableName}\` (
|
|
15043
|
+
statement += `CREATE TABLE \`${tableName}\` (
|
|
15044
|
+
`;
|
|
14775
15045
|
for (let i = 0; i < columns.length; i++) {
|
|
14776
15046
|
const column7 = columns[i];
|
|
14777
15047
|
const primaryKeyStatement = column7.primaryKey ? " PRIMARY KEY" : "";
|
|
14778
15048
|
const notNullStatement = column7.notNull ? " NOT NULL" : "";
|
|
14779
15049
|
const defaultStatement = column7.default !== void 0 ? ` DEFAULT ${column7.default}` : "";
|
|
14780
15050
|
const autoincrementStatement = column7.autoincrement ? " AUTOINCREMENT" : "";
|
|
14781
|
-
statement += "
|
|
15051
|
+
statement += " ";
|
|
14782
15052
|
statement += `\`${column7.name}\` ${column7.type}${primaryKeyStatement}${autoincrementStatement}${defaultStatement}${notNullStatement}`;
|
|
14783
|
-
statement += "
|
|
15053
|
+
statement += i === columns.length - 1 ? "" : ",\n";
|
|
14784
15054
|
}
|
|
14785
15055
|
compositePKs.forEach((it) => {
|
|
14786
|
-
statement += "
|
|
15056
|
+
statement += ",\n ";
|
|
14787
15057
|
statement += `PRIMARY KEY(${it.map((it2) => `\`${it2}\``).join(", ")}),`;
|
|
14788
15058
|
});
|
|
14789
15059
|
for (let i = 0; i < referenceData.length; i++) {
|
|
@@ -14801,11 +15071,17 @@ var init_sqlgenerator = __esm({
|
|
|
14801
15071
|
const onUpdateStatement = onUpdate ? ` ON UPDATE ${onUpdate}` : "";
|
|
14802
15072
|
const fromColumnsString = columnsFrom.map((it) => `\`${it}\``).join(",");
|
|
14803
15073
|
const toColumnsString = columnsTo.map((it) => `\`${it}\``).join(",");
|
|
15074
|
+
statement += ",";
|
|
14804
15075
|
statement += "\n ";
|
|
14805
15076
|
statement += `FOREIGN KEY (${fromColumnsString}) REFERENCES \`${tableTo}\`(${toColumnsString})${onUpdateStatement}${onDeleteStatement}`;
|
|
14806
|
-
statement += ",";
|
|
14807
15077
|
}
|
|
14808
|
-
|
|
15078
|
+
if (typeof uniqueConstraints !== "undefined" && uniqueConstraints.length > 0) {
|
|
15079
|
+
for (const uniqueConstraint4 of uniqueConstraints) {
|
|
15080
|
+
statement += ",\n";
|
|
15081
|
+
const unsquashedUnique = MySqlSquasher.unsquashUnique(uniqueConstraint4);
|
|
15082
|
+
statement += ` CONSTRAINT ${unsquashedUnique.name} UNIQUE(\`${unsquashedUnique.columns.join(`\`,\``)}\`)`;
|
|
15083
|
+
}
|
|
15084
|
+
}
|
|
14809
15085
|
statement += `
|
|
14810
15086
|
`;
|
|
14811
15087
|
statement += `);`;
|
|
@@ -14821,7 +15097,7 @@ var init_sqlgenerator = __esm({
|
|
|
14821
15097
|
convert(statement) {
|
|
14822
15098
|
const unsquashed = PgSquasher.unsquashUnique(statement.data);
|
|
14823
15099
|
const tableNameWithSchema = statement.schema ? `"${statement.schema}"."${statement.tableName}"` : `"${statement.tableName}"`;
|
|
14824
|
-
return `ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT "${unsquashed.name}" UNIQUE("${unsquashed.columns.join('","')}");`;
|
|
15100
|
+
return `ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT "${unsquashed.name}" UNIQUE${unsquashed.nullsNotDistinct ? " NULLS NOT DISTINCT" : ""}("${unsquashed.columns.join('","')}");`;
|
|
14825
15101
|
}
|
|
14826
15102
|
};
|
|
14827
15103
|
PgAlterTableDropUniqueConstraintConvertor = class extends Convertor {
|
|
@@ -14854,6 +15130,32 @@ var init_sqlgenerator = __esm({
|
|
|
14854
15130
|
return `ALTER TABLE ${tableNameWithSchema} DROP CONSTRAINT \`${unsquashed.name}\`;`;
|
|
14855
15131
|
}
|
|
14856
15132
|
};
|
|
15133
|
+
SQLiteAlterTableAddUniqueConstraintConvertor = class extends Convertor {
|
|
15134
|
+
can(statement, dialect6) {
|
|
15135
|
+
return statement.type === "create_unique_constraint" && dialect6 === "sqlite";
|
|
15136
|
+
}
|
|
15137
|
+
convert(statement) {
|
|
15138
|
+
return `/*
|
|
15139
|
+
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
|
|
15140
|
+
Please refer to: https://www.techonthenet.com/sqlite/unique.php
|
|
15141
|
+
|
|
15142
|
+
Due to that we don't generate migration automatically and it has to be done manually
|
|
15143
|
+
*/`;
|
|
15144
|
+
}
|
|
15145
|
+
};
|
|
15146
|
+
SQLiteAlterTableDropUniqueConstraintConvertor = class extends Convertor {
|
|
15147
|
+
can(statement, dialect6) {
|
|
15148
|
+
return statement.type === "delete_unique_constraint" && dialect6 === "sqlite";
|
|
15149
|
+
}
|
|
15150
|
+
convert(statement) {
|
|
15151
|
+
return `/*
|
|
15152
|
+
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
|
|
15153
|
+
Please refer to: https://www.techonthenet.com/sqlite/unique.php
|
|
15154
|
+
|
|
15155
|
+
Due to that we don't generate migration automatically and it has to be done manually
|
|
15156
|
+
*/`;
|
|
15157
|
+
}
|
|
15158
|
+
};
|
|
14857
15159
|
CreateTypeEnumConvertor = class extends Convertor {
|
|
14858
15160
|
can(statement) {
|
|
14859
15161
|
return statement.type === "create_type_enum";
|
|
@@ -15847,6 +16149,8 @@ ${BREAKPOINT}ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT ${statement.newCo
|
|
|
15847
16149
|
convertors.push(new SqliteAlterForeignKeyConvertor());
|
|
15848
16150
|
convertors.push(new SqliteDeleteForeignKeyConvertor());
|
|
15849
16151
|
convertors.push(new SqliteCreateForeignKeyConvertor());
|
|
16152
|
+
convertors.push(new SQLiteAlterTableAddUniqueConstraintConvertor());
|
|
16153
|
+
convertors.push(new SQLiteAlterTableDropUniqueConstraintConvertor());
|
|
15850
16154
|
convertors.push(new SqliteAlterTableAlterColumnSetNotNullConvertor());
|
|
15851
16155
|
convertors.push(new SqliteAlterTableAlterColumnDropNotNullConvertor());
|
|
15852
16156
|
convertors.push(new SqliteAlterTableAlterColumnSetDefaultConvertor());
|
|
@@ -15940,7 +16244,7 @@ var init_jsonStatements = __esm({
|
|
|
15940
16244
|
};
|
|
15941
16245
|
};
|
|
15942
16246
|
prepareSQLiteCreateTable = (table4) => {
|
|
15943
|
-
const { name, columns } = table4;
|
|
16247
|
+
const { name, columns, uniqueConstraints } = table4;
|
|
15944
16248
|
const references2 = Object.values(table4.foreignKeys);
|
|
15945
16249
|
const composites = Object.values(table4.compositePrimaryKeys).map(
|
|
15946
16250
|
(it) => SQLiteSquasher.unsquashPK(it)
|
|
@@ -15950,7 +16254,8 @@ var init_jsonStatements = __esm({
|
|
|
15950
16254
|
tableName: name,
|
|
15951
16255
|
columns: Object.values(columns),
|
|
15952
16256
|
referenceData: references2,
|
|
15953
|
-
compositePKs: composites
|
|
16257
|
+
compositePKs: composites,
|
|
16258
|
+
uniqueConstraints: Object.values(uniqueConstraints)
|
|
15954
16259
|
};
|
|
15955
16260
|
};
|
|
15956
16261
|
prepareDropTableJson = (table4) => {
|
|
@@ -18271,70 +18576,6 @@ var init_sqliteUtils = __esm({
|
|
|
18271
18576
|
}
|
|
18272
18577
|
});
|
|
18273
18578
|
|
|
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
18579
|
// src/cli/validations/common.ts
|
|
18339
18580
|
var checkCollisions;
|
|
18340
18581
|
var init_common = __esm({
|
|
@@ -35363,7 +35604,7 @@ var require_promise = __commonJS({
|
|
|
35363
35604
|
});
|
|
35364
35605
|
|
|
35365
35606
|
// src/mysql-introspect.ts
|
|
35366
|
-
var mysqlImportsList, objToStatement2, timeConfig, binaryConfig, importsPatch, relations, withCasing, schemaToTypeScript, isCyclic, isSelf, mapColumnDefault, mapColumnDefaultForJson, column4, createTableColumns, createTableIndexes, createTablePKs, createTableFKs;
|
|
35607
|
+
var mysqlImportsList, objToStatement2, timeConfig, binaryConfig, importsPatch, relations, withCasing, schemaToTypeScript, isCyclic, isSelf, mapColumnDefault, mapColumnDefaultForJson, column4, createTableColumns, createTableIndexes, createTableUniques, createTablePKs, createTableFKs;
|
|
35367
35608
|
var init_mysql_introspect = __esm({
|
|
35368
35609
|
"src/mysql-introspect.ts"() {
|
|
35369
35610
|
init_utils3();
|
|
@@ -35463,9 +35704,13 @@ var init_mysql_introspect = __esm({
|
|
|
35463
35704
|
const pkImports = Object.values(it.compositePrimaryKeys).map(
|
|
35464
35705
|
(it2) => "primaryKey"
|
|
35465
35706
|
);
|
|
35707
|
+
const uniqueImports = Object.values(it.uniqueConstraints).map(
|
|
35708
|
+
(it2) => "unique"
|
|
35709
|
+
);
|
|
35466
35710
|
res.mysql.push(...idxImports);
|
|
35467
35711
|
res.mysql.push(...fkImpots);
|
|
35468
35712
|
res.mysql.push(...pkImports);
|
|
35713
|
+
res.mysql.push(...uniqueImports);
|
|
35469
35714
|
const columnImports = Object.values(it.columns).map((col) => {
|
|
35470
35715
|
let patched = importsPatch[col.type] ?? col.type;
|
|
35471
35716
|
patched = patched.startsWith("varchar(") ? "varchar" : patched;
|
|
@@ -35512,7 +35757,7 @@ var init_mysql_introspect = __esm({
|
|
|
35512
35757
|
const filteredFKs = Object.values(table4.foreignKeys).filter((it) => {
|
|
35513
35758
|
return it.columnsFrom.length > 1 || isSelf(it);
|
|
35514
35759
|
});
|
|
35515
|
-
if (Object.keys(table4.indexes).length > 0 || filteredFKs.length > 0 || Object.keys(table4.compositePrimaryKeys).length > 0) {
|
|
35760
|
+
if (Object.keys(table4.indexes).length > 0 || filteredFKs.length > 0 || Object.keys(table4.compositePrimaryKeys).length > 0 || Object.keys(table4.uniqueConstraints).length > 0) {
|
|
35516
35761
|
statement += ",\n";
|
|
35517
35762
|
statement += "(table) => {\n";
|
|
35518
35763
|
statement += " return {\n";
|
|
@@ -35526,6 +35771,10 @@ var init_mysql_introspect = __esm({
|
|
|
35526
35771
|
Object.values(table4.compositePrimaryKeys),
|
|
35527
35772
|
casing
|
|
35528
35773
|
);
|
|
35774
|
+
statement += createTableUniques(
|
|
35775
|
+
Object.values(table4.uniqueConstraints),
|
|
35776
|
+
casing
|
|
35777
|
+
);
|
|
35529
35778
|
statement += " }\n";
|
|
35530
35779
|
statement += "}";
|
|
35531
35780
|
}
|
|
@@ -35836,6 +36085,19 @@ import { sql } from "drizzle-orm"
|
|
|
35836
36085
|
statement += `${escapedIndexName})`;
|
|
35837
36086
|
statement += `.on(${it.columns.map((it2) => `table.${withCasing(it2, casing)}`).join(", ")}),`;
|
|
35838
36087
|
statement += `
|
|
36088
|
+
`;
|
|
36089
|
+
});
|
|
36090
|
+
return statement;
|
|
36091
|
+
};
|
|
36092
|
+
createTableUniques = (unqs, casing) => {
|
|
36093
|
+
let statement = "";
|
|
36094
|
+
unqs.forEach((it) => {
|
|
36095
|
+
const idxKey = withCasing(it.name, casing);
|
|
36096
|
+
statement += ` ${idxKey}: `;
|
|
36097
|
+
statement += "unique(";
|
|
36098
|
+
statement += `"${it.name}")`;
|
|
36099
|
+
statement += `.on(${it.columns.map((it2) => `table.${withCasing(it2, casing)}`).join(", ")}),`;
|
|
36100
|
+
statement += `
|
|
35839
36101
|
`;
|
|
35840
36102
|
});
|
|
35841
36103
|
return statement;
|
|
@@ -37164,10 +37426,10 @@ __export(mysqlIntrospect_exports, {
|
|
|
37164
37426
|
mysqlIntrospect: () => mysqlIntrospect,
|
|
37165
37427
|
mysqlPushIntrospect: () => mysqlPushIntrospect
|
|
37166
37428
|
});
|
|
37167
|
-
var
|
|
37429
|
+
var import_hanji6, import_promise, connectToMySQL, mysqlIntrospect, mysqlPushIntrospect;
|
|
37168
37430
|
var init_mysqlIntrospect = __esm({
|
|
37169
37431
|
"src/cli/commands/mysqlIntrospect.ts"() {
|
|
37170
|
-
|
|
37432
|
+
import_hanji6 = __toESM(require_hanji());
|
|
37171
37433
|
init_views();
|
|
37172
37434
|
import_promise = __toESM(require_promise());
|
|
37173
37435
|
init_mysqlSerializer();
|
|
@@ -37216,7 +37478,7 @@ var init_mysqlIntrospect = __esm({
|
|
|
37216
37478
|
return false;
|
|
37217
37479
|
};
|
|
37218
37480
|
const progress = new IntrospectProgress();
|
|
37219
|
-
const res = await (0,
|
|
37481
|
+
const res = await (0, import_hanji6.renderWithTask)(
|
|
37220
37482
|
progress,
|
|
37221
37483
|
fromDatabase(
|
|
37222
37484
|
client,
|
|
@@ -37254,7 +37516,7 @@ var init_mysqlIntrospect = __esm({
|
|
|
37254
37516
|
});
|
|
37255
37517
|
|
|
37256
37518
|
// src/sqlite-introspect.ts
|
|
37257
|
-
var sqliteImportsList, indexName3, objToStatement22, relations2, withCasing2, schemaToTypeScript2, isCyclic2, isSelf2, mapColumnDefault2, column5, createTableColumns2, createTableIndexes2, createTablePKs2, createTableFKs2;
|
|
37519
|
+
var sqliteImportsList, indexName3, objToStatement22, relations2, withCasing2, schemaToTypeScript2, isCyclic2, isSelf2, mapColumnDefault2, column5, createTableColumns2, createTableIndexes2, createTableUniques2, createTablePKs2, createTableFKs2;
|
|
37258
37520
|
var init_sqlite_introspect = __esm({
|
|
37259
37521
|
"src/sqlite-introspect.ts"() {
|
|
37260
37522
|
init_utils3();
|
|
@@ -37305,9 +37567,13 @@ var init_sqlite_introspect = __esm({
|
|
|
37305
37567
|
const pkImports = Object.values(it.compositePrimaryKeys).map(
|
|
37306
37568
|
(it2) => "primaryKey"
|
|
37307
37569
|
);
|
|
37570
|
+
const uniqueImports = Object.values(it.uniqueConstraints).map(
|
|
37571
|
+
(it2) => "unique"
|
|
37572
|
+
);
|
|
37308
37573
|
res.sqlite.push(...idxImports);
|
|
37309
37574
|
res.sqlite.push(...fkImpots);
|
|
37310
37575
|
res.sqlite.push(...pkImports);
|
|
37576
|
+
res.sqlite.push(...uniqueImports);
|
|
37311
37577
|
const columnImports = Object.values(it.columns).map((col) => {
|
|
37312
37578
|
return col.type;
|
|
37313
37579
|
}).filter((type) => {
|
|
@@ -37340,7 +37606,7 @@ var init_sqlite_introspect = __esm({
|
|
|
37340
37606
|
const filteredFKs = Object.values(table4.foreignKeys).filter((it) => {
|
|
37341
37607
|
return it.columnsFrom.length > 1 || isSelf2(it);
|
|
37342
37608
|
});
|
|
37343
|
-
if (Object.keys(table4.indexes).length > 0 || filteredFKs.length > 0 || Object.keys(table4.compositePrimaryKeys).length > 0) {
|
|
37609
|
+
if (Object.keys(table4.indexes).length > 0 || filteredFKs.length > 0 || Object.keys(table4.compositePrimaryKeys).length > 0 || Object.keys(table4.uniqueConstraints).length > 0) {
|
|
37344
37610
|
statement += ",\n";
|
|
37345
37611
|
statement += "(table) => {\n";
|
|
37346
37612
|
statement += " return {\n";
|
|
@@ -37354,6 +37620,10 @@ var init_sqlite_introspect = __esm({
|
|
|
37354
37620
|
Object.values(table4.compositePrimaryKeys),
|
|
37355
37621
|
casing
|
|
37356
37622
|
);
|
|
37623
|
+
statement += createTableUniques2(
|
|
37624
|
+
Object.values(table4.uniqueConstraints),
|
|
37625
|
+
casing
|
|
37626
|
+
);
|
|
37357
37627
|
statement += " }\n";
|
|
37358
37628
|
statement += "}";
|
|
37359
37629
|
}
|
|
@@ -37473,6 +37743,19 @@ import { sql } from "drizzle-orm"
|
|
|
37473
37743
|
statement += `${escapedIndexName})`;
|
|
37474
37744
|
statement += `.on(${it.columns.map((it2) => `table.${withCasing2(it2, casing)}`).join(", ")}),`;
|
|
37475
37745
|
statement += `
|
|
37746
|
+
`;
|
|
37747
|
+
});
|
|
37748
|
+
return statement;
|
|
37749
|
+
};
|
|
37750
|
+
createTableUniques2 = (unqs, casing) => {
|
|
37751
|
+
let statement = "";
|
|
37752
|
+
unqs.forEach((it) => {
|
|
37753
|
+
const idxKey = withCasing2(it.name, casing);
|
|
37754
|
+
statement += ` ${idxKey}: `;
|
|
37755
|
+
statement += "unique(";
|
|
37756
|
+
statement += `"${it.name}")`;
|
|
37757
|
+
statement += `.on(${it.columns.map((it2) => `table.${withCasing2(it2, casing)}`).join(", ")}),`;
|
|
37758
|
+
statement += `
|
|
37476
37759
|
`;
|
|
37477
37760
|
});
|
|
37478
37761
|
return statement;
|
|
@@ -46062,7 +46345,7 @@ __export(sqliteIntrospect_exports, {
|
|
|
46062
46345
|
sqliteIntrospect: () => sqliteIntrospect,
|
|
46063
46346
|
sqlitePushIntrospect: () => sqlitePushIntrospect
|
|
46064
46347
|
});
|
|
46065
|
-
var
|
|
46348
|
+
var import_hanji7, SqliteClient, BetterSqlite, TursoSqlite, connectToSQLite, sqliteIntrospect, sqlitePushIntrospect;
|
|
46066
46349
|
var init_sqliteIntrospect = __esm({
|
|
46067
46350
|
"src/cli/commands/sqliteIntrospect.ts"() {
|
|
46068
46351
|
init_views();
|
|
@@ -46071,7 +46354,7 @@ var init_sqliteIntrospect = __esm({
|
|
|
46071
46354
|
init_sqlite_introspect();
|
|
46072
46355
|
init_mjs();
|
|
46073
46356
|
init_lib_esm2();
|
|
46074
|
-
|
|
46357
|
+
import_hanji7 = __toESM(require_hanji());
|
|
46075
46358
|
SqliteClient = class {
|
|
46076
46359
|
constructor(db) {
|
|
46077
46360
|
this.db = db;
|
|
@@ -46137,7 +46420,7 @@ var init_sqliteIntrospect = __esm({
|
|
|
46137
46420
|
return false;
|
|
46138
46421
|
};
|
|
46139
46422
|
const progress = new IntrospectProgress();
|
|
46140
|
-
const res = await (0,
|
|
46423
|
+
const res = await (0, import_hanji7.renderWithTask)(
|
|
46141
46424
|
progress,
|
|
46142
46425
|
fromDatabase3(
|
|
46143
46426
|
client,
|
|
@@ -50711,7 +50994,7 @@ var require_lib5 = __commonJS({
|
|
|
50711
50994
|
});
|
|
50712
50995
|
|
|
50713
50996
|
// src/introspect.ts
|
|
50714
|
-
var pgImportsList, objToStatement23, timeConfig2, possibleIntervals, intervalStrToObj, intervalConfig, importsPatch2, relations3, withCasing3, schemaToTypeScript3, isCyclic3, isSelf3, column6, dimensionsInArray, createTableColumns3, createTableIndexes3, createTablePKs3, createTableFKs3;
|
|
50997
|
+
var pgImportsList, objToStatement23, timeConfig2, possibleIntervals, intervalStrToObj, intervalConfig, importsPatch2, relations3, withCasing3, schemaToTypeScript3, isCyclic3, isSelf3, column6, dimensionsInArray, createTableColumns3, createTableIndexes3, createTablePKs3, createTableUniques3, createTableFKs3;
|
|
50715
50998
|
var init_introspect = __esm({
|
|
50716
50999
|
"src/introspect.ts"() {
|
|
50717
51000
|
init_utils3();
|
|
@@ -50854,9 +51137,13 @@ var init_introspect = __esm({
|
|
|
50854
51137
|
const pkImports = Object.values(it.compositePrimaryKeys).map(
|
|
50855
51138
|
(it2) => "primaryKey"
|
|
50856
51139
|
);
|
|
51140
|
+
const uniqueImports = Object.values(it.uniqueConstraints).map(
|
|
51141
|
+
(it2) => "unique"
|
|
51142
|
+
);
|
|
50857
51143
|
res.pg.push(...idxImports);
|
|
50858
51144
|
res.pg.push(...fkImpots);
|
|
50859
51145
|
res.pg.push(...pkImports);
|
|
51146
|
+
res.pg.push(...uniqueImports);
|
|
50860
51147
|
const columnImports = Object.values(it.columns).map((col) => {
|
|
50861
51148
|
let patched = importsPatch2[col.type] ?? col.type;
|
|
50862
51149
|
patched = patched.startsWith("varchar(") ? "varchar" : patched;
|
|
@@ -50900,7 +51187,7 @@ var init_introspect = __esm({
|
|
|
50900
51187
|
const filteredFKs = Object.values(table4.foreignKeys).filter((it) => {
|
|
50901
51188
|
return it.columnsFrom.length > 1 || isSelf3(it);
|
|
50902
51189
|
});
|
|
50903
|
-
if (Object.keys(table4.indexes).length > 0 || filteredFKs.length > 0 || Object.keys(table4.compositePrimaryKeys).length > 0) {
|
|
51190
|
+
if (Object.keys(table4.indexes).length > 0 || filteredFKs.length > 0 || Object.keys(table4.compositePrimaryKeys).length > 0 || Object.keys(table4.uniqueConstraints).length > 0) {
|
|
50904
51191
|
statement += ",\n";
|
|
50905
51192
|
statement += "(table) => {\n";
|
|
50906
51193
|
statement += " return {\n";
|
|
@@ -50914,6 +51201,10 @@ var init_introspect = __esm({
|
|
|
50914
51201
|
Object.values(table4.compositePrimaryKeys),
|
|
50915
51202
|
casing
|
|
50916
51203
|
);
|
|
51204
|
+
statement += createTableUniques3(
|
|
51205
|
+
Object.values(table4.uniqueConstraints),
|
|
51206
|
+
casing
|
|
51207
|
+
);
|
|
50917
51208
|
statement += " }\n";
|
|
50918
51209
|
statement += "}";
|
|
50919
51210
|
}
|
|
@@ -51156,7 +51447,13 @@ var init_introspect = __esm({
|
|
|
51156
51447
|
return res;
|
|
51157
51448
|
}, {});
|
|
51158
51449
|
columns.forEach((it) => {
|
|
51159
|
-
const columnStatement = column6(
|
|
51450
|
+
const columnStatement = column6(
|
|
51451
|
+
it.type,
|
|
51452
|
+
it.name,
|
|
51453
|
+
enumTypes,
|
|
51454
|
+
it.default,
|
|
51455
|
+
casing
|
|
51456
|
+
);
|
|
51160
51457
|
statement += " ";
|
|
51161
51458
|
statement += columnStatement;
|
|
51162
51459
|
statement += dimensionsInArray(it.type);
|
|
@@ -51215,6 +51512,20 @@ var init_introspect = __esm({
|
|
|
51215
51512
|
}).join(", ")}`;
|
|
51216
51513
|
statement += ")";
|
|
51217
51514
|
statement += `
|
|
51515
|
+
`;
|
|
51516
|
+
});
|
|
51517
|
+
return statement;
|
|
51518
|
+
};
|
|
51519
|
+
createTableUniques3 = (unqs, casing) => {
|
|
51520
|
+
let statement = "";
|
|
51521
|
+
unqs.forEach((it) => {
|
|
51522
|
+
const idxKey = withCasing3(it.name, casing);
|
|
51523
|
+
statement += ` ${idxKey}: `;
|
|
51524
|
+
statement += "unique(";
|
|
51525
|
+
statement += `"${it.name}")`;
|
|
51526
|
+
statement += `.on(${it.columns.map((it2) => `table.${withCasing3(it2, casing)}`).join(", ")})`;
|
|
51527
|
+
statement += it.nullsNotDistinct ? `.nullsNotDistinct()` : "";
|
|
51528
|
+
statement += `,
|
|
51218
51529
|
`;
|
|
51219
51530
|
});
|
|
51220
51531
|
return statement;
|
|
@@ -51246,10 +51557,10 @@ var pgIntrospect_exports = {};
|
|
|
51246
51557
|
__export(pgIntrospect_exports, {
|
|
51247
51558
|
pgIntrospect: () => pgIntrospect
|
|
51248
51559
|
});
|
|
51249
|
-
var
|
|
51560
|
+
var import_hanji8, import_pg, pgIntrospect;
|
|
51250
51561
|
var init_pgIntrospect = __esm({
|
|
51251
51562
|
"src/cli/commands/pgIntrospect.ts"() {
|
|
51252
|
-
|
|
51563
|
+
import_hanji8 = __toESM(require_hanji());
|
|
51253
51564
|
init_views();
|
|
51254
51565
|
import_pg = __toESM(require_lib5());
|
|
51255
51566
|
init_pgSerializer();
|
|
@@ -51272,7 +51583,7 @@ var init_pgIntrospect = __esm({
|
|
|
51272
51583
|
return false;
|
|
51273
51584
|
};
|
|
51274
51585
|
const progress = new IntrospectProgress();
|
|
51275
|
-
const res = await (0,
|
|
51586
|
+
const res = await (0, import_hanji8.renderWithTask)(
|
|
51276
51587
|
progress,
|
|
51277
51588
|
fromDatabase2(pool, filter2, (stage, count, status) => {
|
|
51278
51589
|
progress.update(stage, count, status);
|
|
@@ -51492,7 +51803,7 @@ var checkHandler = (out, dialect6) => {
|
|
|
51492
51803
|
};
|
|
51493
51804
|
|
|
51494
51805
|
// src/cli/index.ts
|
|
51495
|
-
var
|
|
51806
|
+
var import_hanji9 = __toESM(require_hanji());
|
|
51496
51807
|
var import_path7 = __toESM(require("path"));
|
|
51497
51808
|
|
|
51498
51809
|
// src/cli/utils.ts
|
|
@@ -51626,7 +51937,7 @@ var package_default = {
|
|
|
51626
51937
|
"better-sqlite3": "^8.4.0",
|
|
51627
51938
|
dockerode: "^3.3.4",
|
|
51628
51939
|
dotenv: "^16.0.3",
|
|
51629
|
-
"drizzle-orm": "0.27.
|
|
51940
|
+
"drizzle-orm": "0.27.1-8a21e7b",
|
|
51630
51941
|
eslint: "^8.29.0",
|
|
51631
51942
|
"eslint-config-prettier": "^8.5.0",
|
|
51632
51943
|
"eslint-plugin-prettier": "^4.2.1",
|
|
@@ -51734,6 +52045,8 @@ init_utils();
|
|
|
51734
52045
|
|
|
51735
52046
|
// src/cli/commands/mysqlPushUtils.ts
|
|
51736
52047
|
init_source();
|
|
52048
|
+
var import_hanji5 = __toESM(require_hanji());
|
|
52049
|
+
init_mysqlSchema();
|
|
51737
52050
|
var filterStatements = (statements) => {
|
|
51738
52051
|
return statements.filter((statement) => {
|
|
51739
52052
|
if (statement.type === "alter_table_alter_column_set_type") {
|
|
@@ -51888,6 +52201,33 @@ var logSuggestionsAndReturn = async ({
|
|
|
51888
52201
|
shouldAskForApprove = true;
|
|
51889
52202
|
}
|
|
51890
52203
|
}
|
|
52204
|
+
} else if (statement.type === "create_unique_constraint") {
|
|
52205
|
+
const res = await connection.query(
|
|
52206
|
+
`select count(*) as count from \`${statement.tableName}\``
|
|
52207
|
+
);
|
|
52208
|
+
const count = Number(res[0][0].count);
|
|
52209
|
+
if (count > 0) {
|
|
52210
|
+
const unsquashedUnique = MySqlSquasher.unsquashUnique(statement.data);
|
|
52211
|
+
console.log(
|
|
52212
|
+
`\xB7 You're about to add ${source_default.underline(
|
|
52213
|
+
unsquashedUnique.name
|
|
52214
|
+
)} 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(
|
|
52215
|
+
statement.tableName
|
|
52216
|
+
)} table?
|
|
52217
|
+
`
|
|
52218
|
+
);
|
|
52219
|
+
const { status, data } = await (0, import_hanji5.render)(
|
|
52220
|
+
new Select([
|
|
52221
|
+
"No, add the constraint without truncating the table",
|
|
52222
|
+
`Yes, truncate the table`
|
|
52223
|
+
])
|
|
52224
|
+
);
|
|
52225
|
+
if ((data == null ? void 0 : data.index) === 1) {
|
|
52226
|
+
tablesToTruncate.push(statement.tableName);
|
|
52227
|
+
statementsToExecute.push(`truncate table ${statement.tableName};`);
|
|
52228
|
+
shouldAskForApprove = true;
|
|
52229
|
+
}
|
|
52230
|
+
}
|
|
51891
52231
|
}
|
|
51892
52232
|
}
|
|
51893
52233
|
return {
|
|
@@ -52124,7 +52464,7 @@ var logSuggestionsAndReturn2 = async ({
|
|
|
52124
52464
|
if (typeof tablesContext[fk4.tableFrom] === "undefined") {
|
|
52125
52465
|
tablesContext[fk4.tableFrom] = _moveDataStatements(fk4.tableFrom, json2);
|
|
52126
52466
|
}
|
|
52127
|
-
} else if (statement.type === "create_composite_pk" || statement.type === "alter_composite_pk" || statement.type === "delete_composite_pk") {
|
|
52467
|
+
} 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
52468
|
if (typeof tablesContext[statement.tableName] === "undefined") {
|
|
52129
52469
|
tablesContext[statement.tableName] = _moveDataStatements(
|
|
52130
52470
|
statement.tableName,
|
|
@@ -52222,14 +52562,14 @@ var generateMysqlCommand = new import_commander.Command("generate:mysql").option
|
|
|
52222
52562
|
const { prepareAndMigrateMySql: prepareAndMigrateMySql2 } = await Promise.resolve().then(() => (init_migrate(), migrate_exports));
|
|
52223
52563
|
await prepareAndMigrateMySql2(result);
|
|
52224
52564
|
});
|
|
52225
|
-
var Select = class extends
|
|
52565
|
+
var Select = class extends import_hanji9.Prompt {
|
|
52226
52566
|
// private readonly spinner: () => string;
|
|
52227
52567
|
// private timeout: NodeJS.Timer | undefined;
|
|
52228
52568
|
constructor(items) {
|
|
52229
52569
|
super();
|
|
52230
52570
|
this.on("attach", (terminal) => terminal.toggleCursor("hide"));
|
|
52231
52571
|
this.on("detach", (terminal) => terminal.toggleCursor("show"));
|
|
52232
|
-
this.data = new
|
|
52572
|
+
this.data = new import_hanji9.SelectState(
|
|
52233
52573
|
items.map((it) => ({ label: it, value: `${it}-value` }))
|
|
52234
52574
|
);
|
|
52235
52575
|
this.data.bind(this);
|
|
@@ -52264,7 +52604,7 @@ var dbPushMysqlCommand = new import_commander.Command("push:mysql").option(
|
|
|
52264
52604
|
);
|
|
52265
52605
|
const fileNames = prepareFilenames(drizzleConfig.schema);
|
|
52266
52606
|
if (fileNames.length === 0) {
|
|
52267
|
-
(0,
|
|
52607
|
+
(0, import_hanji9.render)(
|
|
52268
52608
|
`[${source_default.blue("i")}] No schema file in ${drizzleConfig.schema} was found`
|
|
52269
52609
|
);
|
|
52270
52610
|
process.exit(0);
|
|
@@ -52281,7 +52621,7 @@ var dbPushMysqlCommand = new import_commander.Command("push:mysql").option(
|
|
|
52281
52621
|
try {
|
|
52282
52622
|
if (typeof statements === "undefined") {
|
|
52283
52623
|
} else if (statements.sqlStatements.length === 0) {
|
|
52284
|
-
(0,
|
|
52624
|
+
(0, import_hanji9.render)(`[${source_default.blue("i")}] No changes detected`);
|
|
52285
52625
|
} else {
|
|
52286
52626
|
const filteredStatements = filterStatements(statements.statements);
|
|
52287
52627
|
const {
|
|
@@ -52309,11 +52649,11 @@ var dbPushMysqlCommand = new import_commander.Command("push:mysql").option(
|
|
|
52309
52649
|
}
|
|
52310
52650
|
if (drizzleConfig.strict) {
|
|
52311
52651
|
if (!shouldAskForApprove) {
|
|
52312
|
-
const { status, data } = await (0,
|
|
52652
|
+
const { status, data } = await (0, import_hanji9.render)(
|
|
52313
52653
|
new Select(["No, abort", `Yes, I want to execute all statements`])
|
|
52314
52654
|
);
|
|
52315
52655
|
if ((data == null ? void 0 : data.index) === 0) {
|
|
52316
|
-
(0,
|
|
52656
|
+
(0, import_hanji9.render)(`[${source_default.red("x")}] All changes were aborted`);
|
|
52317
52657
|
process.exit(0);
|
|
52318
52658
|
}
|
|
52319
52659
|
}
|
|
@@ -52328,14 +52668,14 @@ var dbPushMysqlCommand = new import_commander.Command("push:mysql").option(
|
|
|
52328
52668
|
)
|
|
52329
52669
|
);
|
|
52330
52670
|
console.log(source_default.white("Do you still want to push changes?"));
|
|
52331
|
-
const { status, data } = await (0,
|
|
52671
|
+
const { status, data } = await (0, import_hanji9.render)(
|
|
52332
52672
|
new Select([
|
|
52333
52673
|
"No, abort",
|
|
52334
52674
|
`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
52675
|
])
|
|
52336
52676
|
);
|
|
52337
52677
|
if ((data == null ? void 0 : data.index) === 0) {
|
|
52338
|
-
(0,
|
|
52678
|
+
(0, import_hanji9.render)(`[${source_default.red("x")}] All changes were aborted`);
|
|
52339
52679
|
process.exit(0);
|
|
52340
52680
|
}
|
|
52341
52681
|
}
|
|
@@ -52346,9 +52686,9 @@ var dbPushMysqlCommand = new import_commander.Command("push:mysql").option(
|
|
|
52346
52686
|
await connection.client.query(statement);
|
|
52347
52687
|
}
|
|
52348
52688
|
if (filteredStatements.length > 0) {
|
|
52349
|
-
(0,
|
|
52689
|
+
(0, import_hanji9.render)(`[${source_default.green("\u2713")}] Changes applied`);
|
|
52350
52690
|
} else {
|
|
52351
|
-
(0,
|
|
52691
|
+
(0, import_hanji9.render)(`[${source_default.blue("i")}] No changes detected`);
|
|
52352
52692
|
}
|
|
52353
52693
|
}
|
|
52354
52694
|
} catch (e) {
|
|
@@ -52368,7 +52708,7 @@ var dbPushSqliteCommand = new import_commander.Command("push:sqlite").option(
|
|
|
52368
52708
|
const res = await validatePush(options);
|
|
52369
52709
|
const fileNames = prepareFilenames(res.schema);
|
|
52370
52710
|
if (fileNames.length === 0) {
|
|
52371
|
-
(0,
|
|
52711
|
+
(0, import_hanji9.render)(`[${source_default.blue("i")}] No schema file in ${res.schema} was found`);
|
|
52372
52712
|
process.exit(0);
|
|
52373
52713
|
}
|
|
52374
52714
|
const connection = await connectToSQLite2(res);
|
|
@@ -52383,7 +52723,7 @@ var dbPushSqliteCommand = new import_commander.Command("push:sqlite").option(
|
|
|
52383
52723
|
try {
|
|
52384
52724
|
if (typeof statements === "undefined") {
|
|
52385
52725
|
} else if (statements.sqlStatements.length === 0) {
|
|
52386
|
-
(0,
|
|
52726
|
+
(0, import_hanji9.render)(`
|
|
52387
52727
|
[${source_default.blue("i")}] No changes detected`);
|
|
52388
52728
|
} else {
|
|
52389
52729
|
const {
|
|
@@ -52411,11 +52751,11 @@ var dbPushSqliteCommand = new import_commander.Command("push:sqlite").option(
|
|
|
52411
52751
|
}
|
|
52412
52752
|
if (res.strict) {
|
|
52413
52753
|
if (!shouldAskForApprove) {
|
|
52414
|
-
const { status, data } = await (0,
|
|
52754
|
+
const { status, data } = await (0, import_hanji9.render)(
|
|
52415
52755
|
new Select(["No, abort", `Yes, I want to execute all statements`])
|
|
52416
52756
|
);
|
|
52417
52757
|
if ((data == null ? void 0 : data.index) === 0) {
|
|
52418
|
-
(0,
|
|
52758
|
+
(0, import_hanji9.render)(`[${source_default.red("x")}] All changes were aborted`);
|
|
52419
52759
|
process.exit(0);
|
|
52420
52760
|
}
|
|
52421
52761
|
}
|
|
@@ -52430,21 +52770,21 @@ var dbPushSqliteCommand = new import_commander.Command("push:sqlite").option(
|
|
|
52430
52770
|
)
|
|
52431
52771
|
);
|
|
52432
52772
|
console.log(source_default.white("Do you still want to push changes?"));
|
|
52433
|
-
const { status, data } = await (0,
|
|
52773
|
+
const { status, data } = await (0, import_hanji9.render)(
|
|
52434
52774
|
new Select([
|
|
52435
52775
|
"No, abort",
|
|
52436
52776
|
`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
52777
|
])
|
|
52438
52778
|
);
|
|
52439
52779
|
if ((data == null ? void 0 : data.index) === 0) {
|
|
52440
|
-
(0,
|
|
52780
|
+
(0, import_hanji9.render)(`[${source_default.red("x")}] All changes were aborted`);
|
|
52441
52781
|
process.exit(0);
|
|
52442
52782
|
}
|
|
52443
52783
|
}
|
|
52444
52784
|
for (const dStmnt of statementsToExecute) {
|
|
52445
52785
|
await connection.client.run(dStmnt);
|
|
52446
52786
|
}
|
|
52447
|
-
(0,
|
|
52787
|
+
(0, import_hanji9.render)(`[${source_default.green("\u2713")}] Changes applied`);
|
|
52448
52788
|
}
|
|
52449
52789
|
} catch (e) {
|
|
52450
52790
|
console.log(e);
|
|
@@ -52613,13 +52953,13 @@ var introspectPgCommand = new import_commander.Command("introspect:pg").option("
|
|
|
52613
52953
|
"introspect"
|
|
52614
52954
|
);
|
|
52615
52955
|
} else {
|
|
52616
|
-
(0,
|
|
52956
|
+
(0, import_hanji9.render)(
|
|
52617
52957
|
`[${source_default.blue(
|
|
52618
52958
|
"i"
|
|
52619
52959
|
)}] No SQL generated, you already have migrations in project`
|
|
52620
52960
|
);
|
|
52621
52961
|
}
|
|
52622
|
-
(0,
|
|
52962
|
+
(0, import_hanji9.render)(
|
|
52623
52963
|
`[${source_default.green(
|
|
52624
52964
|
"\u2713"
|
|
52625
52965
|
)}] You schema file is ready \u279C ${source_default.bold.underline.blue(
|
|
@@ -52666,13 +53006,13 @@ var introspectMySqlCommand = new import_commander.Command("introspect:mysql").op
|
|
|
52666
53006
|
"introspect"
|
|
52667
53007
|
);
|
|
52668
53008
|
} else {
|
|
52669
|
-
(0,
|
|
53009
|
+
(0, import_hanji9.render)(
|
|
52670
53010
|
`[${source_default.blue(
|
|
52671
53011
|
"i"
|
|
52672
53012
|
)}] No SQL generated, you already have migrations in project`
|
|
52673
53013
|
);
|
|
52674
53014
|
}
|
|
52675
|
-
(0,
|
|
53015
|
+
(0, import_hanji9.render)(
|
|
52676
53016
|
`[${source_default.green(
|
|
52677
53017
|
"\u2713"
|
|
52678
53018
|
)}] You schema file is ready \u279C ${source_default.bold.underline.blue(
|
|
@@ -52719,13 +53059,13 @@ var introspectSQLiteCommand = new import_commander.Command("introspect:sqlite").
|
|
|
52719
53059
|
"introspect"
|
|
52720
53060
|
);
|
|
52721
53061
|
} else {
|
|
52722
|
-
(0,
|
|
53062
|
+
(0, import_hanji9.render)(
|
|
52723
53063
|
`[${source_default.blue(
|
|
52724
53064
|
"i"
|
|
52725
53065
|
)}] No SQL generated, you already have migrations in project`
|
|
52726
53066
|
);
|
|
52727
53067
|
}
|
|
52728
|
-
(0,
|
|
53068
|
+
(0, import_hanji9.render)(
|
|
52729
53069
|
`[${source_default.green(
|
|
52730
53070
|
"\u2713"
|
|
52731
53071
|
)}] You schema file is ready \u279C ${source_default.bold.underline.blue(
|