drizzle-kit 0.19.11-6427e88 → 0.19.11-6f50bf8
Sign up to get free protection for your applications and to get access to all the features.
- package/index.cjs +35 -31
- 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");
|
@@ -12320,7 +12320,7 @@ ${withStyle.errorWarning(`We've found duplicated unique constraint names in ${so
|
|
12320
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
|
12321
12321
|
FROM pg_attribute a
|
12322
12322
|
JOIN INFORMATION_SCHEMA.COLUMNS ON INFORMATION_SCHEMA.COLUMNS.column_name = a.attname
|
12323
|
-
WHERE a.attrelid = '${tableSchema}
|
12323
|
+
WHERE a.attrelid = '"${tableSchema}"."${tableName}"'::regclass and INFORMATION_SCHEMA.COLUMNS.table_name = '${tableName}'
|
12324
12324
|
AND a.attnum > 0
|
12325
12325
|
AND NOT a.attisdropped
|
12326
12326
|
ORDER BY a.attnum;`
|
@@ -12879,17 +12879,12 @@ The unique constraint ${source_default.underline.blue(
|
|
12879
12879
|
WHERE m.type = 'table' and m.tbl_name != 'sqlite_sequence' and m.tbl_name != 'sqlite_stat1' and m.tbl_name != '_litestream_seq' and m.tbl_name != '_litestream_lock';
|
12880
12880
|
`
|
12881
12881
|
);
|
12882
|
-
const isSeqExists = await db.query(
|
12883
|
-
`SELECT * FROM sqlite_master WHERE type='table' AND name='sqlite_sequence';`
|
12884
|
-
);
|
12885
12882
|
const tablesWithSeq = [];
|
12886
|
-
|
12887
|
-
|
12888
|
-
|
12889
|
-
|
12890
|
-
|
12891
|
-
tablesWithSeq.push(s.name);
|
12892
|
-
}
|
12883
|
+
const seq = await db.query(
|
12884
|
+
`SELECT * FROM sqlite_master WHERE name != 'sqlite_sequence' and name != 'sqlite_stat1' and name != '_litestream_seq' and name != '_litestream_lock' and sql GLOB '*[ *' || CHAR(9) || CHAR(10) || CHAR(13) || ']AUTOINCREMENT[^'']*';`
|
12885
|
+
);
|
12886
|
+
for (const s of seq) {
|
12887
|
+
tablesWithSeq.push(s.name);
|
12893
12888
|
}
|
12894
12889
|
let columnsCount = 0;
|
12895
12890
|
let tablesCount = /* @__PURE__ */ new Set();
|
@@ -16576,6 +16571,7 @@ var init_jsonStatements = __esm({
|
|
16576
16571
|
const columnNotNull = json2.tables[tableName].columns[columnName].notNull;
|
16577
16572
|
const columnAutoIncrement = json2.tables[tableName].columns[columnName].autoincrement;
|
16578
16573
|
const columnPk = json2.tables[tableName].columns[columnName].primaryKey;
|
16574
|
+
const compositePk = json2.tables[tableName].compositePrimaryKeys[`${tableName}_${columnName}`];
|
16579
16575
|
if (typeof column7.name !== "string") {
|
16580
16576
|
statements.push({
|
16581
16577
|
type: "alter_table_rename_column",
|
@@ -16600,7 +16596,7 @@ var init_jsonStatements = __esm({
|
|
16600
16596
|
columnPk
|
16601
16597
|
});
|
16602
16598
|
}
|
16603
|
-
if (((_e = column7.primaryKey) == null ? void 0 : _e.type) === "deleted" || ((_f = column7.primaryKey) == null ? void 0 : _f.type) === "changed" && !column7.primaryKey.new) {
|
16599
|
+
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") {
|
16604
16600
|
dropPkStatements.push({
|
16605
16601
|
////
|
16606
16602
|
type: "alter_table_alter_column_drop_pk",
|
@@ -16879,15 +16875,22 @@ var init_jsonStatements = __esm({
|
|
16879
16875
|
};
|
16880
16876
|
});
|
16881
16877
|
};
|
16882
|
-
prepareAddCompositePrimaryKeyMySql = (tableName, pks, json2) => {
|
16883
|
-
|
16884
|
-
|
16878
|
+
prepareAddCompositePrimaryKeyMySql = (tableName, pks, json1, json2) => {
|
16879
|
+
var _a, _b;
|
16880
|
+
const res = [];
|
16881
|
+
for (const it of Object.values(pks)) {
|
16882
|
+
const unsquashed = MySqlSquasher.unsquashPK(it);
|
16883
|
+
if (unsquashed.columns.length === 1 && ((_b = (_a = json1.tables[tableName]) == null ? void 0 : _a.columns[unsquashed.columns[0]]) == null ? void 0 : _b.primaryKey)) {
|
16884
|
+
continue;
|
16885
|
+
}
|
16886
|
+
res.push({
|
16885
16887
|
type: "create_composite_pk",
|
16886
16888
|
tableName,
|
16887
16889
|
data: it,
|
16888
|
-
constraintName: json2.tables[tableName].compositePrimaryKeys[`${tableName}_${
|
16889
|
-
};
|
16890
|
-
}
|
16890
|
+
constraintName: json2.tables[tableName].compositePrimaryKeys[`${tableName}_${unsquashed.columns.join("_")}`].name
|
16891
|
+
});
|
16892
|
+
}
|
16893
|
+
return res;
|
16891
16894
|
};
|
16892
16895
|
prepareDeleteCompositePrimaryKeyMySql = (tableName, pks, json1) => {
|
16893
16896
|
return Object.values(pks).map((it) => {
|
@@ -17280,6 +17283,7 @@ var init_snapshotsDiffer = __esm({
|
|
17280
17283
|
addedCompositePKs = prepareAddCompositePrimaryKeyMySql(
|
17281
17284
|
it.name,
|
17282
17285
|
it.addedCompositePKs,
|
17286
|
+
prevFull,
|
17283
17287
|
curFull
|
17284
17288
|
);
|
17285
17289
|
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(
|