drizzle-kit 0.19.11-920c1f3 → 0.19.12-2157698

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.
Files changed (3) hide show
  1. package/index.cjs +42 -34
  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");
@@ -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
- if (isSeqExists.length > 0) {
12887
- const seq = await db.query(
12888
- `SELECT * FROM sqlite_sequence WHERE name != 'sqlite_sequence' and name != 'sqlite_stat1' and name != '_litestream_seq' and name != '_litestream_lock';`
12889
- );
12890
- for (const s of seq) {
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();
@@ -12925,7 +12920,7 @@ The unique constraint ${source_default.underline.blue(
12925
12920
  const newColumn = {
12926
12921
  default: columnDefault === null ? void 0 : /^-?[\d.]+(?:e-?\d+)?$/.test(columnDefault) ? Number(columnDefault) : ["CURRENT_TIME", "CURRENT_DATE", "CURRENT_TIMESTAMP"].includes(
12927
12922
  columnDefault
12928
- ) ? `(${columnDefault})` : columnDefault === "false" ? false : columnDefault === "true" ? true : columnDefault.startsWith('"') && columnDefault.endsWith('"') ? columnDefault.substring(1, columnDefault.length - 1) : columnDefault,
12923
+ ) ? `(${columnDefault})` : columnDefault === "false" ? false : columnDefault === "true" ? true : columnDefault.startsWith("'") && columnDefault.endsWith("'") ? columnDefault : `(${columnDefault})`,
12929
12924
  autoincrement: isAutoincrement,
12930
12925
  name: columnName,
12931
12926
  type: mapSqlToSqliteType(columnType),
@@ -13026,7 +13021,7 @@ FROM sqlite_master AS m,
13026
13021
  pragma_index_list(m.name) AS il,
13027
13022
  pragma_index_info(il.name) AS ii
13028
13023
  WHERE
13029
- m.type = 'table';`
13024
+ m.type = 'table' and il.name NOT LIKE 'sqlite_autoindex_%';`
13030
13025
  );
13031
13026
  for (const idxRow of idxs) {
13032
13027
  const tableName = idxRow.tableName;
@@ -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
- return Object.values(pks).map((it) => {
16884
- return {
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}_${MySqlSquasher.unsquashPK(it).columns.join("_")}`].name
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(
@@ -35930,6 +35934,7 @@ var init_mysql_introspect = __esm({
35930
35934
  patched = patched.startsWith("enum(") ? "mysqlEnum" : patched;
35931
35935
  patched = patched.startsWith("datetime(") ? "datetime" : patched;
35932
35936
  patched = patched.startsWith("varbinary(") ? "varbinary" : patched;
35937
+ patched = patched.startsWith("int(") ? "int" : patched;
35933
35938
  return patched;
35934
35939
  }).filter((type) => {
35935
35940
  return mysqlImportsList.has(type);
@@ -43080,6 +43085,9 @@ import { sql } from "drizzle-orm"
43080
43085
  if (defaultValue === "NULL") {
43081
43086
  return `sql\`NULL\``;
43082
43087
  }
43088
+ if (typeof defaultValue === "string" && defaultValue.startsWith("'") && defaultValue.endsWith("'")) {
43089
+ return defaultValue.substring(1, defaultValue.length - 1);
43090
+ }
43083
43091
  return defaultValue;
43084
43092
  };
43085
43093
  column6 = (type, name, defaultValue, autoincrement, casing) => {
@@ -43096,7 +43104,7 @@ import { sql } from "drizzle-orm"
43096
43104
  }
43097
43105
  if (lowered === "text") {
43098
43106
  let out = `${withCasing3(name, casing)}: text("${name}")`;
43099
- out += defaultValue ? `.default(${mapColumnDefault2(defaultValue)})` : "";
43107
+ out += defaultValue ? `.default("${mapColumnDefault2(defaultValue)}")` : "";
43100
43108
  return out;
43101
43109
  }
43102
43110
  if (lowered === "blob") {
@@ -52118,7 +52126,7 @@ init_source();
52118
52126
  // package.json
52119
52127
  var package_default = {
52120
52128
  name: "drizzle-kit",
52121
- version: "0.19.11",
52129
+ version: "0.19.12",
52122
52130
  repository: "https://github.com/drizzle-team/drizzle-kit-mirror",
52123
52131
  author: "Drizzle Team",
52124
52132
  license: "MIT",
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.12-2157698",
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(