drizzle-kit 0.19.3 → 0.19.4-280a402
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 +745 -181
- package/package.json +2 -2
- package/utils.js +282 -44
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);
|
|
@@ -4551,7 +4551,7 @@ var init_global = __esm({
|
|
|
4551
4551
|
});
|
|
4552
4552
|
|
|
4553
4553
|
// src/serializer/mysqlSchema.ts
|
|
4554
|
-
var index, fk, column, tableV3, compositePK, tableV4, table, dialect, schemaHash, schemaInternalV3, schemaInternalV4, schemaInternal, schemaV3, schemaV4, schema2, tableSquashedV4, tableSquashed, schemaSquashed, schemaSquashedV4, MySqlSquasher, squashMysqlSchemeV4, squashMysqlScheme, mysqlSchema, mysqlSchemaV4, mysqlSchemaV3, backwardCompatibleMysqlSchema, dryMySql;
|
|
4554
|
+
var index, fk, column, tableV3, compositePK, uniqueConstraint, tableV4, table, dialect, schemaHash, schemaInternalV3, schemaInternalV4, schemaInternal, schemaV3, schemaV4, schema2, tableSquashedV4, tableSquashed, schemaSquashed, schemaSquashedV4, MySqlSquasher, squashMysqlSchemeV4, squashMysqlScheme, mysqlSchema, mysqlSchemaV4, mysqlSchemaV3, backwardCompatibleMysqlSchema, dryMySql;
|
|
4555
4555
|
var init_mysqlSchema = __esm({
|
|
4556
4556
|
"src/serializer/mysqlSchema.ts"() {
|
|
4557
4557
|
init_global();
|
|
@@ -4593,6 +4593,10 @@ var init_mysqlSchema = __esm({
|
|
|
4593
4593
|
name: stringType(),
|
|
4594
4594
|
columns: stringType().array()
|
|
4595
4595
|
}).strict();
|
|
4596
|
+
uniqueConstraint = objectType({
|
|
4597
|
+
name: stringType(),
|
|
4598
|
+
columns: stringType().array()
|
|
4599
|
+
}).strict();
|
|
4596
4600
|
tableV4 = objectType({
|
|
4597
4601
|
name: stringType(),
|
|
4598
4602
|
schema: stringType().optional(),
|
|
@@ -4606,7 +4610,8 @@ var init_mysqlSchema = __esm({
|
|
|
4606
4610
|
columns: recordType(stringType(), column),
|
|
4607
4611
|
indexes: recordType(stringType(), index),
|
|
4608
4612
|
foreignKeys: recordType(stringType(), fk),
|
|
4609
|
-
compositePrimaryKeys: recordType(stringType(), compositePK)
|
|
4613
|
+
compositePrimaryKeys: recordType(stringType(), compositePK),
|
|
4614
|
+
uniqueConstraints: recordType(stringType(), uniqueConstraint).default({})
|
|
4610
4615
|
}).strict();
|
|
4611
4616
|
dialect = literalType("mysql");
|
|
4612
4617
|
schemaHash = objectType({
|
|
@@ -4689,6 +4694,13 @@ var init_mysqlSchema = __esm({
|
|
|
4689
4694
|
const splitted = pk.split(";");
|
|
4690
4695
|
return { name: splitted[0], columns: splitted[1].split(",") };
|
|
4691
4696
|
},
|
|
4697
|
+
squashUnique: (unq) => {
|
|
4698
|
+
return `${unq.name};${unq.columns.join(",")}`;
|
|
4699
|
+
},
|
|
4700
|
+
unsquashUnique: (unq) => {
|
|
4701
|
+
const [name, columns] = unq.split(";");
|
|
4702
|
+
return { name, columns: columns.split(",") };
|
|
4703
|
+
},
|
|
4692
4704
|
squashFK: (fk4) => {
|
|
4693
4705
|
return `${fk4.name};${fk4.tableFrom};${fk4.columnsFrom.join(",")};${fk4.tableTo};${fk4.columnsTo.join(",")};${fk4.onUpdate ?? ""};${fk4.onDelete ?? ""}`;
|
|
4694
4706
|
},
|
|
@@ -4754,6 +4766,9 @@ var init_mysqlSchema = __esm({
|
|
|
4754
4766
|
const squashedPKs = mapValues(it[1].compositePrimaryKeys, (pk) => {
|
|
4755
4767
|
return MySqlSquasher.squashPK(pk);
|
|
4756
4768
|
});
|
|
4769
|
+
const squashedUniqueConstraints = mapValues(it[1].uniqueConstraints, (unq) => {
|
|
4770
|
+
return MySqlSquasher.squashUnique(unq);
|
|
4771
|
+
});
|
|
4757
4772
|
return [
|
|
4758
4773
|
it[0],
|
|
4759
4774
|
{
|
|
@@ -4762,7 +4777,8 @@ var init_mysqlSchema = __esm({
|
|
|
4762
4777
|
columns: it[1].columns,
|
|
4763
4778
|
indexes: squashedIndexes,
|
|
4764
4779
|
foreignKeys: squashedFKs,
|
|
4765
|
-
compositePrimaryKeys: squashedPKs
|
|
4780
|
+
compositePrimaryKeys: squashedPKs,
|
|
4781
|
+
uniqueConstraints: squashedUniqueConstraints
|
|
4766
4782
|
}
|
|
4767
4783
|
];
|
|
4768
4784
|
})
|
|
@@ -4777,7 +4793,11 @@ var init_mysqlSchema = __esm({
|
|
|
4777
4793
|
mysqlSchema = schema2;
|
|
4778
4794
|
mysqlSchemaV4 = schemaV4;
|
|
4779
4795
|
mysqlSchemaV3 = schemaV3;
|
|
4780
|
-
backwardCompatibleMysqlSchema = unionType([
|
|
4796
|
+
backwardCompatibleMysqlSchema = unionType([
|
|
4797
|
+
schemaV3,
|
|
4798
|
+
schemaV4,
|
|
4799
|
+
schema2
|
|
4800
|
+
]);
|
|
4781
4801
|
dryMySql = mysqlSchema.parse({
|
|
4782
4802
|
version: snapshotVersion,
|
|
4783
4803
|
dialect: "mysql",
|
|
@@ -4795,7 +4815,7 @@ var init_mysqlSchema = __esm({
|
|
|
4795
4815
|
});
|
|
4796
4816
|
|
|
4797
4817
|
// src/serializer/pgSchema.ts
|
|
4798
|
-
var indexV2, columnV2, tableV2, enumSchema, pgSchemaV2, references, columnV1, tableV1, pgSchemaV1, index2, fk2, column2, tableV32, compositePK2, tableV42, table2, schemaHash2, pgSchemaInternalV3, pgSchemaInternalV4, pgSchemaInternal, tableSquashed2, tableSquashedV42, pgSchemaSquashedV4, pgSchemaSquashed, pgSchemaV3, pgSchemaV4, pgSchema, backwardCompatiblePgSchema, PgSquasher, squashPgSchemeV4, squashPgScheme, dryPg;
|
|
4818
|
+
var indexV2, columnV2, tableV2, enumSchema, pgSchemaV2, references, columnV1, tableV1, pgSchemaV1, index2, fk2, column2, tableV32, compositePK2, uniqueConstraint2, tableV42, table2, schemaHash2, pgSchemaInternalV3, pgSchemaInternalV4, pgSchemaInternal, tableSquashed2, tableSquashedV42, pgSchemaSquashedV4, pgSchemaSquashed, pgSchemaV3, pgSchemaV4, pgSchema, backwardCompatiblePgSchema, PgSquasher, squashPgSchemeV4, squashPgScheme, dryPg;
|
|
4799
4819
|
var init_pgSchema = __esm({
|
|
4800
4820
|
"src/serializer/pgSchema.ts"() {
|
|
4801
4821
|
init_global();
|
|
@@ -4877,7 +4897,10 @@ var init_pgSchema = __esm({
|
|
|
4877
4897
|
type: stringType(),
|
|
4878
4898
|
primaryKey: booleanType(),
|
|
4879
4899
|
notNull: booleanType(),
|
|
4880
|
-
default: anyType().optional()
|
|
4900
|
+
default: anyType().optional(),
|
|
4901
|
+
isUnique: anyType().optional(),
|
|
4902
|
+
uniqueName: stringType().optional(),
|
|
4903
|
+
nullsNotDistinct: booleanType().optional()
|
|
4881
4904
|
}).strict();
|
|
4882
4905
|
tableV32 = objectType({
|
|
4883
4906
|
name: stringType(),
|
|
@@ -4889,6 +4912,11 @@ var init_pgSchema = __esm({
|
|
|
4889
4912
|
name: stringType(),
|
|
4890
4913
|
columns: stringType().array()
|
|
4891
4914
|
}).strict();
|
|
4915
|
+
uniqueConstraint2 = objectType({
|
|
4916
|
+
name: stringType(),
|
|
4917
|
+
columns: stringType().array(),
|
|
4918
|
+
nullsNotDistinct: booleanType()
|
|
4919
|
+
}).strict();
|
|
4892
4920
|
tableV42 = objectType({
|
|
4893
4921
|
name: stringType(),
|
|
4894
4922
|
schema: stringType(),
|
|
@@ -4902,7 +4930,8 @@ var init_pgSchema = __esm({
|
|
|
4902
4930
|
columns: recordType(stringType(), column2),
|
|
4903
4931
|
indexes: recordType(stringType(), index2),
|
|
4904
4932
|
foreignKeys: recordType(stringType(), fk2),
|
|
4905
|
-
compositePrimaryKeys: recordType(stringType(), compositePK2)
|
|
4933
|
+
compositePrimaryKeys: recordType(stringType(), compositePK2),
|
|
4934
|
+
uniqueConstraints: recordType(stringType(), uniqueConstraint2).default({})
|
|
4906
4935
|
}).strict();
|
|
4907
4936
|
schemaHash2 = objectType({
|
|
4908
4937
|
id: stringType(),
|
|
@@ -4939,7 +4968,8 @@ var init_pgSchema = __esm({
|
|
|
4939
4968
|
columns: recordType(stringType(), column2),
|
|
4940
4969
|
indexes: recordType(stringType(), stringType()),
|
|
4941
4970
|
foreignKeys: recordType(stringType(), stringType()),
|
|
4942
|
-
compositePrimaryKeys: recordType(stringType(), stringType())
|
|
4971
|
+
compositePrimaryKeys: recordType(stringType(), stringType()),
|
|
4972
|
+
uniqueConstraints: recordType(stringType(), stringType())
|
|
4943
4973
|
}).strict();
|
|
4944
4974
|
tableSquashedV42 = objectType({
|
|
4945
4975
|
name: stringType(),
|
|
@@ -4995,6 +5025,17 @@ var init_pgSchema = __esm({
|
|
|
4995
5025
|
unsquashPK: (pk) => {
|
|
4996
5026
|
return { name: "", columns: pk.split(",") };
|
|
4997
5027
|
},
|
|
5028
|
+
squashUnique: (unq) => {
|
|
5029
|
+
return `${unq.name};${unq.columns.join(",")};${unq.nullsNotDistinct}`;
|
|
5030
|
+
},
|
|
5031
|
+
unsquashUnique: (unq) => {
|
|
5032
|
+
const [
|
|
5033
|
+
name,
|
|
5034
|
+
columns,
|
|
5035
|
+
nullsNotDistinct
|
|
5036
|
+
] = unq.split(";");
|
|
5037
|
+
return { name, columns: columns.split(","), nullsNotDistinct: nullsNotDistinct === "true" };
|
|
5038
|
+
},
|
|
4998
5039
|
unsquashFK: (input) => {
|
|
4999
5040
|
const [
|
|
5000
5041
|
name,
|
|
@@ -5058,6 +5099,9 @@ var init_pgSchema = __esm({
|
|
|
5058
5099
|
const squashedPKs = mapValues(it[1].compositePrimaryKeys, (pk) => {
|
|
5059
5100
|
return PgSquasher.squashPK(pk);
|
|
5060
5101
|
});
|
|
5102
|
+
const squashedUniqueConstraints = mapValues(it[1].uniqueConstraints, (unq) => {
|
|
5103
|
+
return PgSquasher.squashUnique(unq);
|
|
5104
|
+
});
|
|
5061
5105
|
return [
|
|
5062
5106
|
it[0],
|
|
5063
5107
|
{
|
|
@@ -5066,7 +5110,8 @@ var init_pgSchema = __esm({
|
|
|
5066
5110
|
columns: it[1].columns,
|
|
5067
5111
|
indexes: squashedIndexes,
|
|
5068
5112
|
foreignKeys: squashedFKs,
|
|
5069
|
-
compositePrimaryKeys: squashedPKs
|
|
5113
|
+
compositePrimaryKeys: squashedPKs,
|
|
5114
|
+
uniqueConstraints: squashedUniqueConstraints
|
|
5070
5115
|
}
|
|
5071
5116
|
];
|
|
5072
5117
|
})
|
|
@@ -5097,7 +5142,7 @@ var init_pgSchema = __esm({
|
|
|
5097
5142
|
});
|
|
5098
5143
|
|
|
5099
5144
|
// src/serializer/sqliteSchema.ts
|
|
5100
|
-
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;
|
|
5101
5146
|
var init_sqliteSchema = __esm({
|
|
5102
5147
|
"src/serializer/sqliteSchema.ts"() {
|
|
5103
5148
|
init_global();
|
|
@@ -5135,12 +5180,17 @@ var init_sqliteSchema = __esm({
|
|
|
5135
5180
|
indexes: recordType(stringType(), index3),
|
|
5136
5181
|
foreignKeys: recordType(stringType(), fk3)
|
|
5137
5182
|
}).strict();
|
|
5183
|
+
uniqueConstraint3 = objectType({
|
|
5184
|
+
name: stringType(),
|
|
5185
|
+
columns: stringType().array()
|
|
5186
|
+
}).strict();
|
|
5138
5187
|
table3 = objectType({
|
|
5139
5188
|
name: stringType(),
|
|
5140
5189
|
columns: recordType(stringType(), column3),
|
|
5141
5190
|
indexes: recordType(stringType(), index3),
|
|
5142
5191
|
foreignKeys: recordType(stringType(), fk3),
|
|
5143
|
-
compositePrimaryKeys: recordType(stringType(), compositePK3)
|
|
5192
|
+
compositePrimaryKeys: recordType(stringType(), compositePK3),
|
|
5193
|
+
uniqueConstraints: recordType(stringType(), uniqueConstraint3).default({})
|
|
5144
5194
|
}).strict();
|
|
5145
5195
|
dialect2 = enumType(["sqlite"]);
|
|
5146
5196
|
schemaHash3 = objectType({
|
|
@@ -5201,6 +5251,13 @@ var init_sqliteSchema = __esm({
|
|
|
5201
5251
|
});
|
|
5202
5252
|
return result;
|
|
5203
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
|
+
},
|
|
5204
5261
|
squashFK: (fk4) => {
|
|
5205
5262
|
return `${fk4.name};${fk4.tableFrom};${fk4.columnsFrom.join(",")};${fk4.tableTo};${fk4.columnsTo.join(",")};${fk4.onUpdate ?? ""};${fk4.onDelete ?? ""}`;
|
|
5206
5263
|
},
|
|
@@ -5244,6 +5301,9 @@ var init_sqliteSchema = __esm({
|
|
|
5244
5301
|
const squashedPKs = mapValues(it[1].compositePrimaryKeys, (pk) => {
|
|
5245
5302
|
return SQLiteSquasher.squashPK(pk);
|
|
5246
5303
|
});
|
|
5304
|
+
const squashedUniqueConstraints = mapValues(it[1].uniqueConstraints, (unq) => {
|
|
5305
|
+
return SQLiteSquasher.squashUnique(unq);
|
|
5306
|
+
});
|
|
5247
5307
|
return [
|
|
5248
5308
|
it[0],
|
|
5249
5309
|
{
|
|
@@ -5251,7 +5311,8 @@ var init_sqliteSchema = __esm({
|
|
|
5251
5311
|
columns: it[1].columns,
|
|
5252
5312
|
indexes: squashedIndexes,
|
|
5253
5313
|
foreignKeys: squashedFKs,
|
|
5254
|
-
compositePrimaryKeys: squashedPKs
|
|
5314
|
+
compositePrimaryKeys: squashedPKs,
|
|
5315
|
+
uniqueConstraints: squashedUniqueConstraints
|
|
5255
5316
|
}
|
|
5256
5317
|
];
|
|
5257
5318
|
})
|
|
@@ -5415,6 +5476,15 @@ var init_jsonDiffer = __esm({
|
|
|
5415
5476
|
const alteredCompositePKs = Object.fromEntries(Object.entries(table4.compositePrimaryKeys || {}).filter((it) => {
|
|
5416
5477
|
return !it[0].endsWith("__deleted") && !it[0].endsWith("__added");
|
|
5417
5478
|
}));
|
|
5479
|
+
const addedUniqueConstraints = Object.fromEntries(Object.entries(table4.uniqueConstraints || {}).filter((it) => {
|
|
5480
|
+
return it[0].endsWith("__added");
|
|
5481
|
+
}));
|
|
5482
|
+
const deletedUniqueConstraints = Object.fromEntries(Object.entries(table4.uniqueConstraints || {}).filter((it) => {
|
|
5483
|
+
return it[0].endsWith("__deleted");
|
|
5484
|
+
}));
|
|
5485
|
+
const alteredUniqueConstraints = Object.fromEntries(Object.entries(table4.uniqueConstraints || {}).filter((it) => {
|
|
5486
|
+
return !it[0].endsWith("__deleted") && !it[0].endsWith("__added");
|
|
5487
|
+
}));
|
|
5418
5488
|
const mappedAltered = altered.map((it) => alternationsInColumn(it));
|
|
5419
5489
|
return {
|
|
5420
5490
|
name: table4.name,
|
|
@@ -5430,7 +5500,10 @@ var init_jsonDiffer = __esm({
|
|
|
5430
5500
|
alteredForeignKeys,
|
|
5431
5501
|
addedCompositePKs,
|
|
5432
5502
|
deletedCompositePKs,
|
|
5433
|
-
alteredCompositePKs
|
|
5503
|
+
alteredCompositePKs,
|
|
5504
|
+
addedUniqueConstraints,
|
|
5505
|
+
deletedUniqueConstraints,
|
|
5506
|
+
alteredUniqueConstraints
|
|
5434
5507
|
};
|
|
5435
5508
|
};
|
|
5436
5509
|
alternationsInColumn = (column7) => {
|
|
@@ -11311,6 +11384,71 @@ var init_mysqlImports = __esm({
|
|
|
11311
11384
|
}
|
|
11312
11385
|
});
|
|
11313
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
|
+
|
|
11314
11452
|
// src/serializer/mysqlSerializer.ts
|
|
11315
11453
|
var mysqlSerializer_exports = {};
|
|
11316
11454
|
__export(mysqlSerializer_exports, {
|
|
@@ -11343,6 +11481,8 @@ var init_mysqlSerializer = __esm({
|
|
|
11343
11481
|
import_mysql_core3 = require("drizzle-orm/mysql-core");
|
|
11344
11482
|
import_drizzle_orm3 = require("drizzle-orm");
|
|
11345
11483
|
init_serializer();
|
|
11484
|
+
init_outputs();
|
|
11485
|
+
init_source();
|
|
11346
11486
|
dialect3 = new import_mysql_core2.MySqlDialect();
|
|
11347
11487
|
indexName = (tableName, columns) => {
|
|
11348
11488
|
return `${tableName}_${columns.join("_")}_index`;
|
|
@@ -11356,12 +11496,14 @@ var init_mysqlSerializer = __esm({
|
|
|
11356
11496
|
indexes,
|
|
11357
11497
|
foreignKeys,
|
|
11358
11498
|
schema: schema4,
|
|
11359
|
-
primaryKeys
|
|
11499
|
+
primaryKeys,
|
|
11500
|
+
uniqueConstraints
|
|
11360
11501
|
} = (0, import_mysql_core3.getTableConfig)(table4);
|
|
11361
11502
|
const columnsObject = {};
|
|
11362
11503
|
const indexesObject = {};
|
|
11363
11504
|
const foreignKeysObject = {};
|
|
11364
11505
|
const primaryKeysObject = {};
|
|
11506
|
+
const uniqueConstraintObject = {};
|
|
11365
11507
|
columns.forEach((column7) => {
|
|
11366
11508
|
const notNull = column7.notNull;
|
|
11367
11509
|
const primaryKey = column7.primary;
|
|
@@ -11382,6 +11524,30 @@ var init_mysqlSerializer = __esm({
|
|
|
11382
11524
|
// ? column.hasOnUpdateNow
|
|
11383
11525
|
// : undefined,
|
|
11384
11526
|
};
|
|
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
|
+
}
|
|
11546
|
+
uniqueConstraintObject[column7.uniqueName] = {
|
|
11547
|
+
name: column7.uniqueName,
|
|
11548
|
+
columns: [columnToSet.name]
|
|
11549
|
+
};
|
|
11550
|
+
}
|
|
11385
11551
|
if (column7.default !== void 0) {
|
|
11386
11552
|
if ((0, import_drizzle_orm2.is)(column7.default, import_drizzle_orm3.SQL)) {
|
|
11387
11553
|
columnToSet.default = sqlToStr(column7.default);
|
|
@@ -11418,6 +11584,34 @@ var init_mysqlSerializer = __esm({
|
|
|
11418
11584
|
columnsObject[column7.name].notNull = true;
|
|
11419
11585
|
}
|
|
11420
11586
|
});
|
|
11587
|
+
uniqueConstraints == null ? void 0 : uniqueConstraints.map((unq) => {
|
|
11588
|
+
const columnNames = unq.columns.map((c) => c.name);
|
|
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
|
+
}
|
|
11610
|
+
uniqueConstraintObject[name] = {
|
|
11611
|
+
name: unq.name,
|
|
11612
|
+
columns: columnNames
|
|
11613
|
+
};
|
|
11614
|
+
});
|
|
11421
11615
|
const fks = foreignKeys.map((fk4) => {
|
|
11422
11616
|
const name = fk4.getName();
|
|
11423
11617
|
const tableFrom = tableName;
|
|
@@ -11466,7 +11660,8 @@ var init_mysqlSerializer = __esm({
|
|
|
11466
11660
|
columns: columnsObject,
|
|
11467
11661
|
indexes: indexesObject,
|
|
11468
11662
|
foreignKeys: foreignKeysObject,
|
|
11469
|
-
compositePrimaryKeys: primaryKeysObject
|
|
11663
|
+
compositePrimaryKeys: primaryKeysObject,
|
|
11664
|
+
uniqueConstraints: uniqueConstraintObject
|
|
11470
11665
|
};
|
|
11471
11666
|
}
|
|
11472
11667
|
const schemas = Object.fromEntries(
|
|
@@ -11544,7 +11739,7 @@ var init_mysqlSerializer = __esm({
|
|
|
11544
11739
|
onUpdate = true;
|
|
11545
11740
|
}
|
|
11546
11741
|
const newColumn = {
|
|
11547
|
-
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}'`,
|
|
11548
11743
|
autoincrement: isAutoincrement,
|
|
11549
11744
|
name: columnName,
|
|
11550
11745
|
type: changedType,
|
|
@@ -11561,7 +11756,8 @@ var init_mysqlSerializer = __esm({
|
|
|
11561
11756
|
},
|
|
11562
11757
|
compositePrimaryKeys: {},
|
|
11563
11758
|
indexes: {},
|
|
11564
|
-
foreignKeys: {}
|
|
11759
|
+
foreignKeys: {},
|
|
11760
|
+
uniqueConstraints: {}
|
|
11565
11761
|
};
|
|
11566
11762
|
} else {
|
|
11567
11763
|
result[tableName].columns[columnName] = newColumn;
|
|
@@ -11660,14 +11856,27 @@ var init_mysqlSerializer = __esm({
|
|
|
11660
11856
|
if (progressCallback) {
|
|
11661
11857
|
progressCallback("indexes", indexesCount, "fetching");
|
|
11662
11858
|
}
|
|
11663
|
-
if (
|
|
11664
|
-
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
|
+
}
|
|
11665
11870
|
} else {
|
|
11666
|
-
tableInResult.indexes[constraintName]
|
|
11667
|
-
|
|
11668
|
-
|
|
11669
|
-
|
|
11670
|
-
|
|
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
|
+
}
|
|
11671
11880
|
}
|
|
11672
11881
|
}
|
|
11673
11882
|
if (progressCallback) {
|
|
@@ -11744,6 +11953,8 @@ var init_pgSerializer = __esm({
|
|
|
11744
11953
|
import_drizzle_orm5 = require("drizzle-orm");
|
|
11745
11954
|
import_drizzle_orm6 = require("drizzle-orm");
|
|
11746
11955
|
init_serializer();
|
|
11956
|
+
init_source();
|
|
11957
|
+
init_outputs();
|
|
11747
11958
|
dialect4 = new import_pg_core2.PgDialect();
|
|
11748
11959
|
indexName2 = (tableName, columns) => {
|
|
11749
11960
|
return `${tableName}_${columns.join("_")}_index`;
|
|
@@ -11758,12 +11969,14 @@ var init_pgSerializer = __esm({
|
|
|
11758
11969
|
foreignKeys,
|
|
11759
11970
|
checks,
|
|
11760
11971
|
schema: schema4,
|
|
11761
|
-
primaryKeys
|
|
11972
|
+
primaryKeys,
|
|
11973
|
+
uniqueConstraints
|
|
11762
11974
|
} = (0, import_pg_core3.getTableConfig)(table4);
|
|
11763
11975
|
const columnsObject = {};
|
|
11764
11976
|
const indexesObject = {};
|
|
11765
11977
|
const foreignKeysObject = {};
|
|
11766
11978
|
const primaryKeysObject = {};
|
|
11979
|
+
const uniqueConstraintObject = {};
|
|
11767
11980
|
columns.forEach((column7) => {
|
|
11768
11981
|
const notNull = column7.notNull;
|
|
11769
11982
|
const primaryKey = column7.primary;
|
|
@@ -11774,6 +11987,31 @@ var init_pgSerializer = __esm({
|
|
|
11774
11987
|
primaryKey,
|
|
11775
11988
|
notNull
|
|
11776
11989
|
};
|
|
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
|
+
}
|
|
12009
|
+
uniqueConstraintObject[column7.uniqueName] = {
|
|
12010
|
+
name: column7.uniqueName,
|
|
12011
|
+
nullsNotDistinct: column7.uniqueType === "not distinct",
|
|
12012
|
+
columns: [columnToSet.name]
|
|
12013
|
+
};
|
|
12014
|
+
}
|
|
11777
12015
|
if (column7.default !== void 0) {
|
|
11778
12016
|
if ((0, import_drizzle_orm5.is)(column7.default, import_drizzle_orm5.SQL)) {
|
|
11779
12017
|
columnToSet.default = sqlToStr(column7.default);
|
|
@@ -11808,6 +12046,33 @@ var init_pgSerializer = __esm({
|
|
|
11808
12046
|
columns: columnNames
|
|
11809
12047
|
};
|
|
11810
12048
|
});
|
|
12049
|
+
uniqueConstraints == null ? void 0 : uniqueConstraints.map((unq) => {
|
|
12050
|
+
const columnNames = unq.columns.map((c) => c.name);
|
|
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
|
+
}
|
|
12070
|
+
uniqueConstraintObject[name] = {
|
|
12071
|
+
name: unq.name,
|
|
12072
|
+
nullsNotDistinct: unq.nullsNotDistinct,
|
|
12073
|
+
columns: columnNames
|
|
12074
|
+
};
|
|
12075
|
+
});
|
|
11811
12076
|
const fks = foreignKeys.map((fk4) => {
|
|
11812
12077
|
const name = fk4.getName();
|
|
11813
12078
|
const tableFrom = tableName;
|
|
@@ -11856,7 +12121,8 @@ var init_pgSerializer = __esm({
|
|
|
11856
12121
|
columns: columnsObject,
|
|
11857
12122
|
indexes: indexesObject,
|
|
11858
12123
|
foreignKeys: foreignKeysObject,
|
|
11859
|
-
compositePrimaryKeys: primaryKeysObject
|
|
12124
|
+
compositePrimaryKeys: primaryKeysObject,
|
|
12125
|
+
uniqueConstraints: uniqueConstraintObject
|
|
11860
12126
|
};
|
|
11861
12127
|
}
|
|
11862
12128
|
const enumsToReturn = enums.reduce((map, obj) => {
|
|
@@ -11916,6 +12182,7 @@ var init_pgSerializer = __esm({
|
|
|
11916
12182
|
const indexToReturn = {};
|
|
11917
12183
|
const foreignKeysToReturn = {};
|
|
11918
12184
|
const primaryKeys = {};
|
|
12185
|
+
const uniqueConstrains = {};
|
|
11919
12186
|
const tableResponse = await db.query(
|
|
11920
12187
|
`SELECT a.attrelid::regclass::text, a.attname, is_nullable, a.attndims as array_dimensions
|
|
11921
12188
|
, CASE WHEN a.atttypid = ANY ('{int,int8,int2}'::regtype[])
|
|
@@ -12009,6 +12276,22 @@ var init_pgSerializer = __esm({
|
|
|
12009
12276
|
...new Set(foreignKeysToReturn[foreignKeyName].columnsTo)
|
|
12010
12277
|
];
|
|
12011
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
|
+
}
|
|
12012
12295
|
for (const columnResponse of tableResponse.rows) {
|
|
12013
12296
|
const columnName = columnResponse.attname;
|
|
12014
12297
|
const columnAdditionalDT = columnResponse.additional_dt;
|
|
@@ -12034,9 +12317,6 @@ var init_pgSerializer = __esm({
|
|
|
12034
12317
|
columns: cprimaryKey.map((c) => c.column_name)
|
|
12035
12318
|
};
|
|
12036
12319
|
}
|
|
12037
|
-
const uniqueKey = tableConstraints.rows.filter(
|
|
12038
|
-
(mapRow) => columnName === mapRow.column_name && mapRow.constraint_type === "UNIQUE"
|
|
12039
|
-
);
|
|
12040
12320
|
const defaultValue = defaultForColumn(columnResponse);
|
|
12041
12321
|
const isSerial = columnType === "serial";
|
|
12042
12322
|
let columnTypeMapped = columnType;
|
|
@@ -12084,10 +12364,25 @@ var init_pgSerializer = __esm({
|
|
|
12084
12364
|
t.relname,
|
|
12085
12365
|
i.relname;`
|
|
12086
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);
|
|
12087
12380
|
for (const dbIndex of dbIndexes.rows) {
|
|
12088
12381
|
const indexName4 = dbIndex.index_name;
|
|
12089
12382
|
const indexColumnName = dbIndex.column_name;
|
|
12090
12383
|
const indexIsUnique = dbIndex.is_unique;
|
|
12384
|
+
if (idxsInConsteraint.includes(indexName4))
|
|
12385
|
+
continue;
|
|
12091
12386
|
if (typeof indexToReturn[indexName4] !== "undefined") {
|
|
12092
12387
|
indexToReturn[indexName4].columns.push(indexColumnName);
|
|
12093
12388
|
} else {
|
|
@@ -12108,7 +12403,8 @@ var init_pgSerializer = __esm({
|
|
|
12108
12403
|
columns: columnToReturn,
|
|
12109
12404
|
indexes: indexToReturn,
|
|
12110
12405
|
foreignKeys: foreignKeysToReturn,
|
|
12111
|
-
compositePrimaryKeys: primaryKeys
|
|
12406
|
+
compositePrimaryKeys: primaryKeys,
|
|
12407
|
+
uniqueConstraints: uniqueConstrains
|
|
12112
12408
|
};
|
|
12113
12409
|
} catch (e) {
|
|
12114
12410
|
rej(e);
|
|
@@ -12303,6 +12599,8 @@ var init_sqliteSerializer = __esm({
|
|
|
12303
12599
|
import_drizzle_orm9 = require("drizzle-orm");
|
|
12304
12600
|
import_sqlite_core2 = require("drizzle-orm/sqlite-core");
|
|
12305
12601
|
init_serializer();
|
|
12602
|
+
init_outputs();
|
|
12603
|
+
init_source();
|
|
12306
12604
|
dialect5 = new import_sqlite_core2.SQLiteSyncDialect();
|
|
12307
12605
|
generateSqliteSnapshot = (tables, enums) => {
|
|
12308
12606
|
const result = {};
|
|
@@ -12311,12 +12609,14 @@ var init_sqliteSerializer = __esm({
|
|
|
12311
12609
|
const indexesObject = {};
|
|
12312
12610
|
const foreignKeysObject = {};
|
|
12313
12611
|
const primaryKeysObject = {};
|
|
12612
|
+
const uniqueConstraintObject = {};
|
|
12314
12613
|
const {
|
|
12315
12614
|
name: tableName,
|
|
12316
12615
|
columns,
|
|
12317
12616
|
indexes,
|
|
12318
12617
|
foreignKeys: tableForeignKeys,
|
|
12319
|
-
primaryKeys
|
|
12618
|
+
primaryKeys,
|
|
12619
|
+
uniqueConstraints
|
|
12320
12620
|
} = (0, import_sqlite_core2.getTableConfig)(table4);
|
|
12321
12621
|
columns.forEach((column7) => {
|
|
12322
12622
|
const notNull = column7.notNull;
|
|
@@ -12336,6 +12636,31 @@ var init_sqliteSerializer = __esm({
|
|
|
12336
12636
|
}
|
|
12337
12637
|
}
|
|
12338
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
|
+
}
|
|
12339
12664
|
});
|
|
12340
12665
|
const foreignKeys = tableForeignKeys.map((fk4) => {
|
|
12341
12666
|
const name = fk4.getName();
|
|
@@ -12383,6 +12708,35 @@ var init_sqliteSerializer = __esm({
|
|
|
12383
12708
|
where
|
|
12384
12709
|
};
|
|
12385
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
|
+
});
|
|
12386
12740
|
primaryKeys.forEach((it) => {
|
|
12387
12741
|
if (it.columns.length > 1) {
|
|
12388
12742
|
primaryKeysObject[it.getName()] = {
|
|
@@ -12397,7 +12751,8 @@ var init_sqliteSerializer = __esm({
|
|
|
12397
12751
|
columns: columnsObject,
|
|
12398
12752
|
indexes: indexesObject,
|
|
12399
12753
|
foreignKeys: foreignKeysObject,
|
|
12400
|
-
compositePrimaryKeys: primaryKeysObject
|
|
12754
|
+
compositePrimaryKeys: primaryKeysObject,
|
|
12755
|
+
uniqueConstraints: uniqueConstraintObject
|
|
12401
12756
|
};
|
|
12402
12757
|
}
|
|
12403
12758
|
return {
|
|
@@ -12481,7 +12836,8 @@ var init_sqliteSerializer = __esm({
|
|
|
12481
12836
|
},
|
|
12482
12837
|
compositePrimaryKeys: {},
|
|
12483
12838
|
indexes: {},
|
|
12484
|
-
foreignKeys: {}
|
|
12839
|
+
foreignKeys: {},
|
|
12840
|
+
uniqueConstraints: {}
|
|
12485
12841
|
};
|
|
12486
12842
|
} else {
|
|
12487
12843
|
result[tableName].columns[columnName] = newColumn;
|
|
@@ -12566,7 +12922,7 @@ FROM sqlite_master AS m,
|
|
|
12566
12922
|
pragma_index_list(m.name) AS il,
|
|
12567
12923
|
pragma_index_info(il.name) AS ii
|
|
12568
12924
|
WHERE
|
|
12569
|
-
m.type = 'table'
|
|
12925
|
+
m.type = 'table';`
|
|
12570
12926
|
);
|
|
12571
12927
|
for (const idxRow of idxs) {
|
|
12572
12928
|
const tableName = idxRow.tableName;
|
|
@@ -14537,7 +14893,7 @@ ${sql}
|
|
|
14537
14893
|
});
|
|
14538
14894
|
|
|
14539
14895
|
// src/sqlgenerator.ts
|
|
14540
|
-
var pgNativeTypes, isPgNativeType, Convertor, PgCreateTableConvertor, MySqlCreateTableConvertor, SQLiteCreateTableConvertor, 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;
|
|
14541
14897
|
var init_sqlgenerator = __esm({
|
|
14542
14898
|
"src/sqlgenerator.ts"() {
|
|
14543
14899
|
init_migrate();
|
|
@@ -14598,30 +14954,37 @@ var init_sqlgenerator = __esm({
|
|
|
14598
14954
|
return statement.type === "create_table" && dialect6 === "pg";
|
|
14599
14955
|
}
|
|
14600
14956
|
convert(st) {
|
|
14601
|
-
const { tableName, schema: schema4, columns, compositePKs } = st;
|
|
14957
|
+
const { tableName, schema: schema4, columns, compositePKs, uniqueConstraints } = st;
|
|
14602
14958
|
let statement = "";
|
|
14603
14959
|
const name = schema4 ? `"${schema4}"."${tableName}"` : `"${tableName}"`;
|
|
14604
14960
|
statement += `CREATE TABLE IF NOT EXISTS ${name} (
|
|
14605
14961
|
`;
|
|
14606
14962
|
for (let i = 0; i < columns.length; i++) {
|
|
14607
14963
|
const column7 = columns[i];
|
|
14608
|
-
const primaryKeyStatement = column7.primaryKey ? "PRIMARY KEY" : "";
|
|
14609
|
-
const notNullStatement = column7.notNull ? "NOT NULL" : "";
|
|
14610
|
-
const defaultStatement = column7.default !== void 0 ? `DEFAULT ${column7.default}` : "";
|
|
14964
|
+
const primaryKeyStatement = column7.primaryKey ? " PRIMARY KEY" : "";
|
|
14965
|
+
const notNullStatement = column7.notNull ? " NOT NULL" : "";
|
|
14966
|
+
const defaultStatement = column7.default !== void 0 ? ` DEFAULT ${column7.default}` : "";
|
|
14967
|
+
const uniqueConstraint4 = column7.isUnique ? ` CONSTRAINT "${column7.uniqueName}" UNIQUE${column7.nullsNotDistinct ? " NULLS NOT DISTINCT" : ""}` : "";
|
|
14611
14968
|
const type = isPgNativeType(column7.type) ? column7.type : `"${column7.type}"`;
|
|
14612
|
-
statement +=
|
|
14613
|
-
statement +=
|
|
14969
|
+
statement += ` "${column7.name}" ${type}${primaryKeyStatement}${defaultStatement}${notNullStatement}${uniqueConstraint4}`;
|
|
14970
|
+
statement += i === columns.length - 1 ? "" : ",\n";
|
|
14614
14971
|
}
|
|
14615
|
-
statement += `);`;
|
|
14616
|
-
statement += `
|
|
14617
|
-
`;
|
|
14618
14972
|
if (typeof compositePKs !== "undefined" && compositePKs.length > 0) {
|
|
14973
|
+
statement += ",\n";
|
|
14619
14974
|
const compositePK4 = PgSquasher.unsquashPK(compositePKs[0]);
|
|
14620
|
-
statement +=
|
|
14621
|
-
statement += `ALTER TABLE ${name} ADD CONSTRAINT "${st.compositePkName}" PRIMARY KEY("${compositePK4.columns.join('","')}");`;
|
|
14622
|
-
statement += `
|
|
14623
|
-
`;
|
|
14975
|
+
statement += ` CONSTRAINT ${st.compositePkName} PRIMARY KEY("${compositePK4.columns.join(`","`)}")`;
|
|
14624
14976
|
}
|
|
14977
|
+
if (typeof uniqueConstraints !== "undefined" && uniqueConstraints.length > 0) {
|
|
14978
|
+
for (const uniqueConstraint4 of uniqueConstraints) {
|
|
14979
|
+
statement += ",\n";
|
|
14980
|
+
const unsquashedUnique = PgSquasher.unsquashUnique(uniqueConstraint4);
|
|
14981
|
+
statement += ` CONSTRAINT "${unsquashedUnique.name}" UNIQUE${unsquashedUnique.nullsNotDistinct ? " NULLS NOT DISTINCT" : ""}("${unsquashedUnique.columns.join(`","`)}")`;
|
|
14982
|
+
}
|
|
14983
|
+
}
|
|
14984
|
+
statement += `
|
|
14985
|
+
);`;
|
|
14986
|
+
statement += `
|
|
14987
|
+
`;
|
|
14625
14988
|
return statement;
|
|
14626
14989
|
}
|
|
14627
14990
|
};
|
|
@@ -14630,7 +14993,7 @@ var init_sqlgenerator = __esm({
|
|
|
14630
14993
|
return statement.type === "create_table" && dialect6 === "mysql";
|
|
14631
14994
|
}
|
|
14632
14995
|
convert(st) {
|
|
14633
|
-
const { tableName, columns, schema: schema4, compositePKs } = st;
|
|
14996
|
+
const { tableName, columns, schema: schema4, compositePKs, uniqueConstraints } = st;
|
|
14634
14997
|
let statement = "";
|
|
14635
14998
|
const tName = schema4 ? `\`${schema4}\`.\`${tableName}\`` : `\`${tableName}\``;
|
|
14636
14999
|
statement += `CREATE TABLE ${tName} (
|
|
@@ -14642,17 +15005,23 @@ var init_sqlgenerator = __esm({
|
|
|
14642
15005
|
const defaultStatement = column7.default !== void 0 ? ` DEFAULT ${column7.default}` : "";
|
|
14643
15006
|
const onUpdateStatement = column7.onUpdate ? ` ON UPDATE CURRENT_TIMESTAMP` : "";
|
|
14644
15007
|
const autoincrementStatement = column7.autoincrement ? " AUTO_INCREMENT" : "";
|
|
14645
|
-
statement +=
|
|
15008
|
+
statement += ` \`${column7.name}\` ${column7.type}${autoincrementStatement}${primaryKeyStatement}${notNullStatement}${defaultStatement}${onUpdateStatement}`;
|
|
14646
15009
|
statement += i === columns.length - 1 ? "" : ",\n";
|
|
14647
15010
|
}
|
|
14648
15011
|
if (typeof compositePKs !== "undefined" && compositePKs.length > 0) {
|
|
14649
15012
|
statement += ",\n";
|
|
14650
15013
|
const compositePK4 = MySqlSquasher.unsquashPK(compositePKs[0]);
|
|
14651
|
-
statement += ` PRIMARY KEY(
|
|
14652
|
-
|
|
14653
|
-
|
|
15014
|
+
statement += ` CONSTRAINT \`${st.compositePkName}\` PRIMARY KEY("${compositePK4.columns.join(`","`)}")`;
|
|
15015
|
+
}
|
|
15016
|
+
if (typeof uniqueConstraints !== "undefined" && uniqueConstraints.length > 0) {
|
|
15017
|
+
for (const uniqueConstraint4 of uniqueConstraints) {
|
|
15018
|
+
statement += ",\n";
|
|
15019
|
+
const unsquashedUnique = MySqlSquasher.unsquashUnique(uniqueConstraint4);
|
|
15020
|
+
statement += ` CONSTRAINT \`${unsquashedUnique.name}\` UNIQUE(\`${unsquashedUnique.columns.join(`\`,\``)}\`)`;
|
|
15021
|
+
}
|
|
14654
15022
|
}
|
|
14655
|
-
statement += `
|
|
15023
|
+
statement += `
|
|
15024
|
+
);`;
|
|
14656
15025
|
statement += `
|
|
14657
15026
|
`;
|
|
14658
15027
|
return statement;
|
|
@@ -14663,21 +15032,28 @@ var init_sqlgenerator = __esm({
|
|
|
14663
15032
|
return statement.type === "sqlite_create_table" && dialect6 === "sqlite";
|
|
14664
15033
|
}
|
|
14665
15034
|
convert(st) {
|
|
14666
|
-
const {
|
|
15035
|
+
const {
|
|
15036
|
+
tableName,
|
|
15037
|
+
columns,
|
|
15038
|
+
referenceData,
|
|
15039
|
+
compositePKs,
|
|
15040
|
+
uniqueConstraints
|
|
15041
|
+
} = st;
|
|
14667
15042
|
let statement = "";
|
|
14668
|
-
statement += `CREATE TABLE \`${tableName}\` (
|
|
15043
|
+
statement += `CREATE TABLE \`${tableName}\` (
|
|
15044
|
+
`;
|
|
14669
15045
|
for (let i = 0; i < columns.length; i++) {
|
|
14670
15046
|
const column7 = columns[i];
|
|
14671
15047
|
const primaryKeyStatement = column7.primaryKey ? " PRIMARY KEY" : "";
|
|
14672
15048
|
const notNullStatement = column7.notNull ? " NOT NULL" : "";
|
|
14673
15049
|
const defaultStatement = column7.default !== void 0 ? ` DEFAULT ${column7.default}` : "";
|
|
14674
15050
|
const autoincrementStatement = column7.autoincrement ? " AUTOINCREMENT" : "";
|
|
14675
|
-
statement += "
|
|
15051
|
+
statement += " ";
|
|
14676
15052
|
statement += `\`${column7.name}\` ${column7.type}${primaryKeyStatement}${autoincrementStatement}${defaultStatement}${notNullStatement}`;
|
|
14677
|
-
statement += "
|
|
15053
|
+
statement += i === columns.length - 1 ? "" : ",\n";
|
|
14678
15054
|
}
|
|
14679
15055
|
compositePKs.forEach((it) => {
|
|
14680
|
-
statement += "
|
|
15056
|
+
statement += ",\n ";
|
|
14681
15057
|
statement += `PRIMARY KEY(${it.map((it2) => `\`${it2}\``).join(", ")}),`;
|
|
14682
15058
|
});
|
|
14683
15059
|
for (let i = 0; i < referenceData.length; i++) {
|
|
@@ -14695,11 +15071,17 @@ var init_sqlgenerator = __esm({
|
|
|
14695
15071
|
const onUpdateStatement = onUpdate ? ` ON UPDATE ${onUpdate}` : "";
|
|
14696
15072
|
const fromColumnsString = columnsFrom.map((it) => `\`${it}\``).join(",");
|
|
14697
15073
|
const toColumnsString = columnsTo.map((it) => `\`${it}\``).join(",");
|
|
15074
|
+
statement += ",";
|
|
14698
15075
|
statement += "\n ";
|
|
14699
15076
|
statement += `FOREIGN KEY (${fromColumnsString}) REFERENCES \`${tableTo}\`(${toColumnsString})${onUpdateStatement}${onDeleteStatement}`;
|
|
14700
|
-
statement += ",";
|
|
14701
15077
|
}
|
|
14702
|
-
|
|
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
|
+
}
|
|
14703
15085
|
statement += `
|
|
14704
15086
|
`;
|
|
14705
15087
|
statement += `);`;
|
|
@@ -14708,6 +15090,72 @@ var init_sqlgenerator = __esm({
|
|
|
14708
15090
|
return statement;
|
|
14709
15091
|
}
|
|
14710
15092
|
};
|
|
15093
|
+
PgAlterTableAddUniqueConstraintConvertor = class extends Convertor {
|
|
15094
|
+
can(statement, dialect6) {
|
|
15095
|
+
return statement.type === "create_unique_constraint" && dialect6 === "pg";
|
|
15096
|
+
}
|
|
15097
|
+
convert(statement) {
|
|
15098
|
+
const unsquashed = PgSquasher.unsquashUnique(statement.data);
|
|
15099
|
+
const tableNameWithSchema = statement.schema ? `"${statement.schema}"."${statement.tableName}"` : `"${statement.tableName}"`;
|
|
15100
|
+
return `ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT "${unsquashed.name}" UNIQUE${unsquashed.nullsNotDistinct ? " NULLS NOT DISTINCT" : ""}("${unsquashed.columns.join('","')}");`;
|
|
15101
|
+
}
|
|
15102
|
+
};
|
|
15103
|
+
PgAlterTableDropUniqueConstraintConvertor = class extends Convertor {
|
|
15104
|
+
can(statement, dialect6) {
|
|
15105
|
+
return statement.type === "delete_unique_constraint" && dialect6 === "pg";
|
|
15106
|
+
}
|
|
15107
|
+
convert(statement) {
|
|
15108
|
+
const unsquashed = PgSquasher.unsquashUnique(statement.data);
|
|
15109
|
+
const tableNameWithSchema = statement.schema ? `"${statement.schema}"."${statement.tableName}"` : `"${statement.tableName}"`;
|
|
15110
|
+
return `ALTER TABLE ${tableNameWithSchema} DROP CONSTRAINT "${unsquashed.name}";`;
|
|
15111
|
+
}
|
|
15112
|
+
};
|
|
15113
|
+
MySQLAlterTableAddUniqueConstraintConvertor = class extends Convertor {
|
|
15114
|
+
can(statement, dialect6) {
|
|
15115
|
+
return statement.type === "create_unique_constraint" && dialect6 === "mysql";
|
|
15116
|
+
}
|
|
15117
|
+
convert(statement) {
|
|
15118
|
+
const unsquashed = MySqlSquasher.unsquashUnique(statement.data);
|
|
15119
|
+
const tableNameWithSchema = statement.schema ? `\`${statement.schema}\`.\`${statement.tableName}\`` : `\`${statement.tableName}\``;
|
|
15120
|
+
return `ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT \`${unsquashed.name}\` UNIQUE(\`${unsquashed.columns.join("`,`")}\`);`;
|
|
15121
|
+
}
|
|
15122
|
+
};
|
|
15123
|
+
MySQLAlterTableDropUniqueConstraintConvertor = class extends Convertor {
|
|
15124
|
+
can(statement, dialect6) {
|
|
15125
|
+
return statement.type === "delete_unique_constraint" && dialect6 === "mysql";
|
|
15126
|
+
}
|
|
15127
|
+
convert(statement) {
|
|
15128
|
+
const unsquashed = MySqlSquasher.unsquashUnique(statement.data);
|
|
15129
|
+
const tableNameWithSchema = statement.schema ? `\`${statement.schema}\`.\`${statement.tableName}\`` : `\`${statement.tableName}\``;
|
|
15130
|
+
return `ALTER TABLE ${tableNameWithSchema} DROP CONSTRAINT \`${unsquashed.name}\`;`;
|
|
15131
|
+
}
|
|
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
|
+
};
|
|
14711
15159
|
CreateTypeEnumConvertor = class extends Convertor {
|
|
14712
15160
|
can(statement) {
|
|
14713
15161
|
return statement.type === "create_type_enum";
|
|
@@ -15663,6 +16111,10 @@ ${BREAKPOINT}ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT ${statement.newCo
|
|
|
15663
16111
|
convertors.push(new MySqlAlterTableAddColumnConvertor());
|
|
15664
16112
|
convertors.push(new SQLiteAlterTableAddColumnConvertor());
|
|
15665
16113
|
convertors.push(new PgAlterTableAlterColumnSetTypeConvertor());
|
|
16114
|
+
convertors.push(new PgAlterTableAddUniqueConstraintConvertor());
|
|
16115
|
+
convertors.push(new PgAlterTableDropUniqueConstraintConvertor());
|
|
16116
|
+
convertors.push(new MySQLAlterTableAddUniqueConstraintConvertor());
|
|
16117
|
+
convertors.push(new MySQLAlterTableDropUniqueConstraintConvertor());
|
|
15666
16118
|
convertors.push(new CreatePgIndexConvertor());
|
|
15667
16119
|
convertors.push(new CreateMySqlIndexConvertor());
|
|
15668
16120
|
convertors.push(new CreateSqliteIndexConvertor());
|
|
@@ -15697,6 +16149,8 @@ ${BREAKPOINT}ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT ${statement.newCo
|
|
|
15697
16149
|
convertors.push(new SqliteAlterForeignKeyConvertor());
|
|
15698
16150
|
convertors.push(new SqliteDeleteForeignKeyConvertor());
|
|
15699
16151
|
convertors.push(new SqliteCreateForeignKeyConvertor());
|
|
16152
|
+
convertors.push(new SQLiteAlterTableAddUniqueConstraintConvertor());
|
|
16153
|
+
convertors.push(new SQLiteAlterTableDropUniqueConstraintConvertor());
|
|
15700
16154
|
convertors.push(new SqliteAlterTableAlterColumnSetNotNullConvertor());
|
|
15701
16155
|
convertors.push(new SqliteAlterTableAlterColumnDropNotNullConvertor());
|
|
15702
16156
|
convertors.push(new SqliteAlterTableAlterColumnSetDefaultConvertor());
|
|
@@ -15755,14 +16209,14 @@ drop type __venum;
|
|
|
15755
16209
|
});
|
|
15756
16210
|
|
|
15757
16211
|
// src/jsonStatements.ts
|
|
15758
|
-
var preparePgCreateTableJson, prepareMySqlCreateTableJson, prepareSQLiteCreateTable, prepareDropTableJson, prepareRenameTableJson, prepareCreateEnumJson, prepareAddValuesToEnumJson, prepareCreateSchemasJson, prepareRenameSchemasJson, prepareDeleteSchemasJson, prepareRenameColumns, prepareAlterTableColumnsJson, _prepareDropColumns, _prepareAddColumns, _prepareSQLiteAddColumns, _prepareAlterColumns, prepareCreateIndexesJson, prepareCreateReferencesJson, prepareDropReferencesJson, prepareAlterReferencesJson, prepareDropIndexesJson, prepareAddCompositePrimaryKeySqlite, prepareDeleteCompositePrimaryKeySqlite, prepareAlterCompositePrimaryKeySqlite, prepareAddCompositePrimaryKeyPg, prepareDeleteCompositePrimaryKeyPg, prepareAlterCompositePrimaryKeyPg, prepareAddCompositePrimaryKeyMySql, prepareDeleteCompositePrimaryKeyMySql, prepareAlterCompositePrimaryKeyMySql;
|
|
16212
|
+
var preparePgCreateTableJson, prepareMySqlCreateTableJson, prepareSQLiteCreateTable, prepareDropTableJson, prepareRenameTableJson, prepareCreateEnumJson, prepareAddValuesToEnumJson, prepareCreateSchemasJson, prepareRenameSchemasJson, prepareDeleteSchemasJson, prepareRenameColumns, prepareAlterTableColumnsJson, _prepareDropColumns, _prepareAddColumns, _prepareSQLiteAddColumns, _prepareAlterColumns, prepareCreateIndexesJson, prepareCreateReferencesJson, prepareDropReferencesJson, prepareAlterReferencesJson, prepareDropIndexesJson, prepareAddCompositePrimaryKeySqlite, prepareDeleteCompositePrimaryKeySqlite, prepareAlterCompositePrimaryKeySqlite, prepareAddCompositePrimaryKeyPg, prepareDeleteCompositePrimaryKeyPg, prepareAlterCompositePrimaryKeyPg, prepareAddUniqueConstraintPg, prepareDeleteUniqueConstraintPg, prepareAddCompositePrimaryKeyMySql, prepareDeleteCompositePrimaryKeyMySql, prepareAlterCompositePrimaryKeyMySql;
|
|
15759
16213
|
var init_jsonStatements = __esm({
|
|
15760
16214
|
"src/jsonStatements.ts"() {
|
|
15761
16215
|
init_mysqlSchema();
|
|
15762
16216
|
init_pgSchema();
|
|
15763
16217
|
init_sqliteSchema();
|
|
15764
16218
|
preparePgCreateTableJson = (table4, json2) => {
|
|
15765
|
-
const { name, schema: schema4, columns, compositePrimaryKeys } = table4;
|
|
16219
|
+
const { name, schema: schema4, columns, compositePrimaryKeys, uniqueConstraints } = table4;
|
|
15766
16220
|
return {
|
|
15767
16221
|
type: "create_table",
|
|
15768
16222
|
tableName: name,
|
|
@@ -15771,11 +16225,12 @@ var init_jsonStatements = __esm({
|
|
|
15771
16225
|
compositePKs: Object.values(compositePrimaryKeys),
|
|
15772
16226
|
compositePkName: Object.values(compositePrimaryKeys).length > 0 ? json2.tables[name].compositePrimaryKeys[`${name}_${PgSquasher.unsquashPK(
|
|
15773
16227
|
Object.values(compositePrimaryKeys)[0]
|
|
15774
|
-
).columns.join("_")}`].name : ""
|
|
16228
|
+
).columns.join("_")}`].name : "",
|
|
16229
|
+
uniqueConstraints: Object.values(uniqueConstraints)
|
|
15775
16230
|
};
|
|
15776
16231
|
};
|
|
15777
16232
|
prepareMySqlCreateTableJson = (table4, json2) => {
|
|
15778
|
-
const { name, schema: schema4, columns, compositePrimaryKeys } = table4;
|
|
16233
|
+
const { name, schema: schema4, columns, compositePrimaryKeys, uniqueConstraints } = table4;
|
|
15779
16234
|
return {
|
|
15780
16235
|
type: "create_table",
|
|
15781
16236
|
tableName: name,
|
|
@@ -15784,11 +16239,12 @@ var init_jsonStatements = __esm({
|
|
|
15784
16239
|
compositePKs: Object.values(compositePrimaryKeys),
|
|
15785
16240
|
compositePkName: Object.values(compositePrimaryKeys).length > 0 ? json2.tables[name].compositePrimaryKeys[`${name}_${MySqlSquasher.unsquashPK(
|
|
15786
16241
|
Object.values(compositePrimaryKeys)[0]
|
|
15787
|
-
).columns.join("_")}`].name : ""
|
|
16242
|
+
).columns.join("_")}`].name : "",
|
|
16243
|
+
uniqueConstraints: Object.values(uniqueConstraints)
|
|
15788
16244
|
};
|
|
15789
16245
|
};
|
|
15790
16246
|
prepareSQLiteCreateTable = (table4) => {
|
|
15791
|
-
const { name, columns } = table4;
|
|
16247
|
+
const { name, columns, uniqueConstraints } = table4;
|
|
15792
16248
|
const references2 = Object.values(table4.foreignKeys);
|
|
15793
16249
|
const composites = Object.values(table4.compositePrimaryKeys).map(
|
|
15794
16250
|
(it) => SQLiteSquasher.unsquashPK(it)
|
|
@@ -15798,7 +16254,8 @@ var init_jsonStatements = __esm({
|
|
|
15798
16254
|
tableName: name,
|
|
15799
16255
|
columns: Object.values(columns),
|
|
15800
16256
|
referenceData: references2,
|
|
15801
|
-
compositePKs: composites
|
|
16257
|
+
compositePKs: composites,
|
|
16258
|
+
uniqueConstraints: Object.values(uniqueConstraints)
|
|
15802
16259
|
};
|
|
15803
16260
|
};
|
|
15804
16261
|
prepareDropTableJson = (table4) => {
|
|
@@ -16269,6 +16726,26 @@ var init_jsonStatements = __esm({
|
|
|
16269
16726
|
};
|
|
16270
16727
|
});
|
|
16271
16728
|
};
|
|
16729
|
+
prepareAddUniqueConstraintPg = (tableName, schema4, unqs) => {
|
|
16730
|
+
return Object.values(unqs).map((it) => {
|
|
16731
|
+
return {
|
|
16732
|
+
type: "create_unique_constraint",
|
|
16733
|
+
tableName,
|
|
16734
|
+
data: it,
|
|
16735
|
+
schema: schema4
|
|
16736
|
+
};
|
|
16737
|
+
});
|
|
16738
|
+
};
|
|
16739
|
+
prepareDeleteUniqueConstraintPg = (tableName, schema4, unqs) => {
|
|
16740
|
+
return Object.values(unqs).map((it) => {
|
|
16741
|
+
return {
|
|
16742
|
+
type: "delete_unique_constraint",
|
|
16743
|
+
tableName,
|
|
16744
|
+
data: it,
|
|
16745
|
+
schema: schema4
|
|
16746
|
+
};
|
|
16747
|
+
});
|
|
16748
|
+
};
|
|
16272
16749
|
prepareAddCompositePrimaryKeyMySql = (tableName, pks, json2) => {
|
|
16273
16750
|
return Object.values(pks).map((it) => {
|
|
16274
16751
|
return {
|
|
@@ -16386,12 +16863,14 @@ var init_snapshotsDiffer = __esm({
|
|
|
16386
16863
|
name: stringType(),
|
|
16387
16864
|
type: stringType(),
|
|
16388
16865
|
primaryKey: booleanType().optional(),
|
|
16389
|
-
unique: booleanType().optional(),
|
|
16390
16866
|
default: anyType().optional(),
|
|
16391
16867
|
notNull: booleanType().optional(),
|
|
16392
16868
|
// should it be optional? should if be here?
|
|
16393
16869
|
autoincrement: booleanType().optional(),
|
|
16394
|
-
onUpdate: booleanType().optional()
|
|
16870
|
+
onUpdate: booleanType().optional(),
|
|
16871
|
+
isUnique: anyType().optional(),
|
|
16872
|
+
uniqueName: stringType().optional(),
|
|
16873
|
+
nullsNotDistinct: booleanType().optional()
|
|
16395
16874
|
}).strict();
|
|
16396
16875
|
alteredColumnSchema = objectType({
|
|
16397
16876
|
name: makeSelfOrChanged(stringType()),
|
|
@@ -16417,7 +16896,8 @@ var init_snapshotsDiffer = __esm({
|
|
|
16417
16896
|
columns: recordType(stringType(), columnSchema),
|
|
16418
16897
|
indexes: recordType(stringType(), stringType()),
|
|
16419
16898
|
foreignKeys: recordType(stringType(), stringType()),
|
|
16420
|
-
compositePrimaryKeys: recordType(stringType(), stringType()).default({})
|
|
16899
|
+
compositePrimaryKeys: recordType(stringType(), stringType()).default({}),
|
|
16900
|
+
uniqueConstraints: recordType(stringType(), stringType()).default({})
|
|
16421
16901
|
}).strict();
|
|
16422
16902
|
alteredTableScheme = objectType({
|
|
16423
16903
|
name: stringType(),
|
|
@@ -16451,6 +16931,15 @@ var init_snapshotsDiffer = __esm({
|
|
|
16451
16931
|
__new: stringType(),
|
|
16452
16932
|
__old: stringType()
|
|
16453
16933
|
})
|
|
16934
|
+
),
|
|
16935
|
+
addedUniqueConstraints: recordType(stringType(), stringType()),
|
|
16936
|
+
deletedUniqueConstraints: recordType(stringType(), stringType()),
|
|
16937
|
+
alteredUniqueConstraints: recordType(
|
|
16938
|
+
stringType(),
|
|
16939
|
+
objectType({
|
|
16940
|
+
__new: stringType(),
|
|
16941
|
+
__old: stringType()
|
|
16942
|
+
})
|
|
16454
16943
|
)
|
|
16455
16944
|
}).strict();
|
|
16456
16945
|
diffResultScheme = objectType({
|
|
@@ -16540,13 +17029,19 @@ var init_snapshotsDiffer = __esm({
|
|
|
16540
17029
|
alteredForeignKeys: table4.alteredForeignKeys,
|
|
16541
17030
|
addedCompositePKs: table4.addedCompositePKs,
|
|
16542
17031
|
deletedCompositePKs: table4.deletedCompositePKs,
|
|
16543
|
-
alteredCompositePKs: table4.alteredCompositePKs
|
|
17032
|
+
alteredCompositePKs: table4.alteredCompositePKs,
|
|
17033
|
+
addedUniqueConstraints: table4.addedUniqueConstraints,
|
|
17034
|
+
deletedUniqueConstraints: table4.deletedUniqueConstraints,
|
|
17035
|
+
alteredUniqueConstraints: table4.alteredUniqueConstraints
|
|
16544
17036
|
};
|
|
16545
17037
|
allAlteredResolved.push(resolved);
|
|
16546
17038
|
}
|
|
16547
17039
|
const jsonAddedCompositePKs = [];
|
|
16548
17040
|
const jsonDeletedCompositePKs = [];
|
|
16549
17041
|
const jsonAlteredCompositePKs = [];
|
|
17042
|
+
const jsonAddedUniqueConstraints = [];
|
|
17043
|
+
const jsonDeletedUniqueConstraints = [];
|
|
17044
|
+
const jsonAlteredUniqueConstraints = [];
|
|
16550
17045
|
const jsonSetTableSchemas = [];
|
|
16551
17046
|
const jsonRemoveTableFromSchemas = [];
|
|
16552
17047
|
const jsonSetNewTableSchemas = [];
|
|
@@ -16638,6 +17133,33 @@ var init_snapshotsDiffer = __esm({
|
|
|
16638
17133
|
curFull
|
|
16639
17134
|
);
|
|
16640
17135
|
}
|
|
17136
|
+
let addedUniqueConstraints = [];
|
|
17137
|
+
let deletedUniqueConstraints = [];
|
|
17138
|
+
let alteredUniqueConstraints = [];
|
|
17139
|
+
addedUniqueConstraints = prepareAddUniqueConstraintPg(
|
|
17140
|
+
it.name,
|
|
17141
|
+
schemaUnwrapped,
|
|
17142
|
+
it.addedUniqueConstraints
|
|
17143
|
+
);
|
|
17144
|
+
deletedUniqueConstraints = prepareDeleteUniqueConstraintPg(
|
|
17145
|
+
it.name,
|
|
17146
|
+
schemaUnwrapped,
|
|
17147
|
+
it.deletedUniqueConstraints
|
|
17148
|
+
);
|
|
17149
|
+
if (it.alteredUniqueConstraints) {
|
|
17150
|
+
const added = {};
|
|
17151
|
+
const deleted2 = {};
|
|
17152
|
+
for (const k of Object.keys(it.alteredUniqueConstraints)) {
|
|
17153
|
+
added[k] = it.alteredUniqueConstraints[k].__new;
|
|
17154
|
+
deleted2[k] = it.alteredUniqueConstraints[k].__old;
|
|
17155
|
+
}
|
|
17156
|
+
addedUniqueConstraints.push(
|
|
17157
|
+
...prepareAddUniqueConstraintPg(it.name, schemaUnwrapped, added)
|
|
17158
|
+
);
|
|
17159
|
+
deletedUniqueConstraints.push(
|
|
17160
|
+
...prepareDeleteUniqueConstraintPg(it.name, schemaUnwrapped, deleted2)
|
|
17161
|
+
);
|
|
17162
|
+
}
|
|
16641
17163
|
if (it.schema && typeof it.schema !== "string") {
|
|
16642
17164
|
switch (it.schema.type) {
|
|
16643
17165
|
case "added": {
|
|
@@ -16670,6 +17192,9 @@ var init_snapshotsDiffer = __esm({
|
|
|
16670
17192
|
jsonAddedCompositePKs.push(...addedCompositePKs);
|
|
16671
17193
|
jsonDeletedCompositePKs.push(...deletedCompositePKs);
|
|
16672
17194
|
jsonAlteredCompositePKs.push(...alteredCompositePKs);
|
|
17195
|
+
jsonAddedUniqueConstraints.push(...addedUniqueConstraints);
|
|
17196
|
+
jsonDeletedUniqueConstraints.push(...deletedUniqueConstraints);
|
|
17197
|
+
jsonAlteredUniqueConstraints.push(...alteredUniqueConstraints);
|
|
16673
17198
|
});
|
|
16674
17199
|
const rColumns = jsonRenameColumnsStatements.map((it) => {
|
|
16675
17200
|
const tableName = it.tableName;
|
|
@@ -16794,6 +17319,7 @@ var init_snapshotsDiffer = __esm({
|
|
|
16794
17319
|
jsonStatements.push(...jsonSQLiteCreateTables);
|
|
16795
17320
|
} else if (dialect6 === "pg") {
|
|
16796
17321
|
const jsonPgCreateTables = created.map((it) => {
|
|
17322
|
+
console.log(it);
|
|
16797
17323
|
return preparePgCreateTableJson(it, curFull);
|
|
16798
17324
|
});
|
|
16799
17325
|
jsonStatements.push(...jsonPgCreateTables);
|
|
@@ -16807,6 +17333,7 @@ var init_snapshotsDiffer = __esm({
|
|
|
16807
17333
|
jsonStatements.push(...jsonRenameTables);
|
|
16808
17334
|
jsonStatements.push(...jsonRenameColumnsStatements);
|
|
16809
17335
|
jsonStatements.push(...jsonDeletedCompositePKs);
|
|
17336
|
+
jsonStatements.push(...jsonDeletedUniqueConstraints);
|
|
16810
17337
|
jsonStatements.push(...jsonDroppedReferencesForAlteredTables);
|
|
16811
17338
|
jsonStatements.push(...jsonDropIndexesForAllAlteredTables);
|
|
16812
17339
|
jsonStatements.push(...jsonTableAlternations.alterColumns);
|
|
@@ -16819,6 +17346,8 @@ var init_snapshotsDiffer = __esm({
|
|
|
16819
17346
|
jsonStatements.push(...jsonCreateReferences);
|
|
16820
17347
|
jsonStatements.push(...jsonAddedCompositePKs);
|
|
16821
17348
|
jsonStatements.push(...jsonAlteredCompositePKs);
|
|
17349
|
+
jsonStatements.push(...jsonAddedUniqueConstraints);
|
|
17350
|
+
jsonStatements.push(...jsonAlteredUniqueConstraints);
|
|
16822
17351
|
jsonStatements.push(...jsonSetTableSchemas);
|
|
16823
17352
|
jsonStatements.push(...filteredJsonSetNewTableSchemas);
|
|
16824
17353
|
jsonStatements.push(...jsonRemoveTableFromSchemas);
|
|
@@ -18047,70 +18576,6 @@ var init_sqliteUtils = __esm({
|
|
|
18047
18576
|
}
|
|
18048
18577
|
});
|
|
18049
18578
|
|
|
18050
|
-
// src/cli/validations/outputs.ts
|
|
18051
|
-
var withStyle, outputs;
|
|
18052
|
-
var init_outputs = __esm({
|
|
18053
|
-
"src/cli/validations/outputs.ts"() {
|
|
18054
|
-
init_source();
|
|
18055
|
-
withStyle = {
|
|
18056
|
-
error: (str) => `${source_default.red(`${source_default.white.bgRed(" Invalid input ")} ${str}`)}`,
|
|
18057
|
-
warning: (str) => `${source_default.white.bgGray(" Warning ")} ${str}`,
|
|
18058
|
-
fullWarning: (str) => `${source_default.black.bgYellow("[Warning]")} ${source_default.bold(str)}`
|
|
18059
|
-
};
|
|
18060
|
-
outputs = {
|
|
18061
|
-
studio: {
|
|
18062
|
-
drivers: (param) => withStyle.error(
|
|
18063
|
-
`"${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`
|
|
18064
|
-
),
|
|
18065
|
-
noCredentials: () => withStyle.error(
|
|
18066
|
-
`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`
|
|
18067
|
-
),
|
|
18068
|
-
noDriver: () => withStyle.error(
|
|
18069
|
-
`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`
|
|
18070
|
-
)
|
|
18071
|
-
},
|
|
18072
|
-
common: {
|
|
18073
|
-
ambiguousParams: (command) => withStyle.error(
|
|
18074
|
-
`You can't use both --config and other cli options for ${command} command`
|
|
18075
|
-
),
|
|
18076
|
-
schema: (command) => withStyle.error(`"--schema" is a required field for ${command} command`),
|
|
18077
|
-
schemaConfig: (command) => withStyle.error(
|
|
18078
|
-
`"schema" is a required field in drizzle.config for ${command} command`
|
|
18079
|
-
)
|
|
18080
|
-
},
|
|
18081
|
-
postgres: {
|
|
18082
|
-
connection: {
|
|
18083
|
-
driver: () => withStyle.error(`Only "pg" is available options for "--driver"`),
|
|
18084
|
-
required: () => withStyle.error(
|
|
18085
|
-
`Either "connectionString" or "host", "database" are required for database connection`
|
|
18086
|
-
)
|
|
18087
|
-
}
|
|
18088
|
-
},
|
|
18089
|
-
mysql: {
|
|
18090
|
-
connection: {
|
|
18091
|
-
driver: () => withStyle.error(`Only "mysql2" is available options for "--driver"`),
|
|
18092
|
-
required: () => withStyle.error(
|
|
18093
|
-
`Either "connectionString" or "host", "database" are required for database connection`
|
|
18094
|
-
)
|
|
18095
|
-
}
|
|
18096
|
-
},
|
|
18097
|
-
sqlite: {
|
|
18098
|
-
connection: {
|
|
18099
|
-
driver: () => withStyle.error(
|
|
18100
|
-
`Either "turso", "libsql", "better-sqlite" are available options for "--driver"`
|
|
18101
|
-
),
|
|
18102
|
-
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`),
|
|
18103
|
-
authToken: (driver) => withStyle.error(
|
|
18104
|
-
`"authToken" is a required option for driver "${driver}". You can read more about drizzle.config: https://orm.drizzle.team/kit-docs/config-reference`
|
|
18105
|
-
)
|
|
18106
|
-
},
|
|
18107
|
-
introspect: {},
|
|
18108
|
-
push: {}
|
|
18109
|
-
}
|
|
18110
|
-
};
|
|
18111
|
-
}
|
|
18112
|
-
});
|
|
18113
|
-
|
|
18114
18579
|
// src/cli/validations/common.ts
|
|
18115
18580
|
var checkCollisions;
|
|
18116
18581
|
var init_common = __esm({
|
|
@@ -35139,7 +35604,7 @@ var require_promise = __commonJS({
|
|
|
35139
35604
|
});
|
|
35140
35605
|
|
|
35141
35606
|
// src/mysql-introspect.ts
|
|
35142
|
-
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;
|
|
35143
35608
|
var init_mysql_introspect = __esm({
|
|
35144
35609
|
"src/mysql-introspect.ts"() {
|
|
35145
35610
|
init_utils3();
|
|
@@ -35239,9 +35704,13 @@ var init_mysql_introspect = __esm({
|
|
|
35239
35704
|
const pkImports = Object.values(it.compositePrimaryKeys).map(
|
|
35240
35705
|
(it2) => "primaryKey"
|
|
35241
35706
|
);
|
|
35707
|
+
const uniqueImports = Object.values(it.uniqueConstraints).map(
|
|
35708
|
+
(it2) => "unique"
|
|
35709
|
+
);
|
|
35242
35710
|
res.mysql.push(...idxImports);
|
|
35243
35711
|
res.mysql.push(...fkImpots);
|
|
35244
35712
|
res.mysql.push(...pkImports);
|
|
35713
|
+
res.mysql.push(...uniqueImports);
|
|
35245
35714
|
const columnImports = Object.values(it.columns).map((col) => {
|
|
35246
35715
|
let patched = importsPatch[col.type] ?? col.type;
|
|
35247
35716
|
patched = patched.startsWith("varchar(") ? "varchar" : patched;
|
|
@@ -35288,7 +35757,7 @@ var init_mysql_introspect = __esm({
|
|
|
35288
35757
|
const filteredFKs = Object.values(table4.foreignKeys).filter((it) => {
|
|
35289
35758
|
return it.columnsFrom.length > 1 || isSelf(it);
|
|
35290
35759
|
});
|
|
35291
|
-
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) {
|
|
35292
35761
|
statement += ",\n";
|
|
35293
35762
|
statement += "(table) => {\n";
|
|
35294
35763
|
statement += " return {\n";
|
|
@@ -35302,6 +35771,10 @@ var init_mysql_introspect = __esm({
|
|
|
35302
35771
|
Object.values(table4.compositePrimaryKeys),
|
|
35303
35772
|
casing
|
|
35304
35773
|
);
|
|
35774
|
+
statement += createTableUniques(
|
|
35775
|
+
Object.values(table4.uniqueConstraints),
|
|
35776
|
+
casing
|
|
35777
|
+
);
|
|
35305
35778
|
statement += " }\n";
|
|
35306
35779
|
statement += "}";
|
|
35307
35780
|
}
|
|
@@ -35612,6 +36085,19 @@ import { sql } from "drizzle-orm"
|
|
|
35612
36085
|
statement += `${escapedIndexName})`;
|
|
35613
36086
|
statement += `.on(${it.columns.map((it2) => `table.${withCasing(it2, casing)}`).join(", ")}),`;
|
|
35614
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 += `
|
|
35615
36101
|
`;
|
|
35616
36102
|
});
|
|
35617
36103
|
return statement;
|
|
@@ -36940,10 +37426,10 @@ __export(mysqlIntrospect_exports, {
|
|
|
36940
37426
|
mysqlIntrospect: () => mysqlIntrospect,
|
|
36941
37427
|
mysqlPushIntrospect: () => mysqlPushIntrospect
|
|
36942
37428
|
});
|
|
36943
|
-
var
|
|
37429
|
+
var import_hanji6, import_promise, connectToMySQL, mysqlIntrospect, mysqlPushIntrospect;
|
|
36944
37430
|
var init_mysqlIntrospect = __esm({
|
|
36945
37431
|
"src/cli/commands/mysqlIntrospect.ts"() {
|
|
36946
|
-
|
|
37432
|
+
import_hanji6 = __toESM(require_hanji());
|
|
36947
37433
|
init_views();
|
|
36948
37434
|
import_promise = __toESM(require_promise());
|
|
36949
37435
|
init_mysqlSerializer();
|
|
@@ -36992,7 +37478,7 @@ var init_mysqlIntrospect = __esm({
|
|
|
36992
37478
|
return false;
|
|
36993
37479
|
};
|
|
36994
37480
|
const progress = new IntrospectProgress();
|
|
36995
|
-
const res = await (0,
|
|
37481
|
+
const res = await (0, import_hanji6.renderWithTask)(
|
|
36996
37482
|
progress,
|
|
36997
37483
|
fromDatabase(
|
|
36998
37484
|
client,
|
|
@@ -37030,7 +37516,7 @@ var init_mysqlIntrospect = __esm({
|
|
|
37030
37516
|
});
|
|
37031
37517
|
|
|
37032
37518
|
// src/sqlite-introspect.ts
|
|
37033
|
-
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;
|
|
37034
37520
|
var init_sqlite_introspect = __esm({
|
|
37035
37521
|
"src/sqlite-introspect.ts"() {
|
|
37036
37522
|
init_utils3();
|
|
@@ -37081,9 +37567,13 @@ var init_sqlite_introspect = __esm({
|
|
|
37081
37567
|
const pkImports = Object.values(it.compositePrimaryKeys).map(
|
|
37082
37568
|
(it2) => "primaryKey"
|
|
37083
37569
|
);
|
|
37570
|
+
const uniqueImports = Object.values(it.uniqueConstraints).map(
|
|
37571
|
+
(it2) => "unique"
|
|
37572
|
+
);
|
|
37084
37573
|
res.sqlite.push(...idxImports);
|
|
37085
37574
|
res.sqlite.push(...fkImpots);
|
|
37086
37575
|
res.sqlite.push(...pkImports);
|
|
37576
|
+
res.sqlite.push(...uniqueImports);
|
|
37087
37577
|
const columnImports = Object.values(it.columns).map((col) => {
|
|
37088
37578
|
return col.type;
|
|
37089
37579
|
}).filter((type) => {
|
|
@@ -37116,7 +37606,7 @@ var init_sqlite_introspect = __esm({
|
|
|
37116
37606
|
const filteredFKs = Object.values(table4.foreignKeys).filter((it) => {
|
|
37117
37607
|
return it.columnsFrom.length > 1 || isSelf2(it);
|
|
37118
37608
|
});
|
|
37119
|
-
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) {
|
|
37120
37610
|
statement += ",\n";
|
|
37121
37611
|
statement += "(table) => {\n";
|
|
37122
37612
|
statement += " return {\n";
|
|
@@ -37130,6 +37620,10 @@ var init_sqlite_introspect = __esm({
|
|
|
37130
37620
|
Object.values(table4.compositePrimaryKeys),
|
|
37131
37621
|
casing
|
|
37132
37622
|
);
|
|
37623
|
+
statement += createTableUniques2(
|
|
37624
|
+
Object.values(table4.uniqueConstraints),
|
|
37625
|
+
casing
|
|
37626
|
+
);
|
|
37133
37627
|
statement += " }\n";
|
|
37134
37628
|
statement += "}";
|
|
37135
37629
|
}
|
|
@@ -37249,6 +37743,19 @@ import { sql } from "drizzle-orm"
|
|
|
37249
37743
|
statement += `${escapedIndexName})`;
|
|
37250
37744
|
statement += `.on(${it.columns.map((it2) => `table.${withCasing2(it2, casing)}`).join(", ")}),`;
|
|
37251
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 += `
|
|
37252
37759
|
`;
|
|
37253
37760
|
});
|
|
37254
37761
|
return statement;
|
|
@@ -45838,7 +46345,7 @@ __export(sqliteIntrospect_exports, {
|
|
|
45838
46345
|
sqliteIntrospect: () => sqliteIntrospect,
|
|
45839
46346
|
sqlitePushIntrospect: () => sqlitePushIntrospect
|
|
45840
46347
|
});
|
|
45841
|
-
var
|
|
46348
|
+
var import_hanji7, SqliteClient, BetterSqlite, TursoSqlite, connectToSQLite, sqliteIntrospect, sqlitePushIntrospect;
|
|
45842
46349
|
var init_sqliteIntrospect = __esm({
|
|
45843
46350
|
"src/cli/commands/sqliteIntrospect.ts"() {
|
|
45844
46351
|
init_views();
|
|
@@ -45847,7 +46354,7 @@ var init_sqliteIntrospect = __esm({
|
|
|
45847
46354
|
init_sqlite_introspect();
|
|
45848
46355
|
init_mjs();
|
|
45849
46356
|
init_lib_esm2();
|
|
45850
|
-
|
|
46357
|
+
import_hanji7 = __toESM(require_hanji());
|
|
45851
46358
|
SqliteClient = class {
|
|
45852
46359
|
constructor(db) {
|
|
45853
46360
|
this.db = db;
|
|
@@ -45913,7 +46420,7 @@ var init_sqliteIntrospect = __esm({
|
|
|
45913
46420
|
return false;
|
|
45914
46421
|
};
|
|
45915
46422
|
const progress = new IntrospectProgress();
|
|
45916
|
-
const res = await (0,
|
|
46423
|
+
const res = await (0, import_hanji7.renderWithTask)(
|
|
45917
46424
|
progress,
|
|
45918
46425
|
fromDatabase3(
|
|
45919
46426
|
client,
|
|
@@ -50487,7 +50994,7 @@ var require_lib5 = __commonJS({
|
|
|
50487
50994
|
});
|
|
50488
50995
|
|
|
50489
50996
|
// src/introspect.ts
|
|
50490
|
-
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;
|
|
50491
50998
|
var init_introspect = __esm({
|
|
50492
50999
|
"src/introspect.ts"() {
|
|
50493
51000
|
init_utils3();
|
|
@@ -50630,9 +51137,13 @@ var init_introspect = __esm({
|
|
|
50630
51137
|
const pkImports = Object.values(it.compositePrimaryKeys).map(
|
|
50631
51138
|
(it2) => "primaryKey"
|
|
50632
51139
|
);
|
|
51140
|
+
const uniqueImports = Object.values(it.uniqueConstraints).map(
|
|
51141
|
+
(it2) => "unique"
|
|
51142
|
+
);
|
|
50633
51143
|
res.pg.push(...idxImports);
|
|
50634
51144
|
res.pg.push(...fkImpots);
|
|
50635
51145
|
res.pg.push(...pkImports);
|
|
51146
|
+
res.pg.push(...uniqueImports);
|
|
50636
51147
|
const columnImports = Object.values(it.columns).map((col) => {
|
|
50637
51148
|
let patched = importsPatch2[col.type] ?? col.type;
|
|
50638
51149
|
patched = patched.startsWith("varchar(") ? "varchar" : patched;
|
|
@@ -50676,7 +51187,7 @@ var init_introspect = __esm({
|
|
|
50676
51187
|
const filteredFKs = Object.values(table4.foreignKeys).filter((it) => {
|
|
50677
51188
|
return it.columnsFrom.length > 1 || isSelf3(it);
|
|
50678
51189
|
});
|
|
50679
|
-
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) {
|
|
50680
51191
|
statement += ",\n";
|
|
50681
51192
|
statement += "(table) => {\n";
|
|
50682
51193
|
statement += " return {\n";
|
|
@@ -50690,6 +51201,10 @@ var init_introspect = __esm({
|
|
|
50690
51201
|
Object.values(table4.compositePrimaryKeys),
|
|
50691
51202
|
casing
|
|
50692
51203
|
);
|
|
51204
|
+
statement += createTableUniques3(
|
|
51205
|
+
Object.values(table4.uniqueConstraints),
|
|
51206
|
+
casing
|
|
51207
|
+
);
|
|
50693
51208
|
statement += " }\n";
|
|
50694
51209
|
statement += "}";
|
|
50695
51210
|
}
|
|
@@ -50932,7 +51447,13 @@ var init_introspect = __esm({
|
|
|
50932
51447
|
return res;
|
|
50933
51448
|
}, {});
|
|
50934
51449
|
columns.forEach((it) => {
|
|
50935
|
-
const columnStatement = column6(
|
|
51450
|
+
const columnStatement = column6(
|
|
51451
|
+
it.type,
|
|
51452
|
+
it.name,
|
|
51453
|
+
enumTypes,
|
|
51454
|
+
it.default,
|
|
51455
|
+
casing
|
|
51456
|
+
);
|
|
50936
51457
|
statement += " ";
|
|
50937
51458
|
statement += columnStatement;
|
|
50938
51459
|
statement += dimensionsInArray(it.type);
|
|
@@ -50991,6 +51512,20 @@ var init_introspect = __esm({
|
|
|
50991
51512
|
}).join(", ")}`;
|
|
50992
51513
|
statement += ")";
|
|
50993
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 += `,
|
|
50994
51529
|
`;
|
|
50995
51530
|
});
|
|
50996
51531
|
return statement;
|
|
@@ -51022,10 +51557,10 @@ var pgIntrospect_exports = {};
|
|
|
51022
51557
|
__export(pgIntrospect_exports, {
|
|
51023
51558
|
pgIntrospect: () => pgIntrospect
|
|
51024
51559
|
});
|
|
51025
|
-
var
|
|
51560
|
+
var import_hanji8, import_pg, pgIntrospect;
|
|
51026
51561
|
var init_pgIntrospect = __esm({
|
|
51027
51562
|
"src/cli/commands/pgIntrospect.ts"() {
|
|
51028
|
-
|
|
51563
|
+
import_hanji8 = __toESM(require_hanji());
|
|
51029
51564
|
init_views();
|
|
51030
51565
|
import_pg = __toESM(require_lib5());
|
|
51031
51566
|
init_pgSerializer();
|
|
@@ -51048,7 +51583,7 @@ var init_pgIntrospect = __esm({
|
|
|
51048
51583
|
return false;
|
|
51049
51584
|
};
|
|
51050
51585
|
const progress = new IntrospectProgress();
|
|
51051
|
-
const res = await (0,
|
|
51586
|
+
const res = await (0, import_hanji8.renderWithTask)(
|
|
51052
51587
|
progress,
|
|
51053
51588
|
fromDatabase2(pool, filter2, (stage, count, status) => {
|
|
51054
51589
|
progress.update(stage, count, status);
|
|
@@ -51268,7 +51803,7 @@ var checkHandler = (out, dialect6) => {
|
|
|
51268
51803
|
};
|
|
51269
51804
|
|
|
51270
51805
|
// src/cli/index.ts
|
|
51271
|
-
var
|
|
51806
|
+
var import_hanji9 = __toESM(require_hanji());
|
|
51272
51807
|
var import_path7 = __toESM(require("path"));
|
|
51273
51808
|
|
|
51274
51809
|
// src/cli/utils.ts
|
|
@@ -51323,7 +51858,7 @@ init_source();
|
|
|
51323
51858
|
// package.json
|
|
51324
51859
|
var package_default = {
|
|
51325
51860
|
name: "drizzle-kit",
|
|
51326
|
-
version: "0.19.
|
|
51861
|
+
version: "0.19.4",
|
|
51327
51862
|
repository: "https://github.com/drizzle-team/drizzle-kit-mirror",
|
|
51328
51863
|
author: "Drizzle Team",
|
|
51329
51864
|
license: "MIT",
|
|
@@ -51402,7 +51937,7 @@ var package_default = {
|
|
|
51402
51937
|
"better-sqlite3": "^8.4.0",
|
|
51403
51938
|
dockerode: "^3.3.4",
|
|
51404
51939
|
dotenv: "^16.0.3",
|
|
51405
|
-
"drizzle-orm": "0.27.
|
|
51940
|
+
"drizzle-orm": "0.27.1-8a21e7b",
|
|
51406
51941
|
eslint: "^8.29.0",
|
|
51407
51942
|
"eslint-config-prettier": "^8.5.0",
|
|
51408
51943
|
"eslint-plugin-prettier": "^4.2.1",
|
|
@@ -51510,6 +52045,8 @@ init_utils();
|
|
|
51510
52045
|
|
|
51511
52046
|
// src/cli/commands/mysqlPushUtils.ts
|
|
51512
52047
|
init_source();
|
|
52048
|
+
var import_hanji5 = __toESM(require_hanji());
|
|
52049
|
+
init_mysqlSchema();
|
|
51513
52050
|
var filterStatements = (statements) => {
|
|
51514
52051
|
return statements.filter((statement) => {
|
|
51515
52052
|
if (statement.type === "alter_table_alter_column_set_type") {
|
|
@@ -51664,6 +52201,33 @@ var logSuggestionsAndReturn = async ({
|
|
|
51664
52201
|
shouldAskForApprove = true;
|
|
51665
52202
|
}
|
|
51666
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
|
+
}
|
|
51667
52231
|
}
|
|
51668
52232
|
}
|
|
51669
52233
|
return {
|
|
@@ -51900,7 +52464,7 @@ var logSuggestionsAndReturn2 = async ({
|
|
|
51900
52464
|
if (typeof tablesContext[fk4.tableFrom] === "undefined") {
|
|
51901
52465
|
tablesContext[fk4.tableFrom] = _moveDataStatements(fk4.tableFrom, json2);
|
|
51902
52466
|
}
|
|
51903
|
-
} 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") {
|
|
51904
52468
|
if (typeof tablesContext[statement.tableName] === "undefined") {
|
|
51905
52469
|
tablesContext[statement.tableName] = _moveDataStatements(
|
|
51906
52470
|
statement.tableName,
|
|
@@ -51998,14 +52562,14 @@ var generateMysqlCommand = new import_commander.Command("generate:mysql").option
|
|
|
51998
52562
|
const { prepareAndMigrateMySql: prepareAndMigrateMySql2 } = await Promise.resolve().then(() => (init_migrate(), migrate_exports));
|
|
51999
52563
|
await prepareAndMigrateMySql2(result);
|
|
52000
52564
|
});
|
|
52001
|
-
var Select = class extends
|
|
52565
|
+
var Select = class extends import_hanji9.Prompt {
|
|
52002
52566
|
// private readonly spinner: () => string;
|
|
52003
52567
|
// private timeout: NodeJS.Timer | undefined;
|
|
52004
52568
|
constructor(items) {
|
|
52005
52569
|
super();
|
|
52006
52570
|
this.on("attach", (terminal) => terminal.toggleCursor("hide"));
|
|
52007
52571
|
this.on("detach", (terminal) => terminal.toggleCursor("show"));
|
|
52008
|
-
this.data = new
|
|
52572
|
+
this.data = new import_hanji9.SelectState(
|
|
52009
52573
|
items.map((it) => ({ label: it, value: `${it}-value` }))
|
|
52010
52574
|
);
|
|
52011
52575
|
this.data.bind(this);
|
|
@@ -52040,7 +52604,7 @@ var dbPushMysqlCommand = new import_commander.Command("push:mysql").option(
|
|
|
52040
52604
|
);
|
|
52041
52605
|
const fileNames = prepareFilenames(drizzleConfig.schema);
|
|
52042
52606
|
if (fileNames.length === 0) {
|
|
52043
|
-
(0,
|
|
52607
|
+
(0, import_hanji9.render)(
|
|
52044
52608
|
`[${source_default.blue("i")}] No schema file in ${drizzleConfig.schema} was found`
|
|
52045
52609
|
);
|
|
52046
52610
|
process.exit(0);
|
|
@@ -52057,7 +52621,7 @@ var dbPushMysqlCommand = new import_commander.Command("push:mysql").option(
|
|
|
52057
52621
|
try {
|
|
52058
52622
|
if (typeof statements === "undefined") {
|
|
52059
52623
|
} else if (statements.sqlStatements.length === 0) {
|
|
52060
|
-
(0,
|
|
52624
|
+
(0, import_hanji9.render)(`[${source_default.blue("i")}] No changes detected`);
|
|
52061
52625
|
} else {
|
|
52062
52626
|
const filteredStatements = filterStatements(statements.statements);
|
|
52063
52627
|
const {
|
|
@@ -52085,11 +52649,11 @@ var dbPushMysqlCommand = new import_commander.Command("push:mysql").option(
|
|
|
52085
52649
|
}
|
|
52086
52650
|
if (drizzleConfig.strict) {
|
|
52087
52651
|
if (!shouldAskForApprove) {
|
|
52088
|
-
const { status, data } = await (0,
|
|
52652
|
+
const { status, data } = await (0, import_hanji9.render)(
|
|
52089
52653
|
new Select(["No, abort", `Yes, I want to execute all statements`])
|
|
52090
52654
|
);
|
|
52091
52655
|
if ((data == null ? void 0 : data.index) === 0) {
|
|
52092
|
-
(0,
|
|
52656
|
+
(0, import_hanji9.render)(`[${source_default.red("x")}] All changes were aborted`);
|
|
52093
52657
|
process.exit(0);
|
|
52094
52658
|
}
|
|
52095
52659
|
}
|
|
@@ -52104,14 +52668,14 @@ var dbPushMysqlCommand = new import_commander.Command("push:mysql").option(
|
|
|
52104
52668
|
)
|
|
52105
52669
|
);
|
|
52106
52670
|
console.log(source_default.white("Do you still want to push changes?"));
|
|
52107
|
-
const { status, data } = await (0,
|
|
52671
|
+
const { status, data } = await (0, import_hanji9.render)(
|
|
52108
52672
|
new Select([
|
|
52109
52673
|
"No, abort",
|
|
52110
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, "")
|
|
52111
52675
|
])
|
|
52112
52676
|
);
|
|
52113
52677
|
if ((data == null ? void 0 : data.index) === 0) {
|
|
52114
|
-
(0,
|
|
52678
|
+
(0, import_hanji9.render)(`[${source_default.red("x")}] All changes were aborted`);
|
|
52115
52679
|
process.exit(0);
|
|
52116
52680
|
}
|
|
52117
52681
|
}
|
|
@@ -52122,9 +52686,9 @@ var dbPushMysqlCommand = new import_commander.Command("push:mysql").option(
|
|
|
52122
52686
|
await connection.client.query(statement);
|
|
52123
52687
|
}
|
|
52124
52688
|
if (filteredStatements.length > 0) {
|
|
52125
|
-
(0,
|
|
52689
|
+
(0, import_hanji9.render)(`[${source_default.green("\u2713")}] Changes applied`);
|
|
52126
52690
|
} else {
|
|
52127
|
-
(0,
|
|
52691
|
+
(0, import_hanji9.render)(`[${source_default.blue("i")}] No changes detected`);
|
|
52128
52692
|
}
|
|
52129
52693
|
}
|
|
52130
52694
|
} catch (e) {
|
|
@@ -52144,7 +52708,7 @@ var dbPushSqliteCommand = new import_commander.Command("push:sqlite").option(
|
|
|
52144
52708
|
const res = await validatePush(options);
|
|
52145
52709
|
const fileNames = prepareFilenames(res.schema);
|
|
52146
52710
|
if (fileNames.length === 0) {
|
|
52147
|
-
(0,
|
|
52711
|
+
(0, import_hanji9.render)(`[${source_default.blue("i")}] No schema file in ${res.schema} was found`);
|
|
52148
52712
|
process.exit(0);
|
|
52149
52713
|
}
|
|
52150
52714
|
const connection = await connectToSQLite2(res);
|
|
@@ -52159,7 +52723,7 @@ var dbPushSqliteCommand = new import_commander.Command("push:sqlite").option(
|
|
|
52159
52723
|
try {
|
|
52160
52724
|
if (typeof statements === "undefined") {
|
|
52161
52725
|
} else if (statements.sqlStatements.length === 0) {
|
|
52162
|
-
(0,
|
|
52726
|
+
(0, import_hanji9.render)(`
|
|
52163
52727
|
[${source_default.blue("i")}] No changes detected`);
|
|
52164
52728
|
} else {
|
|
52165
52729
|
const {
|
|
@@ -52187,11 +52751,11 @@ var dbPushSqliteCommand = new import_commander.Command("push:sqlite").option(
|
|
|
52187
52751
|
}
|
|
52188
52752
|
if (res.strict) {
|
|
52189
52753
|
if (!shouldAskForApprove) {
|
|
52190
|
-
const { status, data } = await (0,
|
|
52754
|
+
const { status, data } = await (0, import_hanji9.render)(
|
|
52191
52755
|
new Select(["No, abort", `Yes, I want to execute all statements`])
|
|
52192
52756
|
);
|
|
52193
52757
|
if ((data == null ? void 0 : data.index) === 0) {
|
|
52194
|
-
(0,
|
|
52758
|
+
(0, import_hanji9.render)(`[${source_default.red("x")}] All changes were aborted`);
|
|
52195
52759
|
process.exit(0);
|
|
52196
52760
|
}
|
|
52197
52761
|
}
|
|
@@ -52206,21 +52770,21 @@ var dbPushSqliteCommand = new import_commander.Command("push:sqlite").option(
|
|
|
52206
52770
|
)
|
|
52207
52771
|
);
|
|
52208
52772
|
console.log(source_default.white("Do you still want to push changes?"));
|
|
52209
|
-
const { status, data } = await (0,
|
|
52773
|
+
const { status, data } = await (0, import_hanji9.render)(
|
|
52210
52774
|
new Select([
|
|
52211
52775
|
"No, abort",
|
|
52212
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, "")
|
|
52213
52777
|
])
|
|
52214
52778
|
);
|
|
52215
52779
|
if ((data == null ? void 0 : data.index) === 0) {
|
|
52216
|
-
(0,
|
|
52780
|
+
(0, import_hanji9.render)(`[${source_default.red("x")}] All changes were aborted`);
|
|
52217
52781
|
process.exit(0);
|
|
52218
52782
|
}
|
|
52219
52783
|
}
|
|
52220
52784
|
for (const dStmnt of statementsToExecute) {
|
|
52221
52785
|
await connection.client.run(dStmnt);
|
|
52222
52786
|
}
|
|
52223
|
-
(0,
|
|
52787
|
+
(0, import_hanji9.render)(`[${source_default.green("\u2713")}] Changes applied`);
|
|
52224
52788
|
}
|
|
52225
52789
|
} catch (e) {
|
|
52226
52790
|
console.log(e);
|
|
@@ -52389,13 +52953,13 @@ var introspectPgCommand = new import_commander.Command("introspect:pg").option("
|
|
|
52389
52953
|
"introspect"
|
|
52390
52954
|
);
|
|
52391
52955
|
} else {
|
|
52392
|
-
(0,
|
|
52956
|
+
(0, import_hanji9.render)(
|
|
52393
52957
|
`[${source_default.blue(
|
|
52394
52958
|
"i"
|
|
52395
52959
|
)}] No SQL generated, you already have migrations in project`
|
|
52396
52960
|
);
|
|
52397
52961
|
}
|
|
52398
|
-
(0,
|
|
52962
|
+
(0, import_hanji9.render)(
|
|
52399
52963
|
`[${source_default.green(
|
|
52400
52964
|
"\u2713"
|
|
52401
52965
|
)}] You schema file is ready \u279C ${source_default.bold.underline.blue(
|
|
@@ -52442,13 +53006,13 @@ var introspectMySqlCommand = new import_commander.Command("introspect:mysql").op
|
|
|
52442
53006
|
"introspect"
|
|
52443
53007
|
);
|
|
52444
53008
|
} else {
|
|
52445
|
-
(0,
|
|
53009
|
+
(0, import_hanji9.render)(
|
|
52446
53010
|
`[${source_default.blue(
|
|
52447
53011
|
"i"
|
|
52448
53012
|
)}] No SQL generated, you already have migrations in project`
|
|
52449
53013
|
);
|
|
52450
53014
|
}
|
|
52451
|
-
(0,
|
|
53015
|
+
(0, import_hanji9.render)(
|
|
52452
53016
|
`[${source_default.green(
|
|
52453
53017
|
"\u2713"
|
|
52454
53018
|
)}] You schema file is ready \u279C ${source_default.bold.underline.blue(
|
|
@@ -52495,13 +53059,13 @@ var introspectSQLiteCommand = new import_commander.Command("introspect:sqlite").
|
|
|
52495
53059
|
"introspect"
|
|
52496
53060
|
);
|
|
52497
53061
|
} else {
|
|
52498
|
-
(0,
|
|
53062
|
+
(0, import_hanji9.render)(
|
|
52499
53063
|
`[${source_default.blue(
|
|
52500
53064
|
"i"
|
|
52501
53065
|
)}] No SQL generated, you already have migrations in project`
|
|
52502
53066
|
);
|
|
52503
53067
|
}
|
|
52504
|
-
(0,
|
|
53068
|
+
(0, import_hanji9.render)(
|
|
52505
53069
|
`[${source_default.green(
|
|
52506
53070
|
"\u2713"
|
|
52507
53071
|
)}] You schema file is ready \u279C ${source_default.bold.underline.blue(
|