drizzle-kit 0.19.11-920c1f3 → 0.19.11

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. package/index.cjs +29 -20
  2. package/package.json +1 -1
  3. 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
- if (value.length > 1) {
11866
- result[key].compositePrimaryKeys = {
11867
- [`${key}_${value.sort().join("_")}`]: {
11868
- name: `${key}_${value.join("_")}`,
11869
- columns: value.sort()
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");
@@ -16576,6 +16576,7 @@ var init_jsonStatements = __esm({
16576
16576
  const columnNotNull = json2.tables[tableName].columns[columnName].notNull;
16577
16577
  const columnAutoIncrement = json2.tables[tableName].columns[columnName].autoincrement;
16578
16578
  const columnPk = json2.tables[tableName].columns[columnName].primaryKey;
16579
+ const compositePk = json2.tables[tableName].compositePrimaryKeys[`${tableName}_${columnName}`];
16579
16580
  if (typeof column7.name !== "string") {
16580
16581
  statements.push({
16581
16582
  type: "alter_table_rename_column",
@@ -16600,7 +16601,7 @@ var init_jsonStatements = __esm({
16600
16601
  columnPk
16601
16602
  });
16602
16603
  }
16603
- 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") {
16604
16605
  dropPkStatements.push({
16605
16606
  ////
16606
16607
  type: "alter_table_alter_column_drop_pk",
@@ -16879,15 +16880,22 @@ var init_jsonStatements = __esm({
16879
16880
  };
16880
16881
  });
16881
16882
  };
16882
- prepareAddCompositePrimaryKeyMySql = (tableName, pks, json2) => {
16883
- return Object.values(pks).map((it) => {
16884
- return {
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({
16885
16892
  type: "create_composite_pk",
16886
16893
  tableName,
16887
16894
  data: it,
16888
- constraintName: json2.tables[tableName].compositePrimaryKeys[`${tableName}_${MySqlSquasher.unsquashPK(it).columns.join("_")}`].name
16889
- };
16890
- });
16895
+ constraintName: json2.tables[tableName].compositePrimaryKeys[`${tableName}_${unsquashed.columns.join("_")}`].name
16896
+ });
16897
+ }
16898
+ return res;
16891
16899
  };
16892
16900
  prepareDeleteCompositePrimaryKeyMySql = (tableName, pks, json1) => {
16893
16901
  return Object.values(pks).map((it) => {
@@ -17280,6 +17288,7 @@ var init_snapshotsDiffer = __esm({
17280
17288
  addedCompositePKs = prepareAddCompositePrimaryKeyMySql(
17281
17289
  it.name,
17282
17290
  it.addedCompositePKs,
17291
+ prevFull,
17283
17292
  curFull
17284
17293
  );
17285
17294
  deletedCompositePKs = prepareDeleteCompositePrimaryKeyMySql(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "drizzle-kit",
3
- "version": "0.19.11-920c1f3",
3
+ "version": "0.19.11",
4
4
  "repository": "https://github.com/drizzle-team/drizzle-kit-mirror",
5
5
  "author": "Drizzle Team",
6
6
  "license": "MIT",
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
- return Object.values(pks).map((it) => {
15486
- return {
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}_${MySqlSquasher.unsquashPK(it).columns.join("_")}`].name
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(