drizzle-kit 0.19.11-744600d → 0.19.11-81b40a4
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 +39 -22
- package/package.json +1 -1
- package/utils.js +16 -7
package/index.cjs
CHANGED
|
@@ -11539,16 +11539,21 @@ var init_mysqlSerializer = __esm({
|
|
|
11539
11539
|
const uniqueConstraintObject = {};
|
|
11540
11540
|
columns.forEach((column7) => {
|
|
11541
11541
|
const notNull = column7.notNull;
|
|
11542
|
-
const primaryKey = column7.primary;
|
|
11543
11542
|
const sqlTypeLowered = column7.getSQLType().toLowerCase();
|
|
11544
11543
|
const columnToSet = {
|
|
11545
11544
|
name: column7.name,
|
|
11546
11545
|
type: column7.getSQLType(),
|
|
11547
|
-
primaryKey,
|
|
11546
|
+
primaryKey: false,
|
|
11548
11547
|
notNull,
|
|
11549
11548
|
autoincrement: typeof column7.autoIncrement === "undefined" ? false : column7.autoIncrement,
|
|
11550
11549
|
onUpdate: column7.hasOnUpdateNow
|
|
11551
11550
|
};
|
|
11551
|
+
if (column7.primary) {
|
|
11552
|
+
primaryKeysObject[`${tableName}_${column7.name}`] = {
|
|
11553
|
+
name: `${tableName}_${column7.name}`,
|
|
11554
|
+
columns: [column7.name]
|
|
11555
|
+
};
|
|
11556
|
+
}
|
|
11552
11557
|
if (column7.isUnique) {
|
|
11553
11558
|
const existingUnique = uniqueConstraintObject[column7.uniqueName];
|
|
11554
11559
|
if (typeof existingUnique !== "undefined") {
|
|
@@ -11862,17 +11867,12 @@ We have encountered a collision between the index name on columns ${source_defau
|
|
|
11862
11867
|
}
|
|
11863
11868
|
}
|
|
11864
11869
|
for (const [key, value] of Object.entries(tableToPk)) {
|
|
11865
|
-
|
|
11866
|
-
|
|
11867
|
-
|
|
11868
|
-
|
|
11869
|
-
|
|
11870
|
-
|
|
11871
|
-
};
|
|
11872
|
-
} else if (value.length === 1) {
|
|
11873
|
-
result[key].columns[value[0]].primaryKey = true;
|
|
11874
|
-
} else {
|
|
11875
|
-
}
|
|
11870
|
+
result[key].compositePrimaryKeys = {
|
|
11871
|
+
[`${key}_${value.sort().join("_")}`]: {
|
|
11872
|
+
name: `${key}_${value.join("_")}`,
|
|
11873
|
+
columns: value.sort()
|
|
11874
|
+
}
|
|
11875
|
+
};
|
|
11876
11876
|
}
|
|
11877
11877
|
if (progressCallback) {
|
|
11878
11878
|
progressCallback("columns", columnsCount, "done");
|
|
@@ -12240,7 +12240,15 @@ ${withStyle.errorWarning(`We've found duplicated unique constraint names in ${so
|
|
|
12240
12240
|
}, {});
|
|
12241
12241
|
const schemasObject = Object.fromEntries(
|
|
12242
12242
|
schemas.filter(
|
|
12243
|
-
(it) =>
|
|
12243
|
+
(it) => {
|
|
12244
|
+
if (it.schemaName !== "public")
|
|
12245
|
+
return true;
|
|
12246
|
+
if (schemaFilter) {
|
|
12247
|
+
return schemaFilter.includes(it.schemaName);
|
|
12248
|
+
} else {
|
|
12249
|
+
return true;
|
|
12250
|
+
}
|
|
12251
|
+
}
|
|
12244
12252
|
).map((it) => [it.schemaName, it.schemaName])
|
|
12245
12253
|
);
|
|
12246
12254
|
return {
|
|
@@ -12312,7 +12320,7 @@ ${withStyle.errorWarning(`We've found duplicated unique constraint names in ${so
|
|
|
12312
12320
|
END AS data_type, INFORMATION_SCHEMA.COLUMNS.table_name, INFORMATION_SCHEMA.COLUMNS.column_name, INFORMATION_SCHEMA.COLUMNS.column_default, INFORMATION_SCHEMA.COLUMNS.data_type as additional_dt
|
|
12313
12321
|
FROM pg_attribute a
|
|
12314
12322
|
JOIN INFORMATION_SCHEMA.COLUMNS ON INFORMATION_SCHEMA.COLUMNS.column_name = a.attname
|
|
12315
|
-
WHERE a.attrelid = '${tableSchema}
|
|
12323
|
+
WHERE a.attrelid = '"${tableSchema}"."${tableName}"'::regclass and INFORMATION_SCHEMA.COLUMNS.table_name = '${tableName}'
|
|
12316
12324
|
AND a.attnum > 0
|
|
12317
12325
|
AND NOT a.attisdropped
|
|
12318
12326
|
ORDER BY a.attnum;`
|
|
@@ -16568,6 +16576,7 @@ var init_jsonStatements = __esm({
|
|
|
16568
16576
|
const columnNotNull = json2.tables[tableName].columns[columnName].notNull;
|
|
16569
16577
|
const columnAutoIncrement = json2.tables[tableName].columns[columnName].autoincrement;
|
|
16570
16578
|
const columnPk = json2.tables[tableName].columns[columnName].primaryKey;
|
|
16579
|
+
const compositePk = json2.tables[tableName].compositePrimaryKeys[`${tableName}_${columnName}`];
|
|
16571
16580
|
if (typeof column7.name !== "string") {
|
|
16572
16581
|
statements.push({
|
|
16573
16582
|
type: "alter_table_rename_column",
|
|
@@ -16592,7 +16601,7 @@ var init_jsonStatements = __esm({
|
|
|
16592
16601
|
columnPk
|
|
16593
16602
|
});
|
|
16594
16603
|
}
|
|
16595
|
-
if (((_e = column7.primaryKey) == null ? void 0 : _e.type) === "deleted" || ((_f = column7.primaryKey) == null ? void 0 : _f.type) === "changed" && !column7.primaryKey.new) {
|
|
16604
|
+
if (((_e = column7.primaryKey) == null ? void 0 : _e.type) === "deleted" || ((_f = column7.primaryKey) == null ? void 0 : _f.type) === "changed" && !column7.primaryKey.new && typeof compositePk === "undefined") {
|
|
16596
16605
|
dropPkStatements.push({
|
|
16597
16606
|
////
|
|
16598
16607
|
type: "alter_table_alter_column_drop_pk",
|
|
@@ -16871,15 +16880,22 @@ var init_jsonStatements = __esm({
|
|
|
16871
16880
|
};
|
|
16872
16881
|
});
|
|
16873
16882
|
};
|
|
16874
|
-
prepareAddCompositePrimaryKeyMySql = (tableName, pks, json2) => {
|
|
16875
|
-
|
|
16876
|
-
|
|
16883
|
+
prepareAddCompositePrimaryKeyMySql = (tableName, pks, json1, json2) => {
|
|
16884
|
+
var _a, _b;
|
|
16885
|
+
const res = [];
|
|
16886
|
+
for (const it of Object.values(pks)) {
|
|
16887
|
+
const unsquashed = MySqlSquasher.unsquashPK(it);
|
|
16888
|
+
if (unsquashed.columns.length === 1 && ((_b = (_a = json1.tables[tableName]) == null ? void 0 : _a.columns[unsquashed.columns[0]]) == null ? void 0 : _b.primaryKey)) {
|
|
16889
|
+
continue;
|
|
16890
|
+
}
|
|
16891
|
+
res.push({
|
|
16877
16892
|
type: "create_composite_pk",
|
|
16878
16893
|
tableName,
|
|
16879
16894
|
data: it,
|
|
16880
|
-
constraintName: json2.tables[tableName].compositePrimaryKeys[`${tableName}_${
|
|
16881
|
-
};
|
|
16882
|
-
}
|
|
16895
|
+
constraintName: json2.tables[tableName].compositePrimaryKeys[`${tableName}_${unsquashed.columns.join("_")}`].name
|
|
16896
|
+
});
|
|
16897
|
+
}
|
|
16898
|
+
return res;
|
|
16883
16899
|
};
|
|
16884
16900
|
prepareDeleteCompositePrimaryKeyMySql = (tableName, pks, json1) => {
|
|
16885
16901
|
return Object.values(pks).map((it) => {
|
|
@@ -17272,6 +17288,7 @@ var init_snapshotsDiffer = __esm({
|
|
|
17272
17288
|
addedCompositePKs = prepareAddCompositePrimaryKeyMySql(
|
|
17273
17289
|
it.name,
|
|
17274
17290
|
it.addedCompositePKs,
|
|
17291
|
+
prevFull,
|
|
17275
17292
|
curFull
|
|
17276
17293
|
);
|
|
17277
17294
|
deletedCompositePKs = prepareDeleteCompositePrimaryKeyMySql(
|
package/package.json
CHANGED
package/utils.js
CHANGED
|
@@ -15178,6 +15178,7 @@ var _prepareAlterColumns = (tableName, schema4, columns, json2) => {
|
|
|
15178
15178
|
const columnNotNull = json2.tables[tableName].columns[columnName].notNull;
|
|
15179
15179
|
const columnAutoIncrement = json2.tables[tableName].columns[columnName].autoincrement;
|
|
15180
15180
|
const columnPk = json2.tables[tableName].columns[columnName].primaryKey;
|
|
15181
|
+
const compositePk = json2.tables[tableName].compositePrimaryKeys[`${tableName}_${columnName}`];
|
|
15181
15182
|
if (typeof column4.name !== "string") {
|
|
15182
15183
|
statements.push({
|
|
15183
15184
|
type: "alter_table_rename_column",
|
|
@@ -15202,7 +15203,7 @@ var _prepareAlterColumns = (tableName, schema4, columns, json2) => {
|
|
|
15202
15203
|
columnPk
|
|
15203
15204
|
});
|
|
15204
15205
|
}
|
|
15205
|
-
if (((_e = column4.primaryKey) == null ? void 0 : _e.type) === "deleted" || ((_f = column4.primaryKey) == null ? void 0 : _f.type) === "changed" && !column4.primaryKey.new) {
|
|
15206
|
+
if (((_e = column4.primaryKey) == null ? void 0 : _e.type) === "deleted" || ((_f = column4.primaryKey) == null ? void 0 : _f.type) === "changed" && !column4.primaryKey.new && typeof compositePk === "undefined") {
|
|
15206
15207
|
dropPkStatements.push({
|
|
15207
15208
|
////
|
|
15208
15209
|
type: "alter_table_alter_column_drop_pk",
|
|
@@ -15481,15 +15482,22 @@ var prepareDeleteUniqueConstraintPg = (tableName, schema4, unqs) => {
|
|
|
15481
15482
|
};
|
|
15482
15483
|
});
|
|
15483
15484
|
};
|
|
15484
|
-
var prepareAddCompositePrimaryKeyMySql = (tableName, pks, json2) => {
|
|
15485
|
-
|
|
15486
|
-
|
|
15485
|
+
var prepareAddCompositePrimaryKeyMySql = (tableName, pks, json1, json2) => {
|
|
15486
|
+
var _a, _b;
|
|
15487
|
+
const res = [];
|
|
15488
|
+
for (const it of Object.values(pks)) {
|
|
15489
|
+
const unsquashed = MySqlSquasher.unsquashPK(it);
|
|
15490
|
+
if (unsquashed.columns.length === 1 && ((_b = (_a = json1.tables[tableName]) == null ? void 0 : _a.columns[unsquashed.columns[0]]) == null ? void 0 : _b.primaryKey)) {
|
|
15491
|
+
continue;
|
|
15492
|
+
}
|
|
15493
|
+
res.push({
|
|
15487
15494
|
type: "create_composite_pk",
|
|
15488
15495
|
tableName,
|
|
15489
15496
|
data: it,
|
|
15490
|
-
constraintName: json2.tables[tableName].compositePrimaryKeys[`${tableName}_${
|
|
15491
|
-
};
|
|
15492
|
-
}
|
|
15497
|
+
constraintName: json2.tables[tableName].compositePrimaryKeys[`${tableName}_${unsquashed.columns.join("_")}`].name
|
|
15498
|
+
});
|
|
15499
|
+
}
|
|
15500
|
+
return res;
|
|
15493
15501
|
};
|
|
15494
15502
|
var prepareDeleteCompositePrimaryKeyMySql = (tableName, pks, json1) => {
|
|
15495
15503
|
return Object.values(pks).map((it) => {
|
|
@@ -15870,6 +15878,7 @@ var applySnapshotsDiff = async (json1, json2, dialect3, schemasResolver, tablesR
|
|
|
15870
15878
|
addedCompositePKs = prepareAddCompositePrimaryKeyMySql(
|
|
15871
15879
|
it.name,
|
|
15872
15880
|
it.addedCompositePKs,
|
|
15881
|
+
prevFull,
|
|
15873
15882
|
curFull
|
|
15874
15883
|
);
|
|
15875
15884
|
deletedCompositePKs = prepareDeleteCompositePrimaryKeyMySql(
|