drizzle-kit 0.19.3-d338b71 → 0.19.4-2a2e18d
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 +491 -78
- package/package.json +2 -2
- package/utils.js +277 -40
package/index.cjs
CHANGED
|
@@ -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) => {
|
|
@@ -11356,12 +11429,14 @@ var init_mysqlSerializer = __esm({
|
|
|
11356
11429
|
indexes,
|
|
11357
11430
|
foreignKeys,
|
|
11358
11431
|
schema: schema4,
|
|
11359
|
-
primaryKeys
|
|
11432
|
+
primaryKeys,
|
|
11433
|
+
uniqueConstraints
|
|
11360
11434
|
} = (0, import_mysql_core3.getTableConfig)(table4);
|
|
11361
11435
|
const columnsObject = {};
|
|
11362
11436
|
const indexesObject = {};
|
|
11363
11437
|
const foreignKeysObject = {};
|
|
11364
11438
|
const primaryKeysObject = {};
|
|
11439
|
+
const uniqueConstraintObject = {};
|
|
11365
11440
|
columns.forEach((column7) => {
|
|
11366
11441
|
const notNull = column7.notNull;
|
|
11367
11442
|
const primaryKey = column7.primary;
|
|
@@ -11382,6 +11457,12 @@ var init_mysqlSerializer = __esm({
|
|
|
11382
11457
|
// ? column.hasOnUpdateNow
|
|
11383
11458
|
// : undefined,
|
|
11384
11459
|
};
|
|
11460
|
+
if (column7.isUnique) {
|
|
11461
|
+
uniqueConstraintObject[column7.uniqueName] = {
|
|
11462
|
+
name: column7.uniqueName,
|
|
11463
|
+
columns: [columnToSet.name]
|
|
11464
|
+
};
|
|
11465
|
+
}
|
|
11385
11466
|
if (column7.default !== void 0) {
|
|
11386
11467
|
if ((0, import_drizzle_orm2.is)(column7.default, import_drizzle_orm3.SQL)) {
|
|
11387
11468
|
columnToSet.default = sqlToStr(column7.default);
|
|
@@ -11418,6 +11499,14 @@ var init_mysqlSerializer = __esm({
|
|
|
11418
11499
|
columnsObject[column7.name].notNull = true;
|
|
11419
11500
|
}
|
|
11420
11501
|
});
|
|
11502
|
+
uniqueConstraints.map((unq) => {
|
|
11503
|
+
const columnNames = unq.columns.map((c) => c.name);
|
|
11504
|
+
const name = unq.name ?? (0, import_mysql_core2.uniqueKeyName)(table4, columnNames);
|
|
11505
|
+
uniqueConstraintObject[name] = {
|
|
11506
|
+
name: unq.name,
|
|
11507
|
+
columns: columnNames
|
|
11508
|
+
};
|
|
11509
|
+
});
|
|
11421
11510
|
const fks = foreignKeys.map((fk4) => {
|
|
11422
11511
|
const name = fk4.getName();
|
|
11423
11512
|
const tableFrom = tableName;
|
|
@@ -11466,7 +11555,8 @@ var init_mysqlSerializer = __esm({
|
|
|
11466
11555
|
columns: columnsObject,
|
|
11467
11556
|
indexes: indexesObject,
|
|
11468
11557
|
foreignKeys: foreignKeysObject,
|
|
11469
|
-
compositePrimaryKeys: primaryKeysObject
|
|
11558
|
+
compositePrimaryKeys: primaryKeysObject,
|
|
11559
|
+
uniqueConstraints: uniqueConstraintObject
|
|
11470
11560
|
};
|
|
11471
11561
|
}
|
|
11472
11562
|
const schemas = Object.fromEntries(
|
|
@@ -11544,7 +11634,7 @@ var init_mysqlSerializer = __esm({
|
|
|
11544
11634
|
onUpdate = true;
|
|
11545
11635
|
}
|
|
11546
11636
|
const newColumn = {
|
|
11547
|
-
default: columnDefault === null ? void 0 : /^-?[\d.]+(?:e-?\d+)?$/.test(columnDefault) ? Number(columnDefault) : isDefaultAnExpression ? clearDefaults(columnDefault, collation) : `'${columnDefault}'`,
|
|
11637
|
+
default: columnDefault === null ? void 0 : /^-?[\d.]+(?:e-?\d+)?$/.test(columnDefault) && !columnType.startsWith("decimal") ? Number(columnDefault) : isDefaultAnExpression ? clearDefaults(columnDefault, collation) : `'${columnDefault}'`,
|
|
11548
11638
|
autoincrement: isAutoincrement,
|
|
11549
11639
|
name: columnName,
|
|
11550
11640
|
type: changedType,
|
|
@@ -11561,7 +11651,8 @@ var init_mysqlSerializer = __esm({
|
|
|
11561
11651
|
},
|
|
11562
11652
|
compositePrimaryKeys: {},
|
|
11563
11653
|
indexes: {},
|
|
11564
|
-
foreignKeys: {}
|
|
11654
|
+
foreignKeys: {},
|
|
11655
|
+
uniqueConstraints: {}
|
|
11565
11656
|
};
|
|
11566
11657
|
} else {
|
|
11567
11658
|
result[tableName].columns[columnName] = newColumn;
|
|
@@ -11660,14 +11751,25 @@ var init_mysqlSerializer = __esm({
|
|
|
11660
11751
|
if (progressCallback) {
|
|
11661
11752
|
progressCallback("indexes", indexesCount, "fetching");
|
|
11662
11753
|
}
|
|
11663
|
-
if (
|
|
11664
|
-
tableInResult.
|
|
11754
|
+
if (isUnique) {
|
|
11755
|
+
if (typeof tableInResult.uniqueConstraints[constraintName] !== "undefined") {
|
|
11756
|
+
tableInResult.uniqueConstraints[constraintName].columns.push(columnName);
|
|
11757
|
+
} else {
|
|
11758
|
+
tableInResult.uniqueConstraints[constraintName] = {
|
|
11759
|
+
name: constraintName,
|
|
11760
|
+
columns: [columnName]
|
|
11761
|
+
};
|
|
11762
|
+
}
|
|
11665
11763
|
} else {
|
|
11666
|
-
tableInResult.indexes[constraintName]
|
|
11667
|
-
|
|
11668
|
-
|
|
11669
|
-
|
|
11670
|
-
|
|
11764
|
+
if (typeof tableInResult.indexes[constraintName] !== "undefined") {
|
|
11765
|
+
tableInResult.indexes[constraintName].columns.push(columnName);
|
|
11766
|
+
} else {
|
|
11767
|
+
tableInResult.indexes[constraintName] = {
|
|
11768
|
+
name: constraintName,
|
|
11769
|
+
columns: [columnName],
|
|
11770
|
+
isUnique
|
|
11771
|
+
};
|
|
11772
|
+
}
|
|
11671
11773
|
}
|
|
11672
11774
|
}
|
|
11673
11775
|
if (progressCallback) {
|
|
@@ -11758,12 +11860,14 @@ var init_pgSerializer = __esm({
|
|
|
11758
11860
|
foreignKeys,
|
|
11759
11861
|
checks,
|
|
11760
11862
|
schema: schema4,
|
|
11761
|
-
primaryKeys
|
|
11863
|
+
primaryKeys,
|
|
11864
|
+
uniqueConstraints
|
|
11762
11865
|
} = (0, import_pg_core3.getTableConfig)(table4);
|
|
11763
11866
|
const columnsObject = {};
|
|
11764
11867
|
const indexesObject = {};
|
|
11765
11868
|
const foreignKeysObject = {};
|
|
11766
11869
|
const primaryKeysObject = {};
|
|
11870
|
+
const uniqueConstraintObject = {};
|
|
11767
11871
|
columns.forEach((column7) => {
|
|
11768
11872
|
const notNull = column7.notNull;
|
|
11769
11873
|
const primaryKey = column7.primary;
|
|
@@ -11774,6 +11878,13 @@ var init_pgSerializer = __esm({
|
|
|
11774
11878
|
primaryKey,
|
|
11775
11879
|
notNull
|
|
11776
11880
|
};
|
|
11881
|
+
if (column7.isUnique) {
|
|
11882
|
+
uniqueConstraintObject[column7.uniqueName] = {
|
|
11883
|
+
name: column7.uniqueName,
|
|
11884
|
+
nullsNotDistinct: column7.uniqueType === "not distinct",
|
|
11885
|
+
columns: [columnToSet.name]
|
|
11886
|
+
};
|
|
11887
|
+
}
|
|
11777
11888
|
if (column7.default !== void 0) {
|
|
11778
11889
|
if ((0, import_drizzle_orm5.is)(column7.default, import_drizzle_orm5.SQL)) {
|
|
11779
11890
|
columnToSet.default = sqlToStr(column7.default);
|
|
@@ -11808,6 +11919,15 @@ var init_pgSerializer = __esm({
|
|
|
11808
11919
|
columns: columnNames
|
|
11809
11920
|
};
|
|
11810
11921
|
});
|
|
11922
|
+
uniqueConstraints.map((unq) => {
|
|
11923
|
+
const columnNames = unq.columns.map((c) => c.name);
|
|
11924
|
+
const name = unq.name ?? (0, import_pg_core2.uniqueKeyName)(table4, columnNames);
|
|
11925
|
+
uniqueConstraintObject[name] = {
|
|
11926
|
+
name: unq.name,
|
|
11927
|
+
nullsNotDistinct: unq.nullsNotDistinct,
|
|
11928
|
+
columns: columnNames
|
|
11929
|
+
};
|
|
11930
|
+
});
|
|
11811
11931
|
const fks = foreignKeys.map((fk4) => {
|
|
11812
11932
|
const name = fk4.getName();
|
|
11813
11933
|
const tableFrom = tableName;
|
|
@@ -11856,7 +11976,8 @@ var init_pgSerializer = __esm({
|
|
|
11856
11976
|
columns: columnsObject,
|
|
11857
11977
|
indexes: indexesObject,
|
|
11858
11978
|
foreignKeys: foreignKeysObject,
|
|
11859
|
-
compositePrimaryKeys: primaryKeysObject
|
|
11979
|
+
compositePrimaryKeys: primaryKeysObject,
|
|
11980
|
+
uniqueConstraints: uniqueConstraintObject
|
|
11860
11981
|
};
|
|
11861
11982
|
}
|
|
11862
11983
|
const enumsToReturn = enums.reduce((map, obj) => {
|
|
@@ -11916,6 +12037,7 @@ var init_pgSerializer = __esm({
|
|
|
11916
12037
|
const indexToReturn = {};
|
|
11917
12038
|
const foreignKeysToReturn = {};
|
|
11918
12039
|
const primaryKeys = {};
|
|
12040
|
+
const uniqueConstrains = {};
|
|
11919
12041
|
const tableResponse = await db.query(
|
|
11920
12042
|
`SELECT a.attrelid::regclass::text, a.attname, is_nullable, a.attndims as array_dimensions
|
|
11921
12043
|
, CASE WHEN a.atttypid = ANY ('{int,int8,int2}'::regtype[])
|
|
@@ -12009,6 +12131,22 @@ var init_pgSerializer = __esm({
|
|
|
12009
12131
|
...new Set(foreignKeysToReturn[foreignKeyName].columnsTo)
|
|
12010
12132
|
];
|
|
12011
12133
|
}
|
|
12134
|
+
const uniqueConstrainsRows = tableConstraints.rows.filter(
|
|
12135
|
+
(mapRow) => mapRow.constraint_type === "UNIQUE"
|
|
12136
|
+
);
|
|
12137
|
+
for (const unqs of uniqueConstrainsRows) {
|
|
12138
|
+
const columnName = unqs.column_name;
|
|
12139
|
+
const constraintName = unqs.constraint_name;
|
|
12140
|
+
if (typeof uniqueConstrains[constraintName] !== "undefined") {
|
|
12141
|
+
uniqueConstrains[constraintName].columns.push(columnName);
|
|
12142
|
+
} else {
|
|
12143
|
+
uniqueConstrains[constraintName] = {
|
|
12144
|
+
columns: [columnName],
|
|
12145
|
+
nullsNotDistinct: false,
|
|
12146
|
+
name: constraintName
|
|
12147
|
+
};
|
|
12148
|
+
}
|
|
12149
|
+
}
|
|
12012
12150
|
for (const columnResponse of tableResponse.rows) {
|
|
12013
12151
|
const columnName = columnResponse.attname;
|
|
12014
12152
|
const columnAdditionalDT = columnResponse.additional_dt;
|
|
@@ -12034,9 +12172,6 @@ var init_pgSerializer = __esm({
|
|
|
12034
12172
|
columns: cprimaryKey.map((c) => c.column_name)
|
|
12035
12173
|
};
|
|
12036
12174
|
}
|
|
12037
|
-
const uniqueKey = tableConstraints.rows.filter(
|
|
12038
|
-
(mapRow) => columnName === mapRow.column_name && mapRow.constraint_type === "UNIQUE"
|
|
12039
|
-
);
|
|
12040
12175
|
const defaultValue = defaultForColumn(columnResponse);
|
|
12041
12176
|
const isSerial = columnType === "serial";
|
|
12042
12177
|
let columnTypeMapped = columnType;
|
|
@@ -12084,10 +12219,25 @@ var init_pgSerializer = __esm({
|
|
|
12084
12219
|
t.relname,
|
|
12085
12220
|
i.relname;`
|
|
12086
12221
|
);
|
|
12222
|
+
const dbIndexFromConstraint = await db.query(
|
|
12223
|
+
`SELECT
|
|
12224
|
+
idx.indexrelname AS index_name,
|
|
12225
|
+
idx.relname AS table_name,
|
|
12226
|
+
con.conname,
|
|
12227
|
+
CASE WHEN con.conname IS NOT NULL THEN 1 ELSE 0 END AS generated_by_constraint
|
|
12228
|
+
FROM
|
|
12229
|
+
pg_stat_user_indexes idx
|
|
12230
|
+
LEFT JOIN
|
|
12231
|
+
pg_constraint con ON con.conindid = idx.indexrelid
|
|
12232
|
+
WHERE idx.relname = '${tableName}';`
|
|
12233
|
+
);
|
|
12234
|
+
const idxsInConsteraint = dbIndexFromConstraint.rows.filter((it) => it.generated_by_constraint === 1).map((it) => it.index_name);
|
|
12087
12235
|
for (const dbIndex of dbIndexes.rows) {
|
|
12088
12236
|
const indexName4 = dbIndex.index_name;
|
|
12089
12237
|
const indexColumnName = dbIndex.column_name;
|
|
12090
12238
|
const indexIsUnique = dbIndex.is_unique;
|
|
12239
|
+
if (idxsInConsteraint.includes(indexName4))
|
|
12240
|
+
continue;
|
|
12091
12241
|
if (typeof indexToReturn[indexName4] !== "undefined") {
|
|
12092
12242
|
indexToReturn[indexName4].columns.push(indexColumnName);
|
|
12093
12243
|
} else {
|
|
@@ -12108,7 +12258,8 @@ var init_pgSerializer = __esm({
|
|
|
12108
12258
|
columns: columnToReturn,
|
|
12109
12259
|
indexes: indexToReturn,
|
|
12110
12260
|
foreignKeys: foreignKeysToReturn,
|
|
12111
|
-
compositePrimaryKeys: primaryKeys
|
|
12261
|
+
compositePrimaryKeys: primaryKeys,
|
|
12262
|
+
uniqueConstraints: uniqueConstrains
|
|
12112
12263
|
};
|
|
12113
12264
|
} catch (e) {
|
|
12114
12265
|
rej(e);
|
|
@@ -12311,12 +12462,14 @@ var init_sqliteSerializer = __esm({
|
|
|
12311
12462
|
const indexesObject = {};
|
|
12312
12463
|
const foreignKeysObject = {};
|
|
12313
12464
|
const primaryKeysObject = {};
|
|
12465
|
+
const uniqueConstraintObject = {};
|
|
12314
12466
|
const {
|
|
12315
12467
|
name: tableName,
|
|
12316
12468
|
columns,
|
|
12317
12469
|
indexes,
|
|
12318
12470
|
foreignKeys: tableForeignKeys,
|
|
12319
|
-
primaryKeys
|
|
12471
|
+
primaryKeys,
|
|
12472
|
+
uniqueConstraints
|
|
12320
12473
|
} = (0, import_sqlite_core2.getTableConfig)(table4);
|
|
12321
12474
|
columns.forEach((column7) => {
|
|
12322
12475
|
const notNull = column7.notNull;
|
|
@@ -12336,6 +12489,13 @@ var init_sqliteSerializer = __esm({
|
|
|
12336
12489
|
}
|
|
12337
12490
|
}
|
|
12338
12491
|
columnsObject[column7.name] = columnToSet;
|
|
12492
|
+
if (column7.isUnique) {
|
|
12493
|
+
indexesObject[column7.uniqueName] = {
|
|
12494
|
+
name: column7.uniqueName,
|
|
12495
|
+
columns: [columnToSet.name],
|
|
12496
|
+
isUnique: true
|
|
12497
|
+
};
|
|
12498
|
+
}
|
|
12339
12499
|
});
|
|
12340
12500
|
const foreignKeys = tableForeignKeys.map((fk4) => {
|
|
12341
12501
|
const name = fk4.getName();
|
|
@@ -12383,6 +12543,15 @@ var init_sqliteSerializer = __esm({
|
|
|
12383
12543
|
where
|
|
12384
12544
|
};
|
|
12385
12545
|
});
|
|
12546
|
+
uniqueConstraints.map((unq) => {
|
|
12547
|
+
const columnNames = unq.columns.map((c) => c.name);
|
|
12548
|
+
const name = unq.name ?? (0, import_sqlite_core2.uniqueKeyName)(table4, columnNames);
|
|
12549
|
+
indexesObject[name] = {
|
|
12550
|
+
name: unq.name,
|
|
12551
|
+
columns: columnNames,
|
|
12552
|
+
isUnique: true
|
|
12553
|
+
};
|
|
12554
|
+
});
|
|
12386
12555
|
primaryKeys.forEach((it) => {
|
|
12387
12556
|
if (it.columns.length > 1) {
|
|
12388
12557
|
primaryKeysObject[it.getName()] = {
|
|
@@ -12397,7 +12566,8 @@ var init_sqliteSerializer = __esm({
|
|
|
12397
12566
|
columns: columnsObject,
|
|
12398
12567
|
indexes: indexesObject,
|
|
12399
12568
|
foreignKeys: foreignKeysObject,
|
|
12400
|
-
compositePrimaryKeys: primaryKeysObject
|
|
12569
|
+
compositePrimaryKeys: primaryKeysObject,
|
|
12570
|
+
uniqueConstraints: uniqueConstraintObject
|
|
12401
12571
|
};
|
|
12402
12572
|
}
|
|
12403
12573
|
return {
|
|
@@ -12481,7 +12651,8 @@ var init_sqliteSerializer = __esm({
|
|
|
12481
12651
|
},
|
|
12482
12652
|
compositePrimaryKeys: {},
|
|
12483
12653
|
indexes: {},
|
|
12484
|
-
foreignKeys: {}
|
|
12654
|
+
foreignKeys: {},
|
|
12655
|
+
uniqueConstraints: {}
|
|
12485
12656
|
};
|
|
12486
12657
|
} else {
|
|
12487
12658
|
result[tableName].columns[columnName] = newColumn;
|
|
@@ -12566,7 +12737,7 @@ FROM sqlite_master AS m,
|
|
|
12566
12737
|
pragma_index_list(m.name) AS il,
|
|
12567
12738
|
pragma_index_info(il.name) AS ii
|
|
12568
12739
|
WHERE
|
|
12569
|
-
m.type = 'table'
|
|
12740
|
+
m.type = 'table';`
|
|
12570
12741
|
);
|
|
12571
12742
|
for (const idxRow of idxs) {
|
|
12572
12743
|
const tableName = idxRow.tableName;
|
|
@@ -14537,7 +14708,7 @@ ${sql}
|
|
|
14537
14708
|
});
|
|
14538
14709
|
|
|
14539
14710
|
// 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;
|
|
14711
|
+
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
14712
|
var init_sqlgenerator = __esm({
|
|
14542
14713
|
"src/sqlgenerator.ts"() {
|
|
14543
14714
|
init_migrate();
|
|
@@ -14598,30 +14769,37 @@ var init_sqlgenerator = __esm({
|
|
|
14598
14769
|
return statement.type === "create_table" && dialect6 === "pg";
|
|
14599
14770
|
}
|
|
14600
14771
|
convert(st) {
|
|
14601
|
-
const { tableName, schema: schema4, columns, compositePKs } = st;
|
|
14772
|
+
const { tableName, schema: schema4, columns, compositePKs, uniqueConstraints } = st;
|
|
14602
14773
|
let statement = "";
|
|
14603
14774
|
const name = schema4 ? `"${schema4}"."${tableName}"` : `"${tableName}"`;
|
|
14604
14775
|
statement += `CREATE TABLE IF NOT EXISTS ${name} (
|
|
14605
14776
|
`;
|
|
14606
14777
|
for (let i = 0; i < columns.length; i++) {
|
|
14607
14778
|
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}` : "";
|
|
14779
|
+
const primaryKeyStatement = column7.primaryKey ? " PRIMARY KEY" : "";
|
|
14780
|
+
const notNullStatement = column7.notNull ? " NOT NULL" : "";
|
|
14781
|
+
const defaultStatement = column7.default !== void 0 ? ` DEFAULT ${column7.default}` : "";
|
|
14782
|
+
const uniqueConstraint4 = column7.isUnique ? ` CONSTRAINT ${column7.uniqueName} UNIQUE${column7.nullsNotDistinct ? " NULLS NOT DISTINCT" : ""}` : "";
|
|
14611
14783
|
const type = isPgNativeType(column7.type) ? column7.type : `"${column7.type}"`;
|
|
14612
|
-
statement +=
|
|
14613
|
-
statement +=
|
|
14784
|
+
statement += ` "${column7.name}" ${type}${primaryKeyStatement}${defaultStatement}${notNullStatement}${uniqueConstraint4}`;
|
|
14785
|
+
statement += i === columns.length - 1 ? "" : ",\n";
|
|
14614
14786
|
}
|
|
14615
|
-
statement += `);`;
|
|
14616
|
-
statement += `
|
|
14617
|
-
`;
|
|
14618
14787
|
if (typeof compositePKs !== "undefined" && compositePKs.length > 0) {
|
|
14788
|
+
statement += ",\n";
|
|
14619
14789
|
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
|
-
`;
|
|
14790
|
+
statement += ` CONSTRAINT ${st.compositePkName} PRIMARY KEY("${compositePK4.columns.join(`","`)}")`;
|
|
14624
14791
|
}
|
|
14792
|
+
if (typeof uniqueConstraints !== "undefined" && uniqueConstraints.length > 0) {
|
|
14793
|
+
for (const uniqueConstraint4 of uniqueConstraints) {
|
|
14794
|
+
statement += ",\n";
|
|
14795
|
+
const unsquashedUnique = PgSquasher.unsquashUnique(uniqueConstraint4);
|
|
14796
|
+
statement += ` CONSTRAINT ${unsquashedUnique.name} UNIQUE("${unsquashedUnique.columns.join(`","`)}")`;
|
|
14797
|
+
}
|
|
14798
|
+
}
|
|
14799
|
+
statement += `
|
|
14800
|
+
);`;
|
|
14801
|
+
statement += `
|
|
14802
|
+
`;
|
|
14625
14803
|
return statement;
|
|
14626
14804
|
}
|
|
14627
14805
|
};
|
|
@@ -14630,7 +14808,7 @@ var init_sqlgenerator = __esm({
|
|
|
14630
14808
|
return statement.type === "create_table" && dialect6 === "mysql";
|
|
14631
14809
|
}
|
|
14632
14810
|
convert(st) {
|
|
14633
|
-
const { tableName, columns, schema: schema4, compositePKs } = st;
|
|
14811
|
+
const { tableName, columns, schema: schema4, compositePKs, uniqueConstraints } = st;
|
|
14634
14812
|
let statement = "";
|
|
14635
14813
|
const tName = schema4 ? `\`${schema4}\`.\`${tableName}\`` : `\`${tableName}\``;
|
|
14636
14814
|
statement += `CREATE TABLE ${tName} (
|
|
@@ -14642,17 +14820,23 @@ var init_sqlgenerator = __esm({
|
|
|
14642
14820
|
const defaultStatement = column7.default !== void 0 ? ` DEFAULT ${column7.default}` : "";
|
|
14643
14821
|
const onUpdateStatement = column7.onUpdate ? ` ON UPDATE CURRENT_TIMESTAMP` : "";
|
|
14644
14822
|
const autoincrementStatement = column7.autoincrement ? " AUTO_INCREMENT" : "";
|
|
14645
|
-
statement +=
|
|
14823
|
+
statement += ` \`${column7.name}\` ${column7.type}${autoincrementStatement}${primaryKeyStatement}${notNullStatement}${defaultStatement}${onUpdateStatement}`;
|
|
14646
14824
|
statement += i === columns.length - 1 ? "" : ",\n";
|
|
14647
14825
|
}
|
|
14648
14826
|
if (typeof compositePKs !== "undefined" && compositePKs.length > 0) {
|
|
14649
14827
|
statement += ",\n";
|
|
14650
14828
|
const compositePK4 = MySqlSquasher.unsquashPK(compositePKs[0]);
|
|
14651
|
-
statement += ` PRIMARY KEY(
|
|
14652
|
-
statement += `
|
|
14653
|
-
`;
|
|
14829
|
+
statement += ` CONSTRAINT ${st.compositePkName} PRIMARY KEY("${compositePK4.columns.join(`","`)}")`;
|
|
14654
14830
|
}
|
|
14655
|
-
|
|
14831
|
+
if (typeof uniqueConstraints !== "undefined" && uniqueConstraints.length > 0) {
|
|
14832
|
+
for (const uniqueConstraint4 of uniqueConstraints) {
|
|
14833
|
+
statement += ",\n";
|
|
14834
|
+
const unsquashedUnique = MySqlSquasher.unsquashUnique(uniqueConstraint4);
|
|
14835
|
+
statement += ` CONSTRAINT ${unsquashedUnique.name} UNIQUE(\`${unsquashedUnique.columns.join(`\`,\``)}\`)`;
|
|
14836
|
+
}
|
|
14837
|
+
}
|
|
14838
|
+
statement += `
|
|
14839
|
+
);`;
|
|
14656
14840
|
statement += `
|
|
14657
14841
|
`;
|
|
14658
14842
|
return statement;
|
|
@@ -14663,7 +14847,13 @@ var init_sqlgenerator = __esm({
|
|
|
14663
14847
|
return statement.type === "sqlite_create_table" && dialect6 === "sqlite";
|
|
14664
14848
|
}
|
|
14665
14849
|
convert(st) {
|
|
14666
|
-
const {
|
|
14850
|
+
const {
|
|
14851
|
+
tableName,
|
|
14852
|
+
columns,
|
|
14853
|
+
referenceData,
|
|
14854
|
+
compositePKs,
|
|
14855
|
+
uniqueConstraints
|
|
14856
|
+
} = st;
|
|
14667
14857
|
let statement = "";
|
|
14668
14858
|
statement += `CREATE TABLE \`${tableName}\` (`;
|
|
14669
14859
|
for (let i = 0; i < columns.length; i++) {
|
|
@@ -14695,11 +14885,17 @@ var init_sqlgenerator = __esm({
|
|
|
14695
14885
|
const onUpdateStatement = onUpdate ? ` ON UPDATE ${onUpdate}` : "";
|
|
14696
14886
|
const fromColumnsString = columnsFrom.map((it) => `\`${it}\``).join(",");
|
|
14697
14887
|
const toColumnsString = columnsTo.map((it) => `\`${it}\``).join(",");
|
|
14888
|
+
statement += ",";
|
|
14698
14889
|
statement += "\n ";
|
|
14699
14890
|
statement += `FOREIGN KEY (${fromColumnsString}) REFERENCES \`${tableTo}\`(${toColumnsString})${onUpdateStatement}${onDeleteStatement}`;
|
|
14700
|
-
statement += ",";
|
|
14701
14891
|
}
|
|
14702
|
-
|
|
14892
|
+
if (typeof uniqueConstraints !== "undefined" && uniqueConstraints.length > 0) {
|
|
14893
|
+
for (const uniqueConstraint4 of uniqueConstraints) {
|
|
14894
|
+
statement += ",\n";
|
|
14895
|
+
const unsquashedUnique = MySqlSquasher.unsquashUnique(uniqueConstraint4);
|
|
14896
|
+
statement += ` CONSTRAINT ${unsquashedUnique.name} UNIQUE(\`${unsquashedUnique.columns.join(`\`,\``)}\`)`;
|
|
14897
|
+
}
|
|
14898
|
+
}
|
|
14703
14899
|
statement += `
|
|
14704
14900
|
`;
|
|
14705
14901
|
statement += `);`;
|
|
@@ -14708,6 +14904,72 @@ var init_sqlgenerator = __esm({
|
|
|
14708
14904
|
return statement;
|
|
14709
14905
|
}
|
|
14710
14906
|
};
|
|
14907
|
+
PgAlterTableAddUniqueConstraintConvertor = class extends Convertor {
|
|
14908
|
+
can(statement, dialect6) {
|
|
14909
|
+
return statement.type === "create_unique_constraint" && dialect6 === "pg";
|
|
14910
|
+
}
|
|
14911
|
+
convert(statement) {
|
|
14912
|
+
const unsquashed = PgSquasher.unsquashUnique(statement.data);
|
|
14913
|
+
const tableNameWithSchema = statement.schema ? `"${statement.schema}"."${statement.tableName}"` : `"${statement.tableName}"`;
|
|
14914
|
+
return `ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT "${unsquashed.name}" UNIQUE("${unsquashed.columns.join('","')}");`;
|
|
14915
|
+
}
|
|
14916
|
+
};
|
|
14917
|
+
PgAlterTableDropUniqueConstraintConvertor = class extends Convertor {
|
|
14918
|
+
can(statement, dialect6) {
|
|
14919
|
+
return statement.type === "delete_unique_constraint" && dialect6 === "pg";
|
|
14920
|
+
}
|
|
14921
|
+
convert(statement) {
|
|
14922
|
+
const unsquashed = PgSquasher.unsquashUnique(statement.data);
|
|
14923
|
+
const tableNameWithSchema = statement.schema ? `"${statement.schema}"."${statement.tableName}"` : `"${statement.tableName}"`;
|
|
14924
|
+
return `ALTER TABLE ${tableNameWithSchema} DROP CONSTRAINT "${unsquashed.name}";`;
|
|
14925
|
+
}
|
|
14926
|
+
};
|
|
14927
|
+
MySQLAlterTableAddUniqueConstraintConvertor = class extends Convertor {
|
|
14928
|
+
can(statement, dialect6) {
|
|
14929
|
+
return statement.type === "create_unique_constraint" && dialect6 === "mysql";
|
|
14930
|
+
}
|
|
14931
|
+
convert(statement) {
|
|
14932
|
+
const unsquashed = MySqlSquasher.unsquashUnique(statement.data);
|
|
14933
|
+
const tableNameWithSchema = statement.schema ? `\`${statement.schema}\`.\`${statement.tableName}\`` : `\`${statement.tableName}\``;
|
|
14934
|
+
return `ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT \`${unsquashed.name}\` UNIQUE(\`${unsquashed.columns.join("`,`")}\`);`;
|
|
14935
|
+
}
|
|
14936
|
+
};
|
|
14937
|
+
MySQLAlterTableDropUniqueConstraintConvertor = class extends Convertor {
|
|
14938
|
+
can(statement, dialect6) {
|
|
14939
|
+
return statement.type === "delete_unique_constraint" && dialect6 === "mysql";
|
|
14940
|
+
}
|
|
14941
|
+
convert(statement) {
|
|
14942
|
+
const unsquashed = MySqlSquasher.unsquashUnique(statement.data);
|
|
14943
|
+
const tableNameWithSchema = statement.schema ? `\`${statement.schema}\`.\`${statement.tableName}\`` : `\`${statement.tableName}\``;
|
|
14944
|
+
return `ALTER TABLE ${tableNameWithSchema} DROP CONSTRAINT \`${unsquashed.name}\`;`;
|
|
14945
|
+
}
|
|
14946
|
+
};
|
|
14947
|
+
SQLiteAlterTableAddUniqueConstraintConvertor = class extends Convertor {
|
|
14948
|
+
can(statement, dialect6) {
|
|
14949
|
+
return statement.type === "create_unique_constraint" && dialect6 === "sqlite";
|
|
14950
|
+
}
|
|
14951
|
+
convert(statement) {
|
|
14952
|
+
return `/*
|
|
14953
|
+
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
|
|
14954
|
+
Please refer to: https://www.techonthenet.com/sqlite/unique.php
|
|
14955
|
+
|
|
14956
|
+
Due to that we don't generate migration automatically and it has to be done manually
|
|
14957
|
+
*/`;
|
|
14958
|
+
}
|
|
14959
|
+
};
|
|
14960
|
+
SQLiteAlterTableDropUniqueConstraintConvertor = class extends Convertor {
|
|
14961
|
+
can(statement, dialect6) {
|
|
14962
|
+
return statement.type === "delete_unique_constraint" && dialect6 === "sqlite";
|
|
14963
|
+
}
|
|
14964
|
+
convert(statement) {
|
|
14965
|
+
return `/*
|
|
14966
|
+
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
|
|
14967
|
+
Please refer to: https://www.techonthenet.com/sqlite/unique.php
|
|
14968
|
+
|
|
14969
|
+
Due to that we don't generate migration automatically and it has to be done manually
|
|
14970
|
+
*/`;
|
|
14971
|
+
}
|
|
14972
|
+
};
|
|
14711
14973
|
CreateTypeEnumConvertor = class extends Convertor {
|
|
14712
14974
|
can(statement) {
|
|
14713
14975
|
return statement.type === "create_type_enum";
|
|
@@ -15663,6 +15925,10 @@ ${BREAKPOINT}ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT ${statement.newCo
|
|
|
15663
15925
|
convertors.push(new MySqlAlterTableAddColumnConvertor());
|
|
15664
15926
|
convertors.push(new SQLiteAlterTableAddColumnConvertor());
|
|
15665
15927
|
convertors.push(new PgAlterTableAlterColumnSetTypeConvertor());
|
|
15928
|
+
convertors.push(new PgAlterTableAddUniqueConstraintConvertor());
|
|
15929
|
+
convertors.push(new PgAlterTableDropUniqueConstraintConvertor());
|
|
15930
|
+
convertors.push(new MySQLAlterTableAddUniqueConstraintConvertor());
|
|
15931
|
+
convertors.push(new MySQLAlterTableDropUniqueConstraintConvertor());
|
|
15666
15932
|
convertors.push(new CreatePgIndexConvertor());
|
|
15667
15933
|
convertors.push(new CreateMySqlIndexConvertor());
|
|
15668
15934
|
convertors.push(new CreateSqliteIndexConvertor());
|
|
@@ -15697,6 +15963,8 @@ ${BREAKPOINT}ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT ${statement.newCo
|
|
|
15697
15963
|
convertors.push(new SqliteAlterForeignKeyConvertor());
|
|
15698
15964
|
convertors.push(new SqliteDeleteForeignKeyConvertor());
|
|
15699
15965
|
convertors.push(new SqliteCreateForeignKeyConvertor());
|
|
15966
|
+
convertors.push(new SQLiteAlterTableAddUniqueConstraintConvertor());
|
|
15967
|
+
convertors.push(new SQLiteAlterTableDropUniqueConstraintConvertor());
|
|
15700
15968
|
convertors.push(new SqliteAlterTableAlterColumnSetNotNullConvertor());
|
|
15701
15969
|
convertors.push(new SqliteAlterTableAlterColumnDropNotNullConvertor());
|
|
15702
15970
|
convertors.push(new SqliteAlterTableAlterColumnSetDefaultConvertor());
|
|
@@ -15755,14 +16023,14 @@ drop type __venum;
|
|
|
15755
16023
|
});
|
|
15756
16024
|
|
|
15757
16025
|
// 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;
|
|
16026
|
+
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
16027
|
var init_jsonStatements = __esm({
|
|
15760
16028
|
"src/jsonStatements.ts"() {
|
|
15761
16029
|
init_mysqlSchema();
|
|
15762
16030
|
init_pgSchema();
|
|
15763
16031
|
init_sqliteSchema();
|
|
15764
16032
|
preparePgCreateTableJson = (table4, json2) => {
|
|
15765
|
-
const { name, schema: schema4, columns, compositePrimaryKeys } = table4;
|
|
16033
|
+
const { name, schema: schema4, columns, compositePrimaryKeys, uniqueConstraints } = table4;
|
|
15766
16034
|
return {
|
|
15767
16035
|
type: "create_table",
|
|
15768
16036
|
tableName: name,
|
|
@@ -15771,11 +16039,12 @@ var init_jsonStatements = __esm({
|
|
|
15771
16039
|
compositePKs: Object.values(compositePrimaryKeys),
|
|
15772
16040
|
compositePkName: Object.values(compositePrimaryKeys).length > 0 ? json2.tables[name].compositePrimaryKeys[`${name}_${PgSquasher.unsquashPK(
|
|
15773
16041
|
Object.values(compositePrimaryKeys)[0]
|
|
15774
|
-
).columns.join("_")}`].name : ""
|
|
16042
|
+
).columns.join("_")}`].name : "",
|
|
16043
|
+
uniqueConstraints: Object.values(uniqueConstraints)
|
|
15775
16044
|
};
|
|
15776
16045
|
};
|
|
15777
16046
|
prepareMySqlCreateTableJson = (table4, json2) => {
|
|
15778
|
-
const { name, schema: schema4, columns, compositePrimaryKeys } = table4;
|
|
16047
|
+
const { name, schema: schema4, columns, compositePrimaryKeys, uniqueConstraints } = table4;
|
|
15779
16048
|
return {
|
|
15780
16049
|
type: "create_table",
|
|
15781
16050
|
tableName: name,
|
|
@@ -15784,11 +16053,12 @@ var init_jsonStatements = __esm({
|
|
|
15784
16053
|
compositePKs: Object.values(compositePrimaryKeys),
|
|
15785
16054
|
compositePkName: Object.values(compositePrimaryKeys).length > 0 ? json2.tables[name].compositePrimaryKeys[`${name}_${MySqlSquasher.unsquashPK(
|
|
15786
16055
|
Object.values(compositePrimaryKeys)[0]
|
|
15787
|
-
).columns.join("_")}`].name : ""
|
|
16056
|
+
).columns.join("_")}`].name : "",
|
|
16057
|
+
uniqueConstraints: Object.values(uniqueConstraints)
|
|
15788
16058
|
};
|
|
15789
16059
|
};
|
|
15790
16060
|
prepareSQLiteCreateTable = (table4) => {
|
|
15791
|
-
const { name, columns } = table4;
|
|
16061
|
+
const { name, columns, uniqueConstraints } = table4;
|
|
15792
16062
|
const references2 = Object.values(table4.foreignKeys);
|
|
15793
16063
|
const composites = Object.values(table4.compositePrimaryKeys).map(
|
|
15794
16064
|
(it) => SQLiteSquasher.unsquashPK(it)
|
|
@@ -15798,7 +16068,8 @@ var init_jsonStatements = __esm({
|
|
|
15798
16068
|
tableName: name,
|
|
15799
16069
|
columns: Object.values(columns),
|
|
15800
16070
|
referenceData: references2,
|
|
15801
|
-
compositePKs: composites
|
|
16071
|
+
compositePKs: composites,
|
|
16072
|
+
uniqueConstraints: Object.values(uniqueConstraints)
|
|
15802
16073
|
};
|
|
15803
16074
|
};
|
|
15804
16075
|
prepareDropTableJson = (table4) => {
|
|
@@ -16269,6 +16540,26 @@ var init_jsonStatements = __esm({
|
|
|
16269
16540
|
};
|
|
16270
16541
|
});
|
|
16271
16542
|
};
|
|
16543
|
+
prepareAddUniqueConstraintPg = (tableName, schema4, unqs) => {
|
|
16544
|
+
return Object.values(unqs).map((it) => {
|
|
16545
|
+
return {
|
|
16546
|
+
type: "create_unique_constraint",
|
|
16547
|
+
tableName,
|
|
16548
|
+
data: it,
|
|
16549
|
+
schema: schema4
|
|
16550
|
+
};
|
|
16551
|
+
});
|
|
16552
|
+
};
|
|
16553
|
+
prepareDeleteUniqueConstraintPg = (tableName, schema4, unqs) => {
|
|
16554
|
+
return Object.values(unqs).map((it) => {
|
|
16555
|
+
return {
|
|
16556
|
+
type: "delete_unique_constraint",
|
|
16557
|
+
tableName,
|
|
16558
|
+
data: it,
|
|
16559
|
+
schema: schema4
|
|
16560
|
+
};
|
|
16561
|
+
});
|
|
16562
|
+
};
|
|
16272
16563
|
prepareAddCompositePrimaryKeyMySql = (tableName, pks, json2) => {
|
|
16273
16564
|
return Object.values(pks).map((it) => {
|
|
16274
16565
|
return {
|
|
@@ -16386,12 +16677,14 @@ var init_snapshotsDiffer = __esm({
|
|
|
16386
16677
|
name: stringType(),
|
|
16387
16678
|
type: stringType(),
|
|
16388
16679
|
primaryKey: booleanType().optional(),
|
|
16389
|
-
unique: booleanType().optional(),
|
|
16390
16680
|
default: anyType().optional(),
|
|
16391
16681
|
notNull: booleanType().optional(),
|
|
16392
16682
|
// should it be optional? should if be here?
|
|
16393
16683
|
autoincrement: booleanType().optional(),
|
|
16394
|
-
onUpdate: booleanType().optional()
|
|
16684
|
+
onUpdate: booleanType().optional(),
|
|
16685
|
+
isUnique: anyType().optional(),
|
|
16686
|
+
uniqueName: stringType().optional(),
|
|
16687
|
+
nullsNotDistinct: booleanType().optional()
|
|
16395
16688
|
}).strict();
|
|
16396
16689
|
alteredColumnSchema = objectType({
|
|
16397
16690
|
name: makeSelfOrChanged(stringType()),
|
|
@@ -16417,7 +16710,8 @@ var init_snapshotsDiffer = __esm({
|
|
|
16417
16710
|
columns: recordType(stringType(), columnSchema),
|
|
16418
16711
|
indexes: recordType(stringType(), stringType()),
|
|
16419
16712
|
foreignKeys: recordType(stringType(), stringType()),
|
|
16420
|
-
compositePrimaryKeys: recordType(stringType(), stringType()).default({})
|
|
16713
|
+
compositePrimaryKeys: recordType(stringType(), stringType()).default({}),
|
|
16714
|
+
uniqueConstraints: recordType(stringType(), stringType()).default({})
|
|
16421
16715
|
}).strict();
|
|
16422
16716
|
alteredTableScheme = objectType({
|
|
16423
16717
|
name: stringType(),
|
|
@@ -16451,6 +16745,15 @@ var init_snapshotsDiffer = __esm({
|
|
|
16451
16745
|
__new: stringType(),
|
|
16452
16746
|
__old: stringType()
|
|
16453
16747
|
})
|
|
16748
|
+
),
|
|
16749
|
+
addedUniqueConstraints: recordType(stringType(), stringType()),
|
|
16750
|
+
deletedUniqueConstraints: recordType(stringType(), stringType()),
|
|
16751
|
+
alteredUniqueConstraints: recordType(
|
|
16752
|
+
stringType(),
|
|
16753
|
+
objectType({
|
|
16754
|
+
__new: stringType(),
|
|
16755
|
+
__old: stringType()
|
|
16756
|
+
})
|
|
16454
16757
|
)
|
|
16455
16758
|
}).strict();
|
|
16456
16759
|
diffResultScheme = objectType({
|
|
@@ -16540,13 +16843,19 @@ var init_snapshotsDiffer = __esm({
|
|
|
16540
16843
|
alteredForeignKeys: table4.alteredForeignKeys,
|
|
16541
16844
|
addedCompositePKs: table4.addedCompositePKs,
|
|
16542
16845
|
deletedCompositePKs: table4.deletedCompositePKs,
|
|
16543
|
-
alteredCompositePKs: table4.alteredCompositePKs
|
|
16846
|
+
alteredCompositePKs: table4.alteredCompositePKs,
|
|
16847
|
+
addedUniqueConstraints: table4.addedUniqueConstraints,
|
|
16848
|
+
deletedUniqueConstraints: table4.deletedUniqueConstraints,
|
|
16849
|
+
alteredUniqueConstraints: table4.alteredUniqueConstraints
|
|
16544
16850
|
};
|
|
16545
16851
|
allAlteredResolved.push(resolved);
|
|
16546
16852
|
}
|
|
16547
16853
|
const jsonAddedCompositePKs = [];
|
|
16548
16854
|
const jsonDeletedCompositePKs = [];
|
|
16549
16855
|
const jsonAlteredCompositePKs = [];
|
|
16856
|
+
const jsonAddedUniqueConstraints = [];
|
|
16857
|
+
const jsonDeletedUniqueConstraints = [];
|
|
16858
|
+
const jsonAlteredUniqueConstraints = [];
|
|
16550
16859
|
const jsonSetTableSchemas = [];
|
|
16551
16860
|
const jsonRemoveTableFromSchemas = [];
|
|
16552
16861
|
const jsonSetNewTableSchemas = [];
|
|
@@ -16638,6 +16947,33 @@ var init_snapshotsDiffer = __esm({
|
|
|
16638
16947
|
curFull
|
|
16639
16948
|
);
|
|
16640
16949
|
}
|
|
16950
|
+
let addedUniqueConstraints = [];
|
|
16951
|
+
let deletedUniqueConstraints = [];
|
|
16952
|
+
let alteredUniqueConstraints = [];
|
|
16953
|
+
addedUniqueConstraints = prepareAddUniqueConstraintPg(
|
|
16954
|
+
it.name,
|
|
16955
|
+
schemaUnwrapped,
|
|
16956
|
+
it.addedUniqueConstraints
|
|
16957
|
+
);
|
|
16958
|
+
deletedUniqueConstraints = prepareDeleteUniqueConstraintPg(
|
|
16959
|
+
it.name,
|
|
16960
|
+
schemaUnwrapped,
|
|
16961
|
+
it.deletedUniqueConstraints
|
|
16962
|
+
);
|
|
16963
|
+
if (it.alteredUniqueConstraints) {
|
|
16964
|
+
const added = {};
|
|
16965
|
+
const deleted2 = {};
|
|
16966
|
+
for (const k of Object.keys(it.alteredUniqueConstraints)) {
|
|
16967
|
+
added[k] = it.alteredUniqueConstraints[k].__new;
|
|
16968
|
+
deleted2[k] = it.alteredUniqueConstraints[k].__old;
|
|
16969
|
+
}
|
|
16970
|
+
addedUniqueConstraints.push(
|
|
16971
|
+
...prepareAddUniqueConstraintPg(it.name, schemaUnwrapped, added)
|
|
16972
|
+
);
|
|
16973
|
+
deletedUniqueConstraints.push(
|
|
16974
|
+
...prepareDeleteUniqueConstraintPg(it.name, schemaUnwrapped, deleted2)
|
|
16975
|
+
);
|
|
16976
|
+
}
|
|
16641
16977
|
if (it.schema && typeof it.schema !== "string") {
|
|
16642
16978
|
switch (it.schema.type) {
|
|
16643
16979
|
case "added": {
|
|
@@ -16670,6 +17006,9 @@ var init_snapshotsDiffer = __esm({
|
|
|
16670
17006
|
jsonAddedCompositePKs.push(...addedCompositePKs);
|
|
16671
17007
|
jsonDeletedCompositePKs.push(...deletedCompositePKs);
|
|
16672
17008
|
jsonAlteredCompositePKs.push(...alteredCompositePKs);
|
|
17009
|
+
jsonAddedUniqueConstraints.push(...addedUniqueConstraints);
|
|
17010
|
+
jsonDeletedUniqueConstraints.push(...deletedUniqueConstraints);
|
|
17011
|
+
jsonAlteredUniqueConstraints.push(...alteredUniqueConstraints);
|
|
16673
17012
|
});
|
|
16674
17013
|
const rColumns = jsonRenameColumnsStatements.map((it) => {
|
|
16675
17014
|
const tableName = it.tableName;
|
|
@@ -16794,6 +17133,7 @@ var init_snapshotsDiffer = __esm({
|
|
|
16794
17133
|
jsonStatements.push(...jsonSQLiteCreateTables);
|
|
16795
17134
|
} else if (dialect6 === "pg") {
|
|
16796
17135
|
const jsonPgCreateTables = created.map((it) => {
|
|
17136
|
+
console.log(it);
|
|
16797
17137
|
return preparePgCreateTableJson(it, curFull);
|
|
16798
17138
|
});
|
|
16799
17139
|
jsonStatements.push(...jsonPgCreateTables);
|
|
@@ -16807,6 +17147,7 @@ var init_snapshotsDiffer = __esm({
|
|
|
16807
17147
|
jsonStatements.push(...jsonRenameTables);
|
|
16808
17148
|
jsonStatements.push(...jsonRenameColumnsStatements);
|
|
16809
17149
|
jsonStatements.push(...jsonDeletedCompositePKs);
|
|
17150
|
+
jsonStatements.push(...jsonDeletedUniqueConstraints);
|
|
16810
17151
|
jsonStatements.push(...jsonDroppedReferencesForAlteredTables);
|
|
16811
17152
|
jsonStatements.push(...jsonDropIndexesForAllAlteredTables);
|
|
16812
17153
|
jsonStatements.push(...jsonTableAlternations.alterColumns);
|
|
@@ -16819,6 +17160,8 @@ var init_snapshotsDiffer = __esm({
|
|
|
16819
17160
|
jsonStatements.push(...jsonCreateReferences);
|
|
16820
17161
|
jsonStatements.push(...jsonAddedCompositePKs);
|
|
16821
17162
|
jsonStatements.push(...jsonAlteredCompositePKs);
|
|
17163
|
+
jsonStatements.push(...jsonAddedUniqueConstraints);
|
|
17164
|
+
jsonStatements.push(...jsonAlteredUniqueConstraints);
|
|
16822
17165
|
jsonStatements.push(...jsonSetTableSchemas);
|
|
16823
17166
|
jsonStatements.push(...filteredJsonSetNewTableSchemas);
|
|
16824
17167
|
jsonStatements.push(...jsonRemoveTableFromSchemas);
|
|
@@ -35139,7 +35482,7 @@ var require_promise = __commonJS({
|
|
|
35139
35482
|
});
|
|
35140
35483
|
|
|
35141
35484
|
// src/mysql-introspect.ts
|
|
35142
|
-
var mysqlImportsList, objToStatement2, timeConfig, binaryConfig, importsPatch, relations, withCasing, schemaToTypeScript, isCyclic, isSelf, mapColumnDefault, mapColumnDefaultForJson, column4, createTableColumns, createTableIndexes, createTablePKs, createTableFKs;
|
|
35485
|
+
var mysqlImportsList, objToStatement2, timeConfig, binaryConfig, importsPatch, relations, withCasing, schemaToTypeScript, isCyclic, isSelf, mapColumnDefault, mapColumnDefaultForJson, column4, createTableColumns, createTableIndexes, createTableUniques, createTablePKs, createTableFKs;
|
|
35143
35486
|
var init_mysql_introspect = __esm({
|
|
35144
35487
|
"src/mysql-introspect.ts"() {
|
|
35145
35488
|
init_utils3();
|
|
@@ -35239,9 +35582,13 @@ var init_mysql_introspect = __esm({
|
|
|
35239
35582
|
const pkImports = Object.values(it.compositePrimaryKeys).map(
|
|
35240
35583
|
(it2) => "primaryKey"
|
|
35241
35584
|
);
|
|
35585
|
+
const uniqueImports = Object.values(it.uniqueConstraints).map(
|
|
35586
|
+
(it2) => "unique"
|
|
35587
|
+
);
|
|
35242
35588
|
res.mysql.push(...idxImports);
|
|
35243
35589
|
res.mysql.push(...fkImpots);
|
|
35244
35590
|
res.mysql.push(...pkImports);
|
|
35591
|
+
res.mysql.push(...uniqueImports);
|
|
35245
35592
|
const columnImports = Object.values(it.columns).map((col) => {
|
|
35246
35593
|
let patched = importsPatch[col.type] ?? col.type;
|
|
35247
35594
|
patched = patched.startsWith("varchar(") ? "varchar" : patched;
|
|
@@ -35288,7 +35635,7 @@ var init_mysql_introspect = __esm({
|
|
|
35288
35635
|
const filteredFKs = Object.values(table4.foreignKeys).filter((it) => {
|
|
35289
35636
|
return it.columnsFrom.length > 1 || isSelf(it);
|
|
35290
35637
|
});
|
|
35291
|
-
if (Object.keys(table4.indexes).length > 0 || filteredFKs.length > 0 || Object.keys(table4.compositePrimaryKeys).length > 0) {
|
|
35638
|
+
if (Object.keys(table4.indexes).length > 0 || filteredFKs.length > 0 || Object.keys(table4.compositePrimaryKeys).length > 0 || Object.keys(table4.uniqueConstraints).length > 0) {
|
|
35292
35639
|
statement += ",\n";
|
|
35293
35640
|
statement += "(table) => {\n";
|
|
35294
35641
|
statement += " return {\n";
|
|
@@ -35302,6 +35649,10 @@ var init_mysql_introspect = __esm({
|
|
|
35302
35649
|
Object.values(table4.compositePrimaryKeys),
|
|
35303
35650
|
casing
|
|
35304
35651
|
);
|
|
35652
|
+
statement += createTableUniques(
|
|
35653
|
+
Object.values(table4.uniqueConstraints),
|
|
35654
|
+
casing
|
|
35655
|
+
);
|
|
35305
35656
|
statement += " }\n";
|
|
35306
35657
|
statement += "}";
|
|
35307
35658
|
}
|
|
@@ -35612,6 +35963,19 @@ import { sql } from "drizzle-orm"
|
|
|
35612
35963
|
statement += `${escapedIndexName})`;
|
|
35613
35964
|
statement += `.on(${it.columns.map((it2) => `table.${withCasing(it2, casing)}`).join(", ")}),`;
|
|
35614
35965
|
statement += `
|
|
35966
|
+
`;
|
|
35967
|
+
});
|
|
35968
|
+
return statement;
|
|
35969
|
+
};
|
|
35970
|
+
createTableUniques = (unqs, casing) => {
|
|
35971
|
+
let statement = "";
|
|
35972
|
+
unqs.forEach((it) => {
|
|
35973
|
+
const idxKey = withCasing(it.name, casing);
|
|
35974
|
+
statement += ` ${idxKey}: `;
|
|
35975
|
+
statement += "unique(";
|
|
35976
|
+
statement += `"${it.name}")`;
|
|
35977
|
+
statement += `.on(${it.columns.map((it2) => `table.${withCasing(it2, casing)}`).join(", ")}),`;
|
|
35978
|
+
statement += `
|
|
35615
35979
|
`;
|
|
35616
35980
|
});
|
|
35617
35981
|
return statement;
|
|
@@ -37030,7 +37394,7 @@ var init_mysqlIntrospect = __esm({
|
|
|
37030
37394
|
});
|
|
37031
37395
|
|
|
37032
37396
|
// src/sqlite-introspect.ts
|
|
37033
|
-
var sqliteImportsList, indexName3, objToStatement22, relations2, withCasing2, schemaToTypeScript2, isCyclic2, isSelf2, mapColumnDefault2, column5, createTableColumns2, createTableIndexes2, createTablePKs2, createTableFKs2;
|
|
37397
|
+
var sqliteImportsList, indexName3, objToStatement22, relations2, withCasing2, schemaToTypeScript2, isCyclic2, isSelf2, mapColumnDefault2, column5, createTableColumns2, createTableIndexes2, createTableUniques2, createTablePKs2, createTableFKs2;
|
|
37034
37398
|
var init_sqlite_introspect = __esm({
|
|
37035
37399
|
"src/sqlite-introspect.ts"() {
|
|
37036
37400
|
init_utils3();
|
|
@@ -37081,9 +37445,13 @@ var init_sqlite_introspect = __esm({
|
|
|
37081
37445
|
const pkImports = Object.values(it.compositePrimaryKeys).map(
|
|
37082
37446
|
(it2) => "primaryKey"
|
|
37083
37447
|
);
|
|
37448
|
+
const uniqueImports = Object.values(it.uniqueConstraints).map(
|
|
37449
|
+
(it2) => "unique"
|
|
37450
|
+
);
|
|
37084
37451
|
res.sqlite.push(...idxImports);
|
|
37085
37452
|
res.sqlite.push(...fkImpots);
|
|
37086
37453
|
res.sqlite.push(...pkImports);
|
|
37454
|
+
res.sqlite.push(...uniqueImports);
|
|
37087
37455
|
const columnImports = Object.values(it.columns).map((col) => {
|
|
37088
37456
|
return col.type;
|
|
37089
37457
|
}).filter((type) => {
|
|
@@ -37116,7 +37484,7 @@ var init_sqlite_introspect = __esm({
|
|
|
37116
37484
|
const filteredFKs = Object.values(table4.foreignKeys).filter((it) => {
|
|
37117
37485
|
return it.columnsFrom.length > 1 || isSelf2(it);
|
|
37118
37486
|
});
|
|
37119
|
-
if (Object.keys(table4.indexes).length > 0 || filteredFKs.length > 0 || Object.keys(table4.compositePrimaryKeys).length > 0) {
|
|
37487
|
+
if (Object.keys(table4.indexes).length > 0 || filteredFKs.length > 0 || Object.keys(table4.compositePrimaryKeys).length > 0 || Object.keys(table4.uniqueConstraints).length > 0) {
|
|
37120
37488
|
statement += ",\n";
|
|
37121
37489
|
statement += "(table) => {\n";
|
|
37122
37490
|
statement += " return {\n";
|
|
@@ -37130,6 +37498,10 @@ var init_sqlite_introspect = __esm({
|
|
|
37130
37498
|
Object.values(table4.compositePrimaryKeys),
|
|
37131
37499
|
casing
|
|
37132
37500
|
);
|
|
37501
|
+
statement += createTableUniques2(
|
|
37502
|
+
Object.values(table4.uniqueConstraints),
|
|
37503
|
+
casing
|
|
37504
|
+
);
|
|
37133
37505
|
statement += " }\n";
|
|
37134
37506
|
statement += "}";
|
|
37135
37507
|
}
|
|
@@ -37249,6 +37621,19 @@ import { sql } from "drizzle-orm"
|
|
|
37249
37621
|
statement += `${escapedIndexName})`;
|
|
37250
37622
|
statement += `.on(${it.columns.map((it2) => `table.${withCasing2(it2, casing)}`).join(", ")}),`;
|
|
37251
37623
|
statement += `
|
|
37624
|
+
`;
|
|
37625
|
+
});
|
|
37626
|
+
return statement;
|
|
37627
|
+
};
|
|
37628
|
+
createTableUniques2 = (unqs, casing) => {
|
|
37629
|
+
let statement = "";
|
|
37630
|
+
unqs.forEach((it) => {
|
|
37631
|
+
const idxKey = withCasing2(it.name, casing);
|
|
37632
|
+
statement += ` ${idxKey}: `;
|
|
37633
|
+
statement += "unique(";
|
|
37634
|
+
statement += `"${it.name}")`;
|
|
37635
|
+
statement += `.on(${it.columns.map((it2) => `table.${withCasing2(it2, casing)}`).join(", ")}),`;
|
|
37636
|
+
statement += `
|
|
37252
37637
|
`;
|
|
37253
37638
|
});
|
|
37254
37639
|
return statement;
|
|
@@ -50487,7 +50872,7 @@ var require_lib5 = __commonJS({
|
|
|
50487
50872
|
});
|
|
50488
50873
|
|
|
50489
50874
|
// src/introspect.ts
|
|
50490
|
-
var pgImportsList, objToStatement23, timeConfig2, possibleIntervals, intervalStrToObj, intervalConfig, importsPatch2, relations3, withCasing3, schemaToTypeScript3, isCyclic3, isSelf3, column6, dimensionsInArray, createTableColumns3, createTableIndexes3, createTablePKs3, createTableFKs3;
|
|
50875
|
+
var pgImportsList, objToStatement23, timeConfig2, possibleIntervals, intervalStrToObj, intervalConfig, importsPatch2, relations3, withCasing3, schemaToTypeScript3, isCyclic3, isSelf3, column6, dimensionsInArray, createTableColumns3, createTableIndexes3, createTablePKs3, createTableUniques3, createTableFKs3;
|
|
50491
50876
|
var init_introspect = __esm({
|
|
50492
50877
|
"src/introspect.ts"() {
|
|
50493
50878
|
init_utils3();
|
|
@@ -50630,9 +51015,13 @@ var init_introspect = __esm({
|
|
|
50630
51015
|
const pkImports = Object.values(it.compositePrimaryKeys).map(
|
|
50631
51016
|
(it2) => "primaryKey"
|
|
50632
51017
|
);
|
|
51018
|
+
const uniqueImports = Object.values(it.uniqueConstraints).map(
|
|
51019
|
+
(it2) => "unique"
|
|
51020
|
+
);
|
|
50633
51021
|
res.pg.push(...idxImports);
|
|
50634
51022
|
res.pg.push(...fkImpots);
|
|
50635
51023
|
res.pg.push(...pkImports);
|
|
51024
|
+
res.pg.push(...uniqueImports);
|
|
50636
51025
|
const columnImports = Object.values(it.columns).map((col) => {
|
|
50637
51026
|
let patched = importsPatch2[col.type] ?? col.type;
|
|
50638
51027
|
patched = patched.startsWith("varchar(") ? "varchar" : patched;
|
|
@@ -50676,7 +51065,7 @@ var init_introspect = __esm({
|
|
|
50676
51065
|
const filteredFKs = Object.values(table4.foreignKeys).filter((it) => {
|
|
50677
51066
|
return it.columnsFrom.length > 1 || isSelf3(it);
|
|
50678
51067
|
});
|
|
50679
|
-
if (Object.keys(table4.indexes).length > 0 || filteredFKs.length > 0 || Object.keys(table4.compositePrimaryKeys).length > 0) {
|
|
51068
|
+
if (Object.keys(table4.indexes).length > 0 || filteredFKs.length > 0 || Object.keys(table4.compositePrimaryKeys).length > 0 || Object.keys(table4.uniqueConstraints).length > 0) {
|
|
50680
51069
|
statement += ",\n";
|
|
50681
51070
|
statement += "(table) => {\n";
|
|
50682
51071
|
statement += " return {\n";
|
|
@@ -50690,6 +51079,10 @@ var init_introspect = __esm({
|
|
|
50690
51079
|
Object.values(table4.compositePrimaryKeys),
|
|
50691
51080
|
casing
|
|
50692
51081
|
);
|
|
51082
|
+
statement += createTableUniques3(
|
|
51083
|
+
Object.values(table4.uniqueConstraints),
|
|
51084
|
+
casing
|
|
51085
|
+
);
|
|
50693
51086
|
statement += " }\n";
|
|
50694
51087
|
statement += "}";
|
|
50695
51088
|
}
|
|
@@ -50932,7 +51325,13 @@ var init_introspect = __esm({
|
|
|
50932
51325
|
return res;
|
|
50933
51326
|
}, {});
|
|
50934
51327
|
columns.forEach((it) => {
|
|
50935
|
-
const columnStatement = column6(
|
|
51328
|
+
const columnStatement = column6(
|
|
51329
|
+
it.type,
|
|
51330
|
+
it.name,
|
|
51331
|
+
enumTypes,
|
|
51332
|
+
it.default,
|
|
51333
|
+
casing
|
|
51334
|
+
);
|
|
50936
51335
|
statement += " ";
|
|
50937
51336
|
statement += columnStatement;
|
|
50938
51337
|
statement += dimensionsInArray(it.type);
|
|
@@ -50991,6 +51390,20 @@ var init_introspect = __esm({
|
|
|
50991
51390
|
}).join(", ")}`;
|
|
50992
51391
|
statement += ")";
|
|
50993
51392
|
statement += `
|
|
51393
|
+
`;
|
|
51394
|
+
});
|
|
51395
|
+
return statement;
|
|
51396
|
+
};
|
|
51397
|
+
createTableUniques3 = (unqs, casing) => {
|
|
51398
|
+
let statement = "";
|
|
51399
|
+
unqs.forEach((it) => {
|
|
51400
|
+
const idxKey = withCasing3(it.name, casing);
|
|
51401
|
+
statement += ` ${idxKey}: `;
|
|
51402
|
+
statement += "unique(";
|
|
51403
|
+
statement += `"${it.name}")`;
|
|
51404
|
+
statement += `.on(${it.columns.map((it2) => `table.${withCasing3(it2, casing)}`).join(", ")})`;
|
|
51405
|
+
statement += it.nullsNotDistinct ? `.nullsNotDistinct()` : "";
|
|
51406
|
+
statement += `,
|
|
50994
51407
|
`;
|
|
50995
51408
|
});
|
|
50996
51409
|
return statement;
|
|
@@ -51323,7 +51736,7 @@ init_source();
|
|
|
51323
51736
|
// package.json
|
|
51324
51737
|
var package_default = {
|
|
51325
51738
|
name: "drizzle-kit",
|
|
51326
|
-
version: "0.19.
|
|
51739
|
+
version: "0.19.4",
|
|
51327
51740
|
repository: "https://github.com/drizzle-team/drizzle-kit-mirror",
|
|
51328
51741
|
author: "Drizzle Team",
|
|
51329
51742
|
license: "MIT",
|
|
@@ -51402,7 +51815,7 @@ var package_default = {
|
|
|
51402
51815
|
"better-sqlite3": "^8.4.0",
|
|
51403
51816
|
dockerode: "^3.3.4",
|
|
51404
51817
|
dotenv: "^16.0.3",
|
|
51405
|
-
"drizzle-orm": "0.27.0",
|
|
51818
|
+
"drizzle-orm": "0.27.0-7b55cc2",
|
|
51406
51819
|
eslint: "^8.29.0",
|
|
51407
51820
|
"eslint-config-prettier": "^8.5.0",
|
|
51408
51821
|
"eslint-plugin-prettier": "^4.2.1",
|
|
@@ -51900,7 +52313,7 @@ var logSuggestionsAndReturn2 = async ({
|
|
|
51900
52313
|
if (typeof tablesContext[fk4.tableFrom] === "undefined") {
|
|
51901
52314
|
tablesContext[fk4.tableFrom] = _moveDataStatements(fk4.tableFrom, json2);
|
|
51902
52315
|
}
|
|
51903
|
-
} else if (statement.type === "create_composite_pk" || statement.type === "alter_composite_pk" || statement.type === "delete_composite_pk") {
|
|
52316
|
+
} 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
52317
|
if (typeof tablesContext[statement.tableName] === "undefined") {
|
|
51905
52318
|
tablesContext[statement.tableName] = _moveDataStatements(
|
|
51906
52319
|
statement.tableName,
|