drizzle-kit 0.19.3 → 0.19.4-befd1c5
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 +269 -45
- package/package.json +2 -2
- package/utils.js +218 -34
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
|
})
|
|
@@ -5415,6 +5460,15 @@ var init_jsonDiffer = __esm({
|
|
|
5415
5460
|
const alteredCompositePKs = Object.fromEntries(Object.entries(table4.compositePrimaryKeys || {}).filter((it) => {
|
|
5416
5461
|
return !it[0].endsWith("__deleted") && !it[0].endsWith("__added");
|
|
5417
5462
|
}));
|
|
5463
|
+
const addedUniqueConstraints = Object.fromEntries(Object.entries(table4.uniqueConstraints || {}).filter((it) => {
|
|
5464
|
+
return it[0].endsWith("__added");
|
|
5465
|
+
}));
|
|
5466
|
+
const deletedUniqueConstraints = Object.fromEntries(Object.entries(table4.uniqueConstraints || {}).filter((it) => {
|
|
5467
|
+
return it[0].endsWith("__deleted");
|
|
5468
|
+
}));
|
|
5469
|
+
const alteredUniqueConstraints = Object.fromEntries(Object.entries(table4.uniqueConstraints || {}).filter((it) => {
|
|
5470
|
+
return !it[0].endsWith("__deleted") && !it[0].endsWith("__added");
|
|
5471
|
+
}));
|
|
5418
5472
|
const mappedAltered = altered.map((it) => alternationsInColumn(it));
|
|
5419
5473
|
return {
|
|
5420
5474
|
name: table4.name,
|
|
@@ -5430,7 +5484,10 @@ var init_jsonDiffer = __esm({
|
|
|
5430
5484
|
alteredForeignKeys,
|
|
5431
5485
|
addedCompositePKs,
|
|
5432
5486
|
deletedCompositePKs,
|
|
5433
|
-
alteredCompositePKs
|
|
5487
|
+
alteredCompositePKs,
|
|
5488
|
+
addedUniqueConstraints,
|
|
5489
|
+
deletedUniqueConstraints,
|
|
5490
|
+
alteredUniqueConstraints
|
|
5434
5491
|
};
|
|
5435
5492
|
};
|
|
5436
5493
|
alternationsInColumn = (column7) => {
|
|
@@ -11356,12 +11413,14 @@ var init_mysqlSerializer = __esm({
|
|
|
11356
11413
|
indexes,
|
|
11357
11414
|
foreignKeys,
|
|
11358
11415
|
schema: schema4,
|
|
11359
|
-
primaryKeys
|
|
11416
|
+
primaryKeys,
|
|
11417
|
+
uniqueConstraints
|
|
11360
11418
|
} = (0, import_mysql_core3.getTableConfig)(table4);
|
|
11361
11419
|
const columnsObject = {};
|
|
11362
11420
|
const indexesObject = {};
|
|
11363
11421
|
const foreignKeysObject = {};
|
|
11364
11422
|
const primaryKeysObject = {};
|
|
11423
|
+
const uniqueConstraintObject = {};
|
|
11365
11424
|
columns.forEach((column7) => {
|
|
11366
11425
|
const notNull = column7.notNull;
|
|
11367
11426
|
const primaryKey = column7.primary;
|
|
@@ -11382,6 +11441,12 @@ var init_mysqlSerializer = __esm({
|
|
|
11382
11441
|
// ? column.hasOnUpdateNow
|
|
11383
11442
|
// : undefined,
|
|
11384
11443
|
};
|
|
11444
|
+
if (column7.isUnique) {
|
|
11445
|
+
uniqueConstraintObject[column7.uniqueName] = {
|
|
11446
|
+
name: column7.uniqueName,
|
|
11447
|
+
columns: [columnToSet.name]
|
|
11448
|
+
};
|
|
11449
|
+
}
|
|
11385
11450
|
if (column7.default !== void 0) {
|
|
11386
11451
|
if ((0, import_drizzle_orm2.is)(column7.default, import_drizzle_orm3.SQL)) {
|
|
11387
11452
|
columnToSet.default = sqlToStr(column7.default);
|
|
@@ -11418,6 +11483,14 @@ var init_mysqlSerializer = __esm({
|
|
|
11418
11483
|
columnsObject[column7.name].notNull = true;
|
|
11419
11484
|
}
|
|
11420
11485
|
});
|
|
11486
|
+
uniqueConstraints.map((unq) => {
|
|
11487
|
+
const columnNames = unq.columns.map((c) => c.name);
|
|
11488
|
+
const name = unq.name ?? (0, import_mysql_core2.uniqueKeyName)(table4, columnNames);
|
|
11489
|
+
uniqueConstraintObject[name] = {
|
|
11490
|
+
name: unq.name,
|
|
11491
|
+
columns: columnNames
|
|
11492
|
+
};
|
|
11493
|
+
});
|
|
11421
11494
|
const fks = foreignKeys.map((fk4) => {
|
|
11422
11495
|
const name = fk4.getName();
|
|
11423
11496
|
const tableFrom = tableName;
|
|
@@ -11466,7 +11539,8 @@ var init_mysqlSerializer = __esm({
|
|
|
11466
11539
|
columns: columnsObject,
|
|
11467
11540
|
indexes: indexesObject,
|
|
11468
11541
|
foreignKeys: foreignKeysObject,
|
|
11469
|
-
compositePrimaryKeys: primaryKeysObject
|
|
11542
|
+
compositePrimaryKeys: primaryKeysObject,
|
|
11543
|
+
uniqueConstraints: uniqueConstraintObject
|
|
11470
11544
|
};
|
|
11471
11545
|
}
|
|
11472
11546
|
const schemas = Object.fromEntries(
|
|
@@ -11758,12 +11832,14 @@ var init_pgSerializer = __esm({
|
|
|
11758
11832
|
foreignKeys,
|
|
11759
11833
|
checks,
|
|
11760
11834
|
schema: schema4,
|
|
11761
|
-
primaryKeys
|
|
11835
|
+
primaryKeys,
|
|
11836
|
+
uniqueConstraints
|
|
11762
11837
|
} = (0, import_pg_core3.getTableConfig)(table4);
|
|
11763
11838
|
const columnsObject = {};
|
|
11764
11839
|
const indexesObject = {};
|
|
11765
11840
|
const foreignKeysObject = {};
|
|
11766
11841
|
const primaryKeysObject = {};
|
|
11842
|
+
const uniqueConstraintObject = {};
|
|
11767
11843
|
columns.forEach((column7) => {
|
|
11768
11844
|
const notNull = column7.notNull;
|
|
11769
11845
|
const primaryKey = column7.primary;
|
|
@@ -11774,6 +11850,13 @@ var init_pgSerializer = __esm({
|
|
|
11774
11850
|
primaryKey,
|
|
11775
11851
|
notNull
|
|
11776
11852
|
};
|
|
11853
|
+
if (column7.isUnique) {
|
|
11854
|
+
uniqueConstraintObject[column7.uniqueName] = {
|
|
11855
|
+
name: column7.uniqueName,
|
|
11856
|
+
nullsNotDistinct: column7.uniqueType === "not distinct",
|
|
11857
|
+
columns: [columnToSet.name]
|
|
11858
|
+
};
|
|
11859
|
+
}
|
|
11777
11860
|
if (column7.default !== void 0) {
|
|
11778
11861
|
if ((0, import_drizzle_orm5.is)(column7.default, import_drizzle_orm5.SQL)) {
|
|
11779
11862
|
columnToSet.default = sqlToStr(column7.default);
|
|
@@ -11808,6 +11891,15 @@ var init_pgSerializer = __esm({
|
|
|
11808
11891
|
columns: columnNames
|
|
11809
11892
|
};
|
|
11810
11893
|
});
|
|
11894
|
+
uniqueConstraints.map((unq) => {
|
|
11895
|
+
const columnNames = unq.columns.map((c) => c.name);
|
|
11896
|
+
const name = unq.name ?? (0, import_pg_core2.uniqueKeyName)(table4, columnNames);
|
|
11897
|
+
uniqueConstraintObject[name] = {
|
|
11898
|
+
name: unq.name,
|
|
11899
|
+
nullsNotDistinct: unq.nullsNotDistinct,
|
|
11900
|
+
columns: columnNames
|
|
11901
|
+
};
|
|
11902
|
+
});
|
|
11811
11903
|
const fks = foreignKeys.map((fk4) => {
|
|
11812
11904
|
const name = fk4.getName();
|
|
11813
11905
|
const tableFrom = tableName;
|
|
@@ -11856,7 +11948,8 @@ var init_pgSerializer = __esm({
|
|
|
11856
11948
|
columns: columnsObject,
|
|
11857
11949
|
indexes: indexesObject,
|
|
11858
11950
|
foreignKeys: foreignKeysObject,
|
|
11859
|
-
compositePrimaryKeys: primaryKeysObject
|
|
11951
|
+
compositePrimaryKeys: primaryKeysObject,
|
|
11952
|
+
uniqueConstraints: uniqueConstraintObject
|
|
11860
11953
|
};
|
|
11861
11954
|
}
|
|
11862
11955
|
const enumsToReturn = enums.reduce((map, obj) => {
|
|
@@ -14537,7 +14630,7 @@ ${sql}
|
|
|
14537
14630
|
});
|
|
14538
14631
|
|
|
14539
14632
|
// 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;
|
|
14633
|
+
var pgNativeTypes, isPgNativeType, Convertor, PgCreateTableConvertor, MySqlCreateTableConvertor, SQLiteCreateTableConvertor, PgAlterTableAddUniqueConstraintConvertor, PgAlterTableDropUniqueConstraintConvertor, MySQLAlterTableAddUniqueConstraintConvertor, MySQLAlterTableDropUniqueConstraintConvertor, CreateTypeEnumConvertor, AlterTypeAddValueConvertor, PgDropTableConvertor, MySQLDropTableConvertor, SQLiteDropTableConvertor, PgRenameTableConvertor, SqliteRenameTableConvertor, MySqlRenameTableConvertor, PgAlterTableRenameColumnConvertor, MySqlAlterTableRenameColumnConvertor, SQLiteAlterTableRenameColumnConvertor, PgAlterTableDropColumnConvertor, MySqlAlterTableDropColumnConvertor, SQLiteAlterTableDropColumnConvertor, PgAlterTableAddColumnConvertor, MySqlAlterTableAddColumnConvertor, SQLiteAlterTableAddColumnConvertor, PgAlterTableAlterColumnSetTypeConvertor, SQLiteAlterTableAlterColumnSetTypeConvertor, PgAlterTableAlterColumnSetDefaultConvertor, SqliteAlterTableAlterColumnSetDefaultConvertor, PgAlterTableAlterColumnDropDefaultConvertor, MySqlAlterTableAddPk, MySqlAlterTableDropPk, MySqlModifyColumn, SqliteAlterTableAlterColumnDropDefaultConvertor, PgAlterTableCreateCompositePrimaryKeyConvertor, PgAlterTableDeleteCompositePrimaryKeyConvertor, PgAlterTableAlterCompositePrimaryKeyConvertor, MySqlAlterTableCreateCompositePrimaryKeyConvertor, MySqlAlterTableDeleteCompositePrimaryKeyConvertor, MySqlAlterTableAlterCompositePrimaryKeyConvertor, SqliteAlterTableCreateCompositePrimaryKeyConvertor, SqliteAlterTableDeleteCompositePrimaryKeyConvertor, SqliteAlterTableAlterCompositePrimaryKeyConvertor, PgAlterTableAlterColumnSetPrimaryKeyConvertor, PgAlterTableAlterColumnDropPrimaryKeyConvertor, PgAlterTableAlterColumnSetNotNullConvertor, SqliteAlterTableAlterColumnSetNotNullConvertor, SqliteAlterTableAlterColumnSetAutoincrementConvertor, SqliteAlterTableAlterColumnDropAutoincrementConvertor, PgAlterTableAlterColumnDropNotNullConvertor, SqliteAlterTableAlterColumnDropNotNullConvertor, PgCreateForeignKeyConvertor, SqliteCreateForeignKeyConvertor, MySqlCreateForeignKeyConvertor, PgAlterForeignKeyConvertor, SqliteAlterForeignKeyConvertor, PgDeleteForeignKeyConvertor, SqliteDeleteForeignKeyConvertor, MySqlDeleteForeignKeyConvertor, CreatePgIndexConvertor, CreateMySqlIndexConvertor, CreateSqliteIndexConvertor, PgDropIndexConvertor, PgCreateSchemaConvertor, PgRenameSchemaConvertor, PgDropSchemaConvertor, PgAlterTableSetSchemaConvertor, PgAlterTableSetNewSchemaConvertor, PgAlterTableRemoveFromSchemaConvertor, SqliteDropIndexConvertor, MysqlCreateSchemaConvertor, MysqlDropSchemaConvertor, MysqlAlterTableSetSchemaConvertor, MysqlAlterTableSetNewSchemaConvertor, MysqlAlterTableRemoveFromSchemaConvertor, MySqlDropIndexConvertor, convertors, fromJson;
|
|
14541
14634
|
var init_sqlgenerator = __esm({
|
|
14542
14635
|
"src/sqlgenerator.ts"() {
|
|
14543
14636
|
init_migrate();
|
|
@@ -14598,30 +14691,37 @@ var init_sqlgenerator = __esm({
|
|
|
14598
14691
|
return statement.type === "create_table" && dialect6 === "pg";
|
|
14599
14692
|
}
|
|
14600
14693
|
convert(st) {
|
|
14601
|
-
const { tableName, schema: schema4, columns, compositePKs } = st;
|
|
14694
|
+
const { tableName, schema: schema4, columns, compositePKs, uniqueConstraints } = st;
|
|
14602
14695
|
let statement = "";
|
|
14603
14696
|
const name = schema4 ? `"${schema4}"."${tableName}"` : `"${tableName}"`;
|
|
14604
14697
|
statement += `CREATE TABLE IF NOT EXISTS ${name} (
|
|
14605
14698
|
`;
|
|
14606
14699
|
for (let i = 0; i < columns.length; i++) {
|
|
14607
14700
|
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}` : "";
|
|
14701
|
+
const primaryKeyStatement = column7.primaryKey ? " PRIMARY KEY" : "";
|
|
14702
|
+
const notNullStatement = column7.notNull ? " NOT NULL" : "";
|
|
14703
|
+
const defaultStatement = column7.default !== void 0 ? ` DEFAULT ${column7.default}` : "";
|
|
14704
|
+
const uniqueConstraint3 = column7.isUnique ? ` CONSTRAINT ${column7.uniqueName} UNIQUE${column7.nullsNotDistinct ? " NULLS NOT DISTINCT" : ""}` : "";
|
|
14611
14705
|
const type = isPgNativeType(column7.type) ? column7.type : `"${column7.type}"`;
|
|
14612
|
-
statement +=
|
|
14613
|
-
statement +=
|
|
14706
|
+
statement += ` "${column7.name}" ${type}${primaryKeyStatement}${defaultStatement}${notNullStatement}${uniqueConstraint3}`;
|
|
14707
|
+
statement += i === columns.length - 1 ? "" : ",\n";
|
|
14614
14708
|
}
|
|
14615
|
-
statement += `);`;
|
|
14616
|
-
statement += `
|
|
14617
|
-
`;
|
|
14618
14709
|
if (typeof compositePKs !== "undefined" && compositePKs.length > 0) {
|
|
14710
|
+
statement += ",\n";
|
|
14619
14711
|
const compositePK4 = PgSquasher.unsquashPK(compositePKs[0]);
|
|
14620
|
-
statement +=
|
|
14621
|
-
|
|
14622
|
-
|
|
14623
|
-
|
|
14712
|
+
statement += ` CONSTRAINT ${st.compositePkName} PRIMARY KEY("${compositePK4.columns.join(`","`)}")`;
|
|
14713
|
+
}
|
|
14714
|
+
if (typeof uniqueConstraints !== "undefined" && uniqueConstraints.length > 0) {
|
|
14715
|
+
for (const uniqueConstraint3 of uniqueConstraints) {
|
|
14716
|
+
statement += ",\n";
|
|
14717
|
+
const unsquashedUnique = PgSquasher.unsquashUnique(uniqueConstraint3);
|
|
14718
|
+
statement += ` CONSTRAINT ${unsquashedUnique.name} UNIQUE("${unsquashedUnique.columns.join(`","`)}")`;
|
|
14719
|
+
}
|
|
14624
14720
|
}
|
|
14721
|
+
statement += `
|
|
14722
|
+
);`;
|
|
14723
|
+
statement += `
|
|
14724
|
+
`;
|
|
14625
14725
|
return statement;
|
|
14626
14726
|
}
|
|
14627
14727
|
};
|
|
@@ -14630,7 +14730,7 @@ var init_sqlgenerator = __esm({
|
|
|
14630
14730
|
return statement.type === "create_table" && dialect6 === "mysql";
|
|
14631
14731
|
}
|
|
14632
14732
|
convert(st) {
|
|
14633
|
-
const { tableName, columns, schema: schema4, compositePKs } = st;
|
|
14733
|
+
const { tableName, columns, schema: schema4, compositePKs, uniqueConstraints } = st;
|
|
14634
14734
|
let statement = "";
|
|
14635
14735
|
const tName = schema4 ? `\`${schema4}\`.\`${tableName}\`` : `\`${tableName}\``;
|
|
14636
14736
|
statement += `CREATE TABLE ${tName} (
|
|
@@ -14642,17 +14742,23 @@ var init_sqlgenerator = __esm({
|
|
|
14642
14742
|
const defaultStatement = column7.default !== void 0 ? ` DEFAULT ${column7.default}` : "";
|
|
14643
14743
|
const onUpdateStatement = column7.onUpdate ? ` ON UPDATE CURRENT_TIMESTAMP` : "";
|
|
14644
14744
|
const autoincrementStatement = column7.autoincrement ? " AUTO_INCREMENT" : "";
|
|
14645
|
-
statement +=
|
|
14745
|
+
statement += ` \`${column7.name}\` ${column7.type}${autoincrementStatement}${primaryKeyStatement}${notNullStatement}${defaultStatement}${onUpdateStatement}`;
|
|
14646
14746
|
statement += i === columns.length - 1 ? "" : ",\n";
|
|
14647
14747
|
}
|
|
14648
14748
|
if (typeof compositePKs !== "undefined" && compositePKs.length > 0) {
|
|
14649
14749
|
statement += ",\n";
|
|
14650
14750
|
const compositePK4 = MySqlSquasher.unsquashPK(compositePKs[0]);
|
|
14651
|
-
statement += ` PRIMARY KEY(
|
|
14652
|
-
|
|
14653
|
-
|
|
14751
|
+
statement += ` CONSTRAINT ${st.compositePkName} PRIMARY KEY("${compositePK4.columns.join(`","`)}")`;
|
|
14752
|
+
}
|
|
14753
|
+
if (typeof uniqueConstraints !== "undefined" && uniqueConstraints.length > 0) {
|
|
14754
|
+
for (const uniqueConstraint3 of uniqueConstraints) {
|
|
14755
|
+
statement += ",\n";
|
|
14756
|
+
const unsquashedUnique = MySqlSquasher.unsquashUnique(uniqueConstraint3);
|
|
14757
|
+
statement += ` CONSTRAINT ${unsquashedUnique.name} UNIQUE(\`${unsquashedUnique.columns.join(`\`,\``)}\`)`;
|
|
14758
|
+
}
|
|
14654
14759
|
}
|
|
14655
|
-
statement += `
|
|
14760
|
+
statement += `
|
|
14761
|
+
);`;
|
|
14656
14762
|
statement += `
|
|
14657
14763
|
`;
|
|
14658
14764
|
return statement;
|
|
@@ -14708,6 +14814,46 @@ var init_sqlgenerator = __esm({
|
|
|
14708
14814
|
return statement;
|
|
14709
14815
|
}
|
|
14710
14816
|
};
|
|
14817
|
+
PgAlterTableAddUniqueConstraintConvertor = class extends Convertor {
|
|
14818
|
+
can(statement, dialect6) {
|
|
14819
|
+
return statement.type === "create_unique_constraint" && dialect6 === "pg";
|
|
14820
|
+
}
|
|
14821
|
+
convert(statement) {
|
|
14822
|
+
const unsquashed = PgSquasher.unsquashUnique(statement.data);
|
|
14823
|
+
const tableNameWithSchema = statement.schema ? `"${statement.schema}"."${statement.tableName}"` : `"${statement.tableName}"`;
|
|
14824
|
+
return `ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT "${unsquashed.name}" UNIQUE("${unsquashed.columns.join('","')}");`;
|
|
14825
|
+
}
|
|
14826
|
+
};
|
|
14827
|
+
PgAlterTableDropUniqueConstraintConvertor = class extends Convertor {
|
|
14828
|
+
can(statement, dialect6) {
|
|
14829
|
+
return statement.type === "delete_unique_constraint" && dialect6 === "pg";
|
|
14830
|
+
}
|
|
14831
|
+
convert(statement) {
|
|
14832
|
+
const unsquashed = PgSquasher.unsquashUnique(statement.data);
|
|
14833
|
+
const tableNameWithSchema = statement.schema ? `"${statement.schema}"."${statement.tableName}"` : `"${statement.tableName}"`;
|
|
14834
|
+
return `ALTER TABLE ${tableNameWithSchema} DROP CONSTRAINT "${unsquashed.name}";`;
|
|
14835
|
+
}
|
|
14836
|
+
};
|
|
14837
|
+
MySQLAlterTableAddUniqueConstraintConvertor = class extends Convertor {
|
|
14838
|
+
can(statement, dialect6) {
|
|
14839
|
+
return statement.type === "create_unique_constraint" && dialect6 === "mysql";
|
|
14840
|
+
}
|
|
14841
|
+
convert(statement) {
|
|
14842
|
+
const unsquashed = MySqlSquasher.unsquashUnique(statement.data);
|
|
14843
|
+
const tableNameWithSchema = statement.schema ? `\`${statement.schema}\`.\`${statement.tableName}\`` : `\`${statement.tableName}\``;
|
|
14844
|
+
return `ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT \`${unsquashed.name}\` UNIQUE(\`${unsquashed.columns.join("`,`")}\`);`;
|
|
14845
|
+
}
|
|
14846
|
+
};
|
|
14847
|
+
MySQLAlterTableDropUniqueConstraintConvertor = class extends Convertor {
|
|
14848
|
+
can(statement, dialect6) {
|
|
14849
|
+
return statement.type === "delete_unique_constraint" && dialect6 === "mysql";
|
|
14850
|
+
}
|
|
14851
|
+
convert(statement) {
|
|
14852
|
+
const unsquashed = MySqlSquasher.unsquashUnique(statement.data);
|
|
14853
|
+
const tableNameWithSchema = statement.schema ? `\`${statement.schema}\`.\`${statement.tableName}\`` : `\`${statement.tableName}\``;
|
|
14854
|
+
return `ALTER TABLE ${tableNameWithSchema} DROP CONSTRAINT \`${unsquashed.name}\`;`;
|
|
14855
|
+
}
|
|
14856
|
+
};
|
|
14711
14857
|
CreateTypeEnumConvertor = class extends Convertor {
|
|
14712
14858
|
can(statement) {
|
|
14713
14859
|
return statement.type === "create_type_enum";
|
|
@@ -15663,6 +15809,10 @@ ${BREAKPOINT}ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT ${statement.newCo
|
|
|
15663
15809
|
convertors.push(new MySqlAlterTableAddColumnConvertor());
|
|
15664
15810
|
convertors.push(new SQLiteAlterTableAddColumnConvertor());
|
|
15665
15811
|
convertors.push(new PgAlterTableAlterColumnSetTypeConvertor());
|
|
15812
|
+
convertors.push(new PgAlterTableAddUniqueConstraintConvertor());
|
|
15813
|
+
convertors.push(new PgAlterTableDropUniqueConstraintConvertor());
|
|
15814
|
+
convertors.push(new MySQLAlterTableAddUniqueConstraintConvertor());
|
|
15815
|
+
convertors.push(new MySQLAlterTableDropUniqueConstraintConvertor());
|
|
15666
15816
|
convertors.push(new CreatePgIndexConvertor());
|
|
15667
15817
|
convertors.push(new CreateMySqlIndexConvertor());
|
|
15668
15818
|
convertors.push(new CreateSqliteIndexConvertor());
|
|
@@ -15755,14 +15905,14 @@ drop type __venum;
|
|
|
15755
15905
|
});
|
|
15756
15906
|
|
|
15757
15907
|
// 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;
|
|
15908
|
+
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
15909
|
var init_jsonStatements = __esm({
|
|
15760
15910
|
"src/jsonStatements.ts"() {
|
|
15761
15911
|
init_mysqlSchema();
|
|
15762
15912
|
init_pgSchema();
|
|
15763
15913
|
init_sqliteSchema();
|
|
15764
15914
|
preparePgCreateTableJson = (table4, json2) => {
|
|
15765
|
-
const { name, schema: schema4, columns, compositePrimaryKeys } = table4;
|
|
15915
|
+
const { name, schema: schema4, columns, compositePrimaryKeys, uniqueConstraints } = table4;
|
|
15766
15916
|
return {
|
|
15767
15917
|
type: "create_table",
|
|
15768
15918
|
tableName: name,
|
|
@@ -15771,11 +15921,12 @@ var init_jsonStatements = __esm({
|
|
|
15771
15921
|
compositePKs: Object.values(compositePrimaryKeys),
|
|
15772
15922
|
compositePkName: Object.values(compositePrimaryKeys).length > 0 ? json2.tables[name].compositePrimaryKeys[`${name}_${PgSquasher.unsquashPK(
|
|
15773
15923
|
Object.values(compositePrimaryKeys)[0]
|
|
15774
|
-
).columns.join("_")}`].name : ""
|
|
15924
|
+
).columns.join("_")}`].name : "",
|
|
15925
|
+
uniqueConstraints: Object.values(uniqueConstraints)
|
|
15775
15926
|
};
|
|
15776
15927
|
};
|
|
15777
15928
|
prepareMySqlCreateTableJson = (table4, json2) => {
|
|
15778
|
-
const { name, schema: schema4, columns, compositePrimaryKeys } = table4;
|
|
15929
|
+
const { name, schema: schema4, columns, compositePrimaryKeys, uniqueConstraints } = table4;
|
|
15779
15930
|
return {
|
|
15780
15931
|
type: "create_table",
|
|
15781
15932
|
tableName: name,
|
|
@@ -15784,7 +15935,8 @@ var init_jsonStatements = __esm({
|
|
|
15784
15935
|
compositePKs: Object.values(compositePrimaryKeys),
|
|
15785
15936
|
compositePkName: Object.values(compositePrimaryKeys).length > 0 ? json2.tables[name].compositePrimaryKeys[`${name}_${MySqlSquasher.unsquashPK(
|
|
15786
15937
|
Object.values(compositePrimaryKeys)[0]
|
|
15787
|
-
).columns.join("_")}`].name : ""
|
|
15938
|
+
).columns.join("_")}`].name : "",
|
|
15939
|
+
uniqueConstraints: Object.values(uniqueConstraints)
|
|
15788
15940
|
};
|
|
15789
15941
|
};
|
|
15790
15942
|
prepareSQLiteCreateTable = (table4) => {
|
|
@@ -16269,6 +16421,26 @@ var init_jsonStatements = __esm({
|
|
|
16269
16421
|
};
|
|
16270
16422
|
});
|
|
16271
16423
|
};
|
|
16424
|
+
prepareAddUniqueConstraintPg = (tableName, schema4, unqs) => {
|
|
16425
|
+
return Object.values(unqs).map((it) => {
|
|
16426
|
+
return {
|
|
16427
|
+
type: "create_unique_constraint",
|
|
16428
|
+
tableName,
|
|
16429
|
+
data: it,
|
|
16430
|
+
schema: schema4
|
|
16431
|
+
};
|
|
16432
|
+
});
|
|
16433
|
+
};
|
|
16434
|
+
prepareDeleteUniqueConstraintPg = (tableName, schema4, unqs) => {
|
|
16435
|
+
return Object.values(unqs).map((it) => {
|
|
16436
|
+
return {
|
|
16437
|
+
type: "delete_unique_constraint",
|
|
16438
|
+
tableName,
|
|
16439
|
+
data: it,
|
|
16440
|
+
schema: schema4
|
|
16441
|
+
};
|
|
16442
|
+
});
|
|
16443
|
+
};
|
|
16272
16444
|
prepareAddCompositePrimaryKeyMySql = (tableName, pks, json2) => {
|
|
16273
16445
|
return Object.values(pks).map((it) => {
|
|
16274
16446
|
return {
|
|
@@ -16386,12 +16558,14 @@ var init_snapshotsDiffer = __esm({
|
|
|
16386
16558
|
name: stringType(),
|
|
16387
16559
|
type: stringType(),
|
|
16388
16560
|
primaryKey: booleanType().optional(),
|
|
16389
|
-
unique: booleanType().optional(),
|
|
16390
16561
|
default: anyType().optional(),
|
|
16391
16562
|
notNull: booleanType().optional(),
|
|
16392
16563
|
// should it be optional? should if be here?
|
|
16393
16564
|
autoincrement: booleanType().optional(),
|
|
16394
|
-
onUpdate: booleanType().optional()
|
|
16565
|
+
onUpdate: booleanType().optional(),
|
|
16566
|
+
isUnique: anyType().optional(),
|
|
16567
|
+
uniqueName: stringType().optional(),
|
|
16568
|
+
nullsNotDistinct: booleanType().optional()
|
|
16395
16569
|
}).strict();
|
|
16396
16570
|
alteredColumnSchema = objectType({
|
|
16397
16571
|
name: makeSelfOrChanged(stringType()),
|
|
@@ -16417,7 +16591,8 @@ var init_snapshotsDiffer = __esm({
|
|
|
16417
16591
|
columns: recordType(stringType(), columnSchema),
|
|
16418
16592
|
indexes: recordType(stringType(), stringType()),
|
|
16419
16593
|
foreignKeys: recordType(stringType(), stringType()),
|
|
16420
|
-
compositePrimaryKeys: recordType(stringType(), stringType()).default({})
|
|
16594
|
+
compositePrimaryKeys: recordType(stringType(), stringType()).default({}),
|
|
16595
|
+
uniqueConstraints: recordType(stringType(), stringType()).default({})
|
|
16421
16596
|
}).strict();
|
|
16422
16597
|
alteredTableScheme = objectType({
|
|
16423
16598
|
name: stringType(),
|
|
@@ -16451,6 +16626,15 @@ var init_snapshotsDiffer = __esm({
|
|
|
16451
16626
|
__new: stringType(),
|
|
16452
16627
|
__old: stringType()
|
|
16453
16628
|
})
|
|
16629
|
+
),
|
|
16630
|
+
addedUniqueConstraints: recordType(stringType(), stringType()),
|
|
16631
|
+
deletedUniqueConstraints: recordType(stringType(), stringType()),
|
|
16632
|
+
alteredUniqueConstraints: recordType(
|
|
16633
|
+
stringType(),
|
|
16634
|
+
objectType({
|
|
16635
|
+
__new: stringType(),
|
|
16636
|
+
__old: stringType()
|
|
16637
|
+
})
|
|
16454
16638
|
)
|
|
16455
16639
|
}).strict();
|
|
16456
16640
|
diffResultScheme = objectType({
|
|
@@ -16540,13 +16724,19 @@ var init_snapshotsDiffer = __esm({
|
|
|
16540
16724
|
alteredForeignKeys: table4.alteredForeignKeys,
|
|
16541
16725
|
addedCompositePKs: table4.addedCompositePKs,
|
|
16542
16726
|
deletedCompositePKs: table4.deletedCompositePKs,
|
|
16543
|
-
alteredCompositePKs: table4.alteredCompositePKs
|
|
16727
|
+
alteredCompositePKs: table4.alteredCompositePKs,
|
|
16728
|
+
addedUniqueConstraints: table4.addedUniqueConstraints,
|
|
16729
|
+
deletedUniqueConstraints: table4.deletedUniqueConstraints,
|
|
16730
|
+
alteredUniqueConstraints: table4.alteredUniqueConstraints
|
|
16544
16731
|
};
|
|
16545
16732
|
allAlteredResolved.push(resolved);
|
|
16546
16733
|
}
|
|
16547
16734
|
const jsonAddedCompositePKs = [];
|
|
16548
16735
|
const jsonDeletedCompositePKs = [];
|
|
16549
16736
|
const jsonAlteredCompositePKs = [];
|
|
16737
|
+
const jsonAddedUniqueConstraints = [];
|
|
16738
|
+
const jsonDeletedUniqueConstraints = [];
|
|
16739
|
+
const jsonAlteredUniqueConstraints = [];
|
|
16550
16740
|
const jsonSetTableSchemas = [];
|
|
16551
16741
|
const jsonRemoveTableFromSchemas = [];
|
|
16552
16742
|
const jsonSetNewTableSchemas = [];
|
|
@@ -16638,6 +16828,33 @@ var init_snapshotsDiffer = __esm({
|
|
|
16638
16828
|
curFull
|
|
16639
16829
|
);
|
|
16640
16830
|
}
|
|
16831
|
+
let addedUniqueConstraints = [];
|
|
16832
|
+
let deletedUniqueConstraints = [];
|
|
16833
|
+
let alteredUniqueConstraints = [];
|
|
16834
|
+
addedUniqueConstraints = prepareAddUniqueConstraintPg(
|
|
16835
|
+
it.name,
|
|
16836
|
+
schemaUnwrapped,
|
|
16837
|
+
it.addedUniqueConstraints
|
|
16838
|
+
);
|
|
16839
|
+
deletedUniqueConstraints = prepareDeleteUniqueConstraintPg(
|
|
16840
|
+
it.name,
|
|
16841
|
+
schemaUnwrapped,
|
|
16842
|
+
it.deletedUniqueConstraints
|
|
16843
|
+
);
|
|
16844
|
+
if (it.alteredUniqueConstraints) {
|
|
16845
|
+
const added = {};
|
|
16846
|
+
const deleted2 = {};
|
|
16847
|
+
for (const k of Object.keys(it.alteredUniqueConstraints)) {
|
|
16848
|
+
added[k] = it.alteredUniqueConstraints[k].__new;
|
|
16849
|
+
deleted2[k] = it.alteredUniqueConstraints[k].__old;
|
|
16850
|
+
}
|
|
16851
|
+
addedUniqueConstraints.push(
|
|
16852
|
+
...prepareAddUniqueConstraintPg(it.name, schemaUnwrapped, added)
|
|
16853
|
+
);
|
|
16854
|
+
deletedUniqueConstraints.push(
|
|
16855
|
+
...prepareDeleteUniqueConstraintPg(it.name, schemaUnwrapped, deleted2)
|
|
16856
|
+
);
|
|
16857
|
+
}
|
|
16641
16858
|
if (it.schema && typeof it.schema !== "string") {
|
|
16642
16859
|
switch (it.schema.type) {
|
|
16643
16860
|
case "added": {
|
|
@@ -16670,6 +16887,9 @@ var init_snapshotsDiffer = __esm({
|
|
|
16670
16887
|
jsonAddedCompositePKs.push(...addedCompositePKs);
|
|
16671
16888
|
jsonDeletedCompositePKs.push(...deletedCompositePKs);
|
|
16672
16889
|
jsonAlteredCompositePKs.push(...alteredCompositePKs);
|
|
16890
|
+
jsonAddedUniqueConstraints.push(...addedUniqueConstraints);
|
|
16891
|
+
jsonDeletedUniqueConstraints.push(...deletedUniqueConstraints);
|
|
16892
|
+
jsonAlteredUniqueConstraints.push(...alteredUniqueConstraints);
|
|
16673
16893
|
});
|
|
16674
16894
|
const rColumns = jsonRenameColumnsStatements.map((it) => {
|
|
16675
16895
|
const tableName = it.tableName;
|
|
@@ -16794,6 +17014,7 @@ var init_snapshotsDiffer = __esm({
|
|
|
16794
17014
|
jsonStatements.push(...jsonSQLiteCreateTables);
|
|
16795
17015
|
} else if (dialect6 === "pg") {
|
|
16796
17016
|
const jsonPgCreateTables = created.map((it) => {
|
|
17017
|
+
console.log(it);
|
|
16797
17018
|
return preparePgCreateTableJson(it, curFull);
|
|
16798
17019
|
});
|
|
16799
17020
|
jsonStatements.push(...jsonPgCreateTables);
|
|
@@ -16807,6 +17028,7 @@ var init_snapshotsDiffer = __esm({
|
|
|
16807
17028
|
jsonStatements.push(...jsonRenameTables);
|
|
16808
17029
|
jsonStatements.push(...jsonRenameColumnsStatements);
|
|
16809
17030
|
jsonStatements.push(...jsonDeletedCompositePKs);
|
|
17031
|
+
jsonStatements.push(...jsonDeletedUniqueConstraints);
|
|
16810
17032
|
jsonStatements.push(...jsonDroppedReferencesForAlteredTables);
|
|
16811
17033
|
jsonStatements.push(...jsonDropIndexesForAllAlteredTables);
|
|
16812
17034
|
jsonStatements.push(...jsonTableAlternations.alterColumns);
|
|
@@ -16819,6 +17041,8 @@ var init_snapshotsDiffer = __esm({
|
|
|
16819
17041
|
jsonStatements.push(...jsonCreateReferences);
|
|
16820
17042
|
jsonStatements.push(...jsonAddedCompositePKs);
|
|
16821
17043
|
jsonStatements.push(...jsonAlteredCompositePKs);
|
|
17044
|
+
jsonStatements.push(...jsonAddedUniqueConstraints);
|
|
17045
|
+
jsonStatements.push(...jsonAlteredUniqueConstraints);
|
|
16822
17046
|
jsonStatements.push(...jsonSetTableSchemas);
|
|
16823
17047
|
jsonStatements.push(...filteredJsonSetNewTableSchemas);
|
|
16824
17048
|
jsonStatements.push(...jsonRemoveTableFromSchemas);
|
|
@@ -51323,7 +51547,7 @@ init_source();
|
|
|
51323
51547
|
// package.json
|
|
51324
51548
|
var package_default = {
|
|
51325
51549
|
name: "drizzle-kit",
|
|
51326
|
-
version: "0.19.
|
|
51550
|
+
version: "0.19.4",
|
|
51327
51551
|
repository: "https://github.com/drizzle-team/drizzle-kit-mirror",
|
|
51328
51552
|
author: "Drizzle Team",
|
|
51329
51553
|
license: "MIT",
|
|
@@ -51402,7 +51626,7 @@ var package_default = {
|
|
|
51402
51626
|
"better-sqlite3": "^8.4.0",
|
|
51403
51627
|
dockerode: "^3.3.4",
|
|
51404
51628
|
dotenv: "^16.0.3",
|
|
51405
|
-
"drizzle-orm": "0.27.0",
|
|
51629
|
+
"drizzle-orm": "0.27.0-e9da18b",
|
|
51406
51630
|
eslint: "^8.29.0",
|
|
51407
51631
|
"eslint-config-prettier": "^8.5.0",
|
|
51408
51632
|
"eslint-plugin-prettier": "^4.2.1",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "drizzle-kit",
|
|
3
|
-
"version": "0.19.
|
|
3
|
+
"version": "0.19.4-befd1c5",
|
|
4
4
|
"repository": "https://github.com/drizzle-team/drizzle-kit-mirror",
|
|
5
5
|
"author": "Drizzle Team",
|
|
6
6
|
"license": "MIT",
|
|
@@ -79,7 +79,7 @@
|
|
|
79
79
|
"better-sqlite3": "^8.4.0",
|
|
80
80
|
"dockerode": "^3.3.4",
|
|
81
81
|
"dotenv": "^16.0.3",
|
|
82
|
-
"drizzle-orm": "0.27.0",
|
|
82
|
+
"drizzle-orm": "0.27.0-e9da18b",
|
|
83
83
|
"eslint": "^8.29.0",
|
|
84
84
|
"eslint-config-prettier": "^8.5.0",
|
|
85
85
|
"eslint-plugin-prettier": "^4.2.1",
|
package/utils.js
CHANGED
|
@@ -12759,6 +12759,10 @@ var compositePK = objectType({
|
|
|
12759
12759
|
name: stringType(),
|
|
12760
12760
|
columns: stringType().array()
|
|
12761
12761
|
}).strict();
|
|
12762
|
+
var uniqueConstraint = objectType({
|
|
12763
|
+
name: stringType(),
|
|
12764
|
+
columns: stringType().array()
|
|
12765
|
+
}).strict();
|
|
12762
12766
|
var tableV4 = objectType({
|
|
12763
12767
|
name: stringType(),
|
|
12764
12768
|
schema: stringType().optional(),
|
|
@@ -12772,7 +12776,8 @@ var table = objectType({
|
|
|
12772
12776
|
columns: recordType(stringType(), column),
|
|
12773
12777
|
indexes: recordType(stringType(), index),
|
|
12774
12778
|
foreignKeys: recordType(stringType(), fk),
|
|
12775
|
-
compositePrimaryKeys: recordType(stringType(), compositePK)
|
|
12779
|
+
compositePrimaryKeys: recordType(stringType(), compositePK),
|
|
12780
|
+
uniqueConstraints: recordType(stringType(), uniqueConstraint).default({})
|
|
12776
12781
|
}).strict();
|
|
12777
12782
|
var dialect = literalType("mysql");
|
|
12778
12783
|
var schemaHash = objectType({
|
|
@@ -12855,6 +12860,13 @@ var MySqlSquasher = {
|
|
|
12855
12860
|
const splitted = pk.split(";");
|
|
12856
12861
|
return { name: splitted[0], columns: splitted[1].split(",") };
|
|
12857
12862
|
},
|
|
12863
|
+
squashUnique: (unq) => {
|
|
12864
|
+
return `${unq.name};${unq.columns.join(",")}`;
|
|
12865
|
+
},
|
|
12866
|
+
unsquashUnique: (unq) => {
|
|
12867
|
+
const [name, columns] = unq.split(";");
|
|
12868
|
+
return { name, columns: columns.split(",") };
|
|
12869
|
+
},
|
|
12858
12870
|
squashFK: (fk4) => {
|
|
12859
12871
|
return `${fk4.name};${fk4.tableFrom};${fk4.columnsFrom.join(",")};${fk4.tableTo};${fk4.columnsTo.join(",")};${fk4.onUpdate ?? ""};${fk4.onDelete ?? ""}`;
|
|
12860
12872
|
},
|
|
@@ -12881,7 +12893,11 @@ var MySqlSquasher = {
|
|
|
12881
12893
|
}
|
|
12882
12894
|
};
|
|
12883
12895
|
var mysqlSchema = schema;
|
|
12884
|
-
var backwardCompatibleMysqlSchema = unionType([
|
|
12896
|
+
var backwardCompatibleMysqlSchema = unionType([
|
|
12897
|
+
schemaV3,
|
|
12898
|
+
schemaV4,
|
|
12899
|
+
schema
|
|
12900
|
+
]);
|
|
12885
12901
|
var dryMySql = mysqlSchema.parse({
|
|
12886
12902
|
version: snapshotVersion,
|
|
12887
12903
|
dialect: "mysql",
|
|
@@ -12974,7 +12990,10 @@ var column2 = objectType({
|
|
|
12974
12990
|
type: stringType(),
|
|
12975
12991
|
primaryKey: booleanType(),
|
|
12976
12992
|
notNull: booleanType(),
|
|
12977
|
-
default: anyType().optional()
|
|
12993
|
+
default: anyType().optional(),
|
|
12994
|
+
isUnique: anyType().optional(),
|
|
12995
|
+
uniqueName: stringType().optional(),
|
|
12996
|
+
nullsNotDistinct: booleanType().optional()
|
|
12978
12997
|
}).strict();
|
|
12979
12998
|
var tableV32 = objectType({
|
|
12980
12999
|
name: stringType(),
|
|
@@ -12986,6 +13005,11 @@ var compositePK2 = objectType({
|
|
|
12986
13005
|
name: stringType(),
|
|
12987
13006
|
columns: stringType().array()
|
|
12988
13007
|
}).strict();
|
|
13008
|
+
var uniqueConstraint2 = objectType({
|
|
13009
|
+
name: stringType(),
|
|
13010
|
+
columns: stringType().array(),
|
|
13011
|
+
nullsNotDistinct: booleanType()
|
|
13012
|
+
}).strict();
|
|
12989
13013
|
var tableV42 = objectType({
|
|
12990
13014
|
name: stringType(),
|
|
12991
13015
|
schema: stringType(),
|
|
@@ -12999,7 +13023,8 @@ var table2 = objectType({
|
|
|
12999
13023
|
columns: recordType(stringType(), column2),
|
|
13000
13024
|
indexes: recordType(stringType(), index2),
|
|
13001
13025
|
foreignKeys: recordType(stringType(), fk2),
|
|
13002
|
-
compositePrimaryKeys: recordType(stringType(), compositePK2)
|
|
13026
|
+
compositePrimaryKeys: recordType(stringType(), compositePK2),
|
|
13027
|
+
uniqueConstraints: recordType(stringType(), uniqueConstraint2).default({})
|
|
13003
13028
|
}).strict();
|
|
13004
13029
|
var schemaHash2 = objectType({
|
|
13005
13030
|
id: stringType(),
|
|
@@ -13036,7 +13061,8 @@ var tableSquashed2 = objectType({
|
|
|
13036
13061
|
columns: recordType(stringType(), column2),
|
|
13037
13062
|
indexes: recordType(stringType(), stringType()),
|
|
13038
13063
|
foreignKeys: recordType(stringType(), stringType()),
|
|
13039
|
-
compositePrimaryKeys: recordType(stringType(), stringType())
|
|
13064
|
+
compositePrimaryKeys: recordType(stringType(), stringType()),
|
|
13065
|
+
uniqueConstraints: recordType(stringType(), stringType())
|
|
13040
13066
|
}).strict();
|
|
13041
13067
|
var tableSquashedV42 = objectType({
|
|
13042
13068
|
name: stringType(),
|
|
@@ -13092,6 +13118,17 @@ var PgSquasher = {
|
|
|
13092
13118
|
unsquashPK: (pk) => {
|
|
13093
13119
|
return { name: "", columns: pk.split(",") };
|
|
13094
13120
|
},
|
|
13121
|
+
squashUnique: (unq) => {
|
|
13122
|
+
return `${unq.name};${unq.columns.join(",")};${unq.nullsNotDistinct}`;
|
|
13123
|
+
},
|
|
13124
|
+
unsquashUnique: (unq) => {
|
|
13125
|
+
const [
|
|
13126
|
+
name,
|
|
13127
|
+
columns,
|
|
13128
|
+
nullsNotDistinct
|
|
13129
|
+
] = unq.split(";");
|
|
13130
|
+
return { name, columns: columns.split(","), nullsNotDistinct: nullsNotDistinct === "true" };
|
|
13131
|
+
},
|
|
13095
13132
|
unsquashFK: (input) => {
|
|
13096
13133
|
const [
|
|
13097
13134
|
name,
|
|
@@ -13126,6 +13163,9 @@ var squashPgScheme = (json) => {
|
|
|
13126
13163
|
const squashedPKs = mapValues(it[1].compositePrimaryKeys, (pk) => {
|
|
13127
13164
|
return PgSquasher.squashPK(pk);
|
|
13128
13165
|
});
|
|
13166
|
+
const squashedUniqueConstraints = mapValues(it[1].uniqueConstraints, (unq) => {
|
|
13167
|
+
return PgSquasher.squashUnique(unq);
|
|
13168
|
+
});
|
|
13129
13169
|
return [
|
|
13130
13170
|
it[0],
|
|
13131
13171
|
{
|
|
@@ -13134,7 +13174,8 @@ var squashPgScheme = (json) => {
|
|
|
13134
13174
|
columns: it[1].columns,
|
|
13135
13175
|
indexes: squashedIndexes,
|
|
13136
13176
|
foreignKeys: squashedFKs,
|
|
13137
|
-
compositePrimaryKeys: squashedPKs
|
|
13177
|
+
compositePrimaryKeys: squashedPKs,
|
|
13178
|
+
uniqueConstraints: squashedUniqueConstraints
|
|
13138
13179
|
}
|
|
13139
13180
|
];
|
|
13140
13181
|
})
|
|
@@ -13440,6 +13481,15 @@ var findAlternationsInTable = (table4, tableSchema) => {
|
|
|
13440
13481
|
const alteredCompositePKs = Object.fromEntries(Object.entries(table4.compositePrimaryKeys || {}).filter((it) => {
|
|
13441
13482
|
return !it[0].endsWith("__deleted") && !it[0].endsWith("__added");
|
|
13442
13483
|
}));
|
|
13484
|
+
const addedUniqueConstraints = Object.fromEntries(Object.entries(table4.uniqueConstraints || {}).filter((it) => {
|
|
13485
|
+
return it[0].endsWith("__added");
|
|
13486
|
+
}));
|
|
13487
|
+
const deletedUniqueConstraints = Object.fromEntries(Object.entries(table4.uniqueConstraints || {}).filter((it) => {
|
|
13488
|
+
return it[0].endsWith("__deleted");
|
|
13489
|
+
}));
|
|
13490
|
+
const alteredUniqueConstraints = Object.fromEntries(Object.entries(table4.uniqueConstraints || {}).filter((it) => {
|
|
13491
|
+
return !it[0].endsWith("__deleted") && !it[0].endsWith("__added");
|
|
13492
|
+
}));
|
|
13443
13493
|
const mappedAltered = altered.map((it) => alternationsInColumn(it));
|
|
13444
13494
|
return {
|
|
13445
13495
|
name: table4.name,
|
|
@@ -13455,7 +13505,10 @@ var findAlternationsInTable = (table4, tableSchema) => {
|
|
|
13455
13505
|
alteredForeignKeys,
|
|
13456
13506
|
addedCompositePKs,
|
|
13457
13507
|
deletedCompositePKs,
|
|
13458
|
-
alteredCompositePKs
|
|
13508
|
+
alteredCompositePKs,
|
|
13509
|
+
addedUniqueConstraints,
|
|
13510
|
+
deletedUniqueConstraints,
|
|
13511
|
+
alteredUniqueConstraints
|
|
13459
13512
|
};
|
|
13460
13513
|
};
|
|
13461
13514
|
var alternationsInColumn = (column4) => {
|
|
@@ -13603,30 +13656,37 @@ var PgCreateTableConvertor = class extends Convertor {
|
|
|
13603
13656
|
return statement.type === "create_table" && dialect3 === "pg";
|
|
13604
13657
|
}
|
|
13605
13658
|
convert(st) {
|
|
13606
|
-
const { tableName, schema: schema4, columns, compositePKs } = st;
|
|
13659
|
+
const { tableName, schema: schema4, columns, compositePKs, uniqueConstraints } = st;
|
|
13607
13660
|
let statement = "";
|
|
13608
13661
|
const name = schema4 ? `"${schema4}"."${tableName}"` : `"${tableName}"`;
|
|
13609
13662
|
statement += `CREATE TABLE IF NOT EXISTS ${name} (
|
|
13610
13663
|
`;
|
|
13611
13664
|
for (let i = 0; i < columns.length; i++) {
|
|
13612
13665
|
const column4 = columns[i];
|
|
13613
|
-
const primaryKeyStatement = column4.primaryKey ? "PRIMARY KEY" : "";
|
|
13614
|
-
const notNullStatement = column4.notNull ? "NOT NULL" : "";
|
|
13615
|
-
const defaultStatement = column4.default !== void 0 ? `DEFAULT ${column4.default}` : "";
|
|
13666
|
+
const primaryKeyStatement = column4.primaryKey ? " PRIMARY KEY" : "";
|
|
13667
|
+
const notNullStatement = column4.notNull ? " NOT NULL" : "";
|
|
13668
|
+
const defaultStatement = column4.default !== void 0 ? ` DEFAULT ${column4.default}` : "";
|
|
13669
|
+
const uniqueConstraint3 = column4.isUnique ? ` CONSTRAINT ${column4.uniqueName} UNIQUE${column4.nullsNotDistinct ? " NULLS NOT DISTINCT" : ""}` : "";
|
|
13616
13670
|
const type = isPgNativeType(column4.type) ? column4.type : `"${column4.type}"`;
|
|
13617
|
-
statement +=
|
|
13618
|
-
statement +=
|
|
13671
|
+
statement += ` "${column4.name}" ${type}${primaryKeyStatement}${defaultStatement}${notNullStatement}${uniqueConstraint3}`;
|
|
13672
|
+
statement += i === columns.length - 1 ? "" : ",\n";
|
|
13619
13673
|
}
|
|
13620
|
-
statement += `);`;
|
|
13621
|
-
statement += `
|
|
13622
|
-
`;
|
|
13623
13674
|
if (typeof compositePKs !== "undefined" && compositePKs.length > 0) {
|
|
13675
|
+
statement += ",\n";
|
|
13624
13676
|
const compositePK4 = PgSquasher.unsquashPK(compositePKs[0]);
|
|
13625
|
-
statement +=
|
|
13626
|
-
statement += `ALTER TABLE ${name} ADD CONSTRAINT "${st.compositePkName}" PRIMARY KEY("${compositePK4.columns.join('","')}");`;
|
|
13627
|
-
statement += `
|
|
13628
|
-
`;
|
|
13677
|
+
statement += ` CONSTRAINT ${st.compositePkName} PRIMARY KEY("${compositePK4.columns.join(`","`)}")`;
|
|
13629
13678
|
}
|
|
13679
|
+
if (typeof uniqueConstraints !== "undefined" && uniqueConstraints.length > 0) {
|
|
13680
|
+
for (const uniqueConstraint3 of uniqueConstraints) {
|
|
13681
|
+
statement += ",\n";
|
|
13682
|
+
const unsquashedUnique = PgSquasher.unsquashUnique(uniqueConstraint3);
|
|
13683
|
+
statement += ` CONSTRAINT ${unsquashedUnique.name} UNIQUE("${unsquashedUnique.columns.join(`","`)}")`;
|
|
13684
|
+
}
|
|
13685
|
+
}
|
|
13686
|
+
statement += `
|
|
13687
|
+
);`;
|
|
13688
|
+
statement += `
|
|
13689
|
+
`;
|
|
13630
13690
|
return statement;
|
|
13631
13691
|
}
|
|
13632
13692
|
};
|
|
@@ -13635,7 +13695,7 @@ var MySqlCreateTableConvertor = class extends Convertor {
|
|
|
13635
13695
|
return statement.type === "create_table" && dialect3 === "mysql";
|
|
13636
13696
|
}
|
|
13637
13697
|
convert(st) {
|
|
13638
|
-
const { tableName, columns, schema: schema4, compositePKs } = st;
|
|
13698
|
+
const { tableName, columns, schema: schema4, compositePKs, uniqueConstraints } = st;
|
|
13639
13699
|
let statement = "";
|
|
13640
13700
|
const tName = schema4 ? `\`${schema4}\`.\`${tableName}\`` : `\`${tableName}\``;
|
|
13641
13701
|
statement += `CREATE TABLE ${tName} (
|
|
@@ -13647,17 +13707,23 @@ var MySqlCreateTableConvertor = class extends Convertor {
|
|
|
13647
13707
|
const defaultStatement = column4.default !== void 0 ? ` DEFAULT ${column4.default}` : "";
|
|
13648
13708
|
const onUpdateStatement = column4.onUpdate ? ` ON UPDATE CURRENT_TIMESTAMP` : "";
|
|
13649
13709
|
const autoincrementStatement = column4.autoincrement ? " AUTO_INCREMENT" : "";
|
|
13650
|
-
statement +=
|
|
13710
|
+
statement += ` \`${column4.name}\` ${column4.type}${autoincrementStatement}${primaryKeyStatement}${notNullStatement}${defaultStatement}${onUpdateStatement}`;
|
|
13651
13711
|
statement += i === columns.length - 1 ? "" : ",\n";
|
|
13652
13712
|
}
|
|
13653
13713
|
if (typeof compositePKs !== "undefined" && compositePKs.length > 0) {
|
|
13654
13714
|
statement += ",\n";
|
|
13655
13715
|
const compositePK4 = MySqlSquasher.unsquashPK(compositePKs[0]);
|
|
13656
|
-
statement += ` PRIMARY KEY(
|
|
13657
|
-
|
|
13658
|
-
|
|
13716
|
+
statement += ` CONSTRAINT ${st.compositePkName} PRIMARY KEY("${compositePK4.columns.join(`","`)}")`;
|
|
13717
|
+
}
|
|
13718
|
+
if (typeof uniqueConstraints !== "undefined" && uniqueConstraints.length > 0) {
|
|
13719
|
+
for (const uniqueConstraint3 of uniqueConstraints) {
|
|
13720
|
+
statement += ",\n";
|
|
13721
|
+
const unsquashedUnique = MySqlSquasher.unsquashUnique(uniqueConstraint3);
|
|
13722
|
+
statement += ` CONSTRAINT ${unsquashedUnique.name} UNIQUE(\`${unsquashedUnique.columns.join(`\`,\``)}\`)`;
|
|
13723
|
+
}
|
|
13659
13724
|
}
|
|
13660
|
-
statement += `
|
|
13725
|
+
statement += `
|
|
13726
|
+
);`;
|
|
13661
13727
|
statement += `
|
|
13662
13728
|
`;
|
|
13663
13729
|
return statement;
|
|
@@ -13713,6 +13779,46 @@ var SQLiteCreateTableConvertor = class extends Convertor {
|
|
|
13713
13779
|
return statement;
|
|
13714
13780
|
}
|
|
13715
13781
|
};
|
|
13782
|
+
var PgAlterTableAddUniqueConstraintConvertor = class extends Convertor {
|
|
13783
|
+
can(statement, dialect3) {
|
|
13784
|
+
return statement.type === "create_unique_constraint" && dialect3 === "pg";
|
|
13785
|
+
}
|
|
13786
|
+
convert(statement) {
|
|
13787
|
+
const unsquashed = PgSquasher.unsquashUnique(statement.data);
|
|
13788
|
+
const tableNameWithSchema = statement.schema ? `"${statement.schema}"."${statement.tableName}"` : `"${statement.tableName}"`;
|
|
13789
|
+
return `ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT "${unsquashed.name}" UNIQUE("${unsquashed.columns.join('","')}");`;
|
|
13790
|
+
}
|
|
13791
|
+
};
|
|
13792
|
+
var PgAlterTableDropUniqueConstraintConvertor = class extends Convertor {
|
|
13793
|
+
can(statement, dialect3) {
|
|
13794
|
+
return statement.type === "delete_unique_constraint" && dialect3 === "pg";
|
|
13795
|
+
}
|
|
13796
|
+
convert(statement) {
|
|
13797
|
+
const unsquashed = PgSquasher.unsquashUnique(statement.data);
|
|
13798
|
+
const tableNameWithSchema = statement.schema ? `"${statement.schema}"."${statement.tableName}"` : `"${statement.tableName}"`;
|
|
13799
|
+
return `ALTER TABLE ${tableNameWithSchema} DROP CONSTRAINT "${unsquashed.name}";`;
|
|
13800
|
+
}
|
|
13801
|
+
};
|
|
13802
|
+
var MySQLAlterTableAddUniqueConstraintConvertor = class extends Convertor {
|
|
13803
|
+
can(statement, dialect3) {
|
|
13804
|
+
return statement.type === "create_unique_constraint" && dialect3 === "mysql";
|
|
13805
|
+
}
|
|
13806
|
+
convert(statement) {
|
|
13807
|
+
const unsquashed = MySqlSquasher.unsquashUnique(statement.data);
|
|
13808
|
+
const tableNameWithSchema = statement.schema ? `\`${statement.schema}\`.\`${statement.tableName}\`` : `\`${statement.tableName}\``;
|
|
13809
|
+
return `ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT \`${unsquashed.name}\` UNIQUE(\`${unsquashed.columns.join("`,`")}\`);`;
|
|
13810
|
+
}
|
|
13811
|
+
};
|
|
13812
|
+
var MySQLAlterTableDropUniqueConstraintConvertor = class extends Convertor {
|
|
13813
|
+
can(statement, dialect3) {
|
|
13814
|
+
return statement.type === "delete_unique_constraint" && dialect3 === "mysql";
|
|
13815
|
+
}
|
|
13816
|
+
convert(statement) {
|
|
13817
|
+
const unsquashed = MySqlSquasher.unsquashUnique(statement.data);
|
|
13818
|
+
const tableNameWithSchema = statement.schema ? `\`${statement.schema}\`.\`${statement.tableName}\`` : `\`${statement.tableName}\``;
|
|
13819
|
+
return `ALTER TABLE ${tableNameWithSchema} DROP CONSTRAINT \`${unsquashed.name}\`;`;
|
|
13820
|
+
}
|
|
13821
|
+
};
|
|
13716
13822
|
var CreateTypeEnumConvertor = class extends Convertor {
|
|
13717
13823
|
can(statement) {
|
|
13718
13824
|
return statement.type === "create_type_enum";
|
|
@@ -14668,6 +14774,10 @@ convertors.push(new PgAlterTableAddColumnConvertor());
|
|
|
14668
14774
|
convertors.push(new MySqlAlterTableAddColumnConvertor());
|
|
14669
14775
|
convertors.push(new SQLiteAlterTableAddColumnConvertor());
|
|
14670
14776
|
convertors.push(new PgAlterTableAlterColumnSetTypeConvertor());
|
|
14777
|
+
convertors.push(new PgAlterTableAddUniqueConstraintConvertor());
|
|
14778
|
+
convertors.push(new PgAlterTableDropUniqueConstraintConvertor());
|
|
14779
|
+
convertors.push(new MySQLAlterTableAddUniqueConstraintConvertor());
|
|
14780
|
+
convertors.push(new MySQLAlterTableDropUniqueConstraintConvertor());
|
|
14671
14781
|
convertors.push(new CreatePgIndexConvertor());
|
|
14672
14782
|
convertors.push(new CreateMySqlIndexConvertor());
|
|
14673
14783
|
convertors.push(new CreateSqliteIndexConvertor());
|
|
@@ -14762,7 +14872,7 @@ init_lib();
|
|
|
14762
14872
|
|
|
14763
14873
|
// src/jsonStatements.ts
|
|
14764
14874
|
var preparePgCreateTableJson = (table4, json2) => {
|
|
14765
|
-
const { name, schema: schema4, columns, compositePrimaryKeys } = table4;
|
|
14875
|
+
const { name, schema: schema4, columns, compositePrimaryKeys, uniqueConstraints } = table4;
|
|
14766
14876
|
return {
|
|
14767
14877
|
type: "create_table",
|
|
14768
14878
|
tableName: name,
|
|
@@ -14771,11 +14881,12 @@ var preparePgCreateTableJson = (table4, json2) => {
|
|
|
14771
14881
|
compositePKs: Object.values(compositePrimaryKeys),
|
|
14772
14882
|
compositePkName: Object.values(compositePrimaryKeys).length > 0 ? json2.tables[name].compositePrimaryKeys[`${name}_${PgSquasher.unsquashPK(
|
|
14773
14883
|
Object.values(compositePrimaryKeys)[0]
|
|
14774
|
-
).columns.join("_")}`].name : ""
|
|
14884
|
+
).columns.join("_")}`].name : "",
|
|
14885
|
+
uniqueConstraints: Object.values(uniqueConstraints)
|
|
14775
14886
|
};
|
|
14776
14887
|
};
|
|
14777
14888
|
var prepareMySqlCreateTableJson = (table4, json2) => {
|
|
14778
|
-
const { name, schema: schema4, columns, compositePrimaryKeys } = table4;
|
|
14889
|
+
const { name, schema: schema4, columns, compositePrimaryKeys, uniqueConstraints } = table4;
|
|
14779
14890
|
return {
|
|
14780
14891
|
type: "create_table",
|
|
14781
14892
|
tableName: name,
|
|
@@ -14784,7 +14895,8 @@ var prepareMySqlCreateTableJson = (table4, json2) => {
|
|
|
14784
14895
|
compositePKs: Object.values(compositePrimaryKeys),
|
|
14785
14896
|
compositePkName: Object.values(compositePrimaryKeys).length > 0 ? json2.tables[name].compositePrimaryKeys[`${name}_${MySqlSquasher.unsquashPK(
|
|
14786
14897
|
Object.values(compositePrimaryKeys)[0]
|
|
14787
|
-
).columns.join("_")}`].name : ""
|
|
14898
|
+
).columns.join("_")}`].name : "",
|
|
14899
|
+
uniqueConstraints: Object.values(uniqueConstraints)
|
|
14788
14900
|
};
|
|
14789
14901
|
};
|
|
14790
14902
|
var prepareSQLiteCreateTable = (table4) => {
|
|
@@ -15269,6 +15381,26 @@ var prepareAlterCompositePrimaryKeyPg = (tableName, schema4, pks, json1, json2)
|
|
|
15269
15381
|
};
|
|
15270
15382
|
});
|
|
15271
15383
|
};
|
|
15384
|
+
var prepareAddUniqueConstraintPg = (tableName, schema4, unqs) => {
|
|
15385
|
+
return Object.values(unqs).map((it) => {
|
|
15386
|
+
return {
|
|
15387
|
+
type: "create_unique_constraint",
|
|
15388
|
+
tableName,
|
|
15389
|
+
data: it,
|
|
15390
|
+
schema: schema4
|
|
15391
|
+
};
|
|
15392
|
+
});
|
|
15393
|
+
};
|
|
15394
|
+
var prepareDeleteUniqueConstraintPg = (tableName, schema4, unqs) => {
|
|
15395
|
+
return Object.values(unqs).map((it) => {
|
|
15396
|
+
return {
|
|
15397
|
+
type: "delete_unique_constraint",
|
|
15398
|
+
tableName,
|
|
15399
|
+
data: it,
|
|
15400
|
+
schema: schema4
|
|
15401
|
+
};
|
|
15402
|
+
});
|
|
15403
|
+
};
|
|
15272
15404
|
var prepareAddCompositePrimaryKeyMySql = (tableName, pks, json2) => {
|
|
15273
15405
|
return Object.values(pks).map((it) => {
|
|
15274
15406
|
return {
|
|
@@ -15374,12 +15506,14 @@ var columnSchema = objectType({
|
|
|
15374
15506
|
name: stringType(),
|
|
15375
15507
|
type: stringType(),
|
|
15376
15508
|
primaryKey: booleanType().optional(),
|
|
15377
|
-
unique: booleanType().optional(),
|
|
15378
15509
|
default: anyType().optional(),
|
|
15379
15510
|
notNull: booleanType().optional(),
|
|
15380
15511
|
// should it be optional? should if be here?
|
|
15381
15512
|
autoincrement: booleanType().optional(),
|
|
15382
|
-
onUpdate: booleanType().optional()
|
|
15513
|
+
onUpdate: booleanType().optional(),
|
|
15514
|
+
isUnique: anyType().optional(),
|
|
15515
|
+
uniqueName: stringType().optional(),
|
|
15516
|
+
nullsNotDistinct: booleanType().optional()
|
|
15383
15517
|
}).strict();
|
|
15384
15518
|
var alteredColumnSchema = objectType({
|
|
15385
15519
|
name: makeSelfOrChanged(stringType()),
|
|
@@ -15405,7 +15539,8 @@ var tableScheme = objectType({
|
|
|
15405
15539
|
columns: recordType(stringType(), columnSchema),
|
|
15406
15540
|
indexes: recordType(stringType(), stringType()),
|
|
15407
15541
|
foreignKeys: recordType(stringType(), stringType()),
|
|
15408
|
-
compositePrimaryKeys: recordType(stringType(), stringType()).default({})
|
|
15542
|
+
compositePrimaryKeys: recordType(stringType(), stringType()).default({}),
|
|
15543
|
+
uniqueConstraints: recordType(stringType(), stringType()).default({})
|
|
15409
15544
|
}).strict();
|
|
15410
15545
|
var alteredTableScheme = objectType({
|
|
15411
15546
|
name: stringType(),
|
|
@@ -15439,6 +15574,15 @@ var alteredTableScheme = objectType({
|
|
|
15439
15574
|
__new: stringType(),
|
|
15440
15575
|
__old: stringType()
|
|
15441
15576
|
})
|
|
15577
|
+
),
|
|
15578
|
+
addedUniqueConstraints: recordType(stringType(), stringType()),
|
|
15579
|
+
deletedUniqueConstraints: recordType(stringType(), stringType()),
|
|
15580
|
+
alteredUniqueConstraints: recordType(
|
|
15581
|
+
stringType(),
|
|
15582
|
+
objectType({
|
|
15583
|
+
__new: stringType(),
|
|
15584
|
+
__old: stringType()
|
|
15585
|
+
})
|
|
15442
15586
|
)
|
|
15443
15587
|
}).strict();
|
|
15444
15588
|
var diffResultScheme = objectType({
|
|
@@ -15528,13 +15672,19 @@ var applySnapshotsDiff = async (json1, json2, dialect3, schemasResolver, tablesR
|
|
|
15528
15672
|
alteredForeignKeys: table4.alteredForeignKeys,
|
|
15529
15673
|
addedCompositePKs: table4.addedCompositePKs,
|
|
15530
15674
|
deletedCompositePKs: table4.deletedCompositePKs,
|
|
15531
|
-
alteredCompositePKs: table4.alteredCompositePKs
|
|
15675
|
+
alteredCompositePKs: table4.alteredCompositePKs,
|
|
15676
|
+
addedUniqueConstraints: table4.addedUniqueConstraints,
|
|
15677
|
+
deletedUniqueConstraints: table4.deletedUniqueConstraints,
|
|
15678
|
+
alteredUniqueConstraints: table4.alteredUniqueConstraints
|
|
15532
15679
|
};
|
|
15533
15680
|
allAlteredResolved.push(resolved);
|
|
15534
15681
|
}
|
|
15535
15682
|
const jsonAddedCompositePKs = [];
|
|
15536
15683
|
const jsonDeletedCompositePKs = [];
|
|
15537
15684
|
const jsonAlteredCompositePKs = [];
|
|
15685
|
+
const jsonAddedUniqueConstraints = [];
|
|
15686
|
+
const jsonDeletedUniqueConstraints = [];
|
|
15687
|
+
const jsonAlteredUniqueConstraints = [];
|
|
15538
15688
|
const jsonSetTableSchemas = [];
|
|
15539
15689
|
const jsonRemoveTableFromSchemas = [];
|
|
15540
15690
|
const jsonSetNewTableSchemas = [];
|
|
@@ -15626,6 +15776,33 @@ var applySnapshotsDiff = async (json1, json2, dialect3, schemasResolver, tablesR
|
|
|
15626
15776
|
curFull
|
|
15627
15777
|
);
|
|
15628
15778
|
}
|
|
15779
|
+
let addedUniqueConstraints = [];
|
|
15780
|
+
let deletedUniqueConstraints = [];
|
|
15781
|
+
let alteredUniqueConstraints = [];
|
|
15782
|
+
addedUniqueConstraints = prepareAddUniqueConstraintPg(
|
|
15783
|
+
it.name,
|
|
15784
|
+
schemaUnwrapped,
|
|
15785
|
+
it.addedUniqueConstraints
|
|
15786
|
+
);
|
|
15787
|
+
deletedUniqueConstraints = prepareDeleteUniqueConstraintPg(
|
|
15788
|
+
it.name,
|
|
15789
|
+
schemaUnwrapped,
|
|
15790
|
+
it.deletedUniqueConstraints
|
|
15791
|
+
);
|
|
15792
|
+
if (it.alteredUniqueConstraints) {
|
|
15793
|
+
const added = {};
|
|
15794
|
+
const deleted2 = {};
|
|
15795
|
+
for (const k of Object.keys(it.alteredUniqueConstraints)) {
|
|
15796
|
+
added[k] = it.alteredUniqueConstraints[k].__new;
|
|
15797
|
+
deleted2[k] = it.alteredUniqueConstraints[k].__old;
|
|
15798
|
+
}
|
|
15799
|
+
addedUniqueConstraints.push(
|
|
15800
|
+
...prepareAddUniqueConstraintPg(it.name, schemaUnwrapped, added)
|
|
15801
|
+
);
|
|
15802
|
+
deletedUniqueConstraints.push(
|
|
15803
|
+
...prepareDeleteUniqueConstraintPg(it.name, schemaUnwrapped, deleted2)
|
|
15804
|
+
);
|
|
15805
|
+
}
|
|
15629
15806
|
if (it.schema && typeof it.schema !== "string") {
|
|
15630
15807
|
switch (it.schema.type) {
|
|
15631
15808
|
case "added": {
|
|
@@ -15658,6 +15835,9 @@ var applySnapshotsDiff = async (json1, json2, dialect3, schemasResolver, tablesR
|
|
|
15658
15835
|
jsonAddedCompositePKs.push(...addedCompositePKs);
|
|
15659
15836
|
jsonDeletedCompositePKs.push(...deletedCompositePKs);
|
|
15660
15837
|
jsonAlteredCompositePKs.push(...alteredCompositePKs);
|
|
15838
|
+
jsonAddedUniqueConstraints.push(...addedUniqueConstraints);
|
|
15839
|
+
jsonDeletedUniqueConstraints.push(...deletedUniqueConstraints);
|
|
15840
|
+
jsonAlteredUniqueConstraints.push(...alteredUniqueConstraints);
|
|
15661
15841
|
});
|
|
15662
15842
|
const rColumns = jsonRenameColumnsStatements.map((it) => {
|
|
15663
15843
|
const tableName = it.tableName;
|
|
@@ -15782,6 +15962,7 @@ var applySnapshotsDiff = async (json1, json2, dialect3, schemasResolver, tablesR
|
|
|
15782
15962
|
jsonStatements.push(...jsonSQLiteCreateTables);
|
|
15783
15963
|
} else if (dialect3 === "pg") {
|
|
15784
15964
|
const jsonPgCreateTables = created.map((it) => {
|
|
15965
|
+
console.log(it);
|
|
15785
15966
|
return preparePgCreateTableJson(it, curFull);
|
|
15786
15967
|
});
|
|
15787
15968
|
jsonStatements.push(...jsonPgCreateTables);
|
|
@@ -15795,6 +15976,7 @@ var applySnapshotsDiff = async (json1, json2, dialect3, schemasResolver, tablesR
|
|
|
15795
15976
|
jsonStatements.push(...jsonRenameTables);
|
|
15796
15977
|
jsonStatements.push(...jsonRenameColumnsStatements);
|
|
15797
15978
|
jsonStatements.push(...jsonDeletedCompositePKs);
|
|
15979
|
+
jsonStatements.push(...jsonDeletedUniqueConstraints);
|
|
15798
15980
|
jsonStatements.push(...jsonDroppedReferencesForAlteredTables);
|
|
15799
15981
|
jsonStatements.push(...jsonDropIndexesForAllAlteredTables);
|
|
15800
15982
|
jsonStatements.push(...jsonTableAlternations.alterColumns);
|
|
@@ -15807,6 +15989,8 @@ var applySnapshotsDiff = async (json1, json2, dialect3, schemasResolver, tablesR
|
|
|
15807
15989
|
jsonStatements.push(...jsonCreateReferences);
|
|
15808
15990
|
jsonStatements.push(...jsonAddedCompositePKs);
|
|
15809
15991
|
jsonStatements.push(...jsonAlteredCompositePKs);
|
|
15992
|
+
jsonStatements.push(...jsonAddedUniqueConstraints);
|
|
15993
|
+
jsonStatements.push(...jsonAlteredUniqueConstraints);
|
|
15810
15994
|
jsonStatements.push(...jsonSetTableSchemas);
|
|
15811
15995
|
jsonStatements.push(...filteredJsonSetNewTableSchemas);
|
|
15812
15996
|
jsonStatements.push(...jsonRemoveTableFromSchemas);
|