drizzle-kit 0.19.10 → 0.19.11-052f5fd

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 +55 -40
  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");
@@ -12060,7 +12060,7 @@ var init_pgSerializer = __esm({
12060
12060
  indexName2 = (tableName, columns) => {
12061
12061
  return `${tableName}_${columns.join("_")}_index`;
12062
12062
  };
12063
- generatePgSnapshot = (tables, enums, schemas, schemaFilter = ["public"]) => {
12063
+ generatePgSnapshot = (tables, enums, schemas, schemaFilter) => {
12064
12064
  const result = {};
12065
12065
  for (const table4 of tables) {
12066
12066
  const {
@@ -12073,7 +12073,7 @@ var init_pgSerializer = __esm({
12073
12073
  primaryKeys,
12074
12074
  uniqueConstraints
12075
12075
  } = (0, import_pg_core3.getTableConfig)(table4);
12076
- if (!schemaFilter.includes(schema4 ?? "public")) {
12076
+ if (schemaFilter && !schemaFilter.includes(schema4 ?? "public")) {
12077
12077
  continue;
12078
12078
  }
12079
12079
  const columnsObject = {};
@@ -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) => it.schemaName !== "public" && schemaFilter.includes(it.schemaName)
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}.${tableName}'::regclass and INFORMATION_SCHEMA.COLUMNS.table_name = '${tableName}'
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;`
@@ -12871,17 +12879,12 @@ The unique constraint ${source_default.underline.blue(
12871
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';
12872
12880
  `
12873
12881
  );
12874
- const isSeqExists = await db.query(
12875
- `SELECT * FROM sqlite_master WHERE type='table' AND name='sqlite_sequence';`
12876
- );
12877
12882
  const tablesWithSeq = [];
12878
- if (isSeqExists.length > 0) {
12879
- const seq = await db.query(
12880
- `SELECT * FROM sqlite_sequence WHERE name != 'sqlite_sequence' and name != 'sqlite_stat1' and name != '_litestream_seq' and name != '_litestream_lock';`
12881
- );
12882
- for (const s of seq) {
12883
- tablesWithSeq.push(s.name);
12884
- }
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);
12885
12888
  }
12886
12889
  let columnsCount = 0;
12887
12890
  let tablesCount = /* @__PURE__ */ new Set();
@@ -12917,7 +12920,7 @@ The unique constraint ${source_default.underline.blue(
12917
12920
  const newColumn = {
12918
12921
  default: columnDefault === null ? void 0 : /^-?[\d.]+(?:e-?\d+)?$/.test(columnDefault) ? Number(columnDefault) : ["CURRENT_TIME", "CURRENT_DATE", "CURRENT_TIMESTAMP"].includes(
12919
12922
  columnDefault
12920
- ) ? `(${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})`,
12921
12924
  autoincrement: isAutoincrement,
12922
12925
  name: columnName,
12923
12926
  type: mapSqlToSqliteType(columnType),
@@ -13018,7 +13021,7 @@ FROM sqlite_master AS m,
13018
13021
  pragma_index_list(m.name) AS il,
13019
13022
  pragma_index_info(il.name) AS ii
13020
13023
  WHERE
13021
- m.type = 'table';`
13024
+ m.type = 'table' and il.name NOT LIKE 'sqlite_autoindex_%';`
13022
13025
  );
13023
13026
  for (const idxRow of idxs) {
13024
13027
  const tableName = idxRow.tableName;
@@ -13091,7 +13094,7 @@ ${filenames.join("\n")}
13091
13094
  const { tables, enums, schemas } = await prepareFromMySqlImports2(filenames);
13092
13095
  return generateMySqlSnapshot2(tables, enums, schemas);
13093
13096
  };
13094
- serializePg = async (path3, schemaFilter = ["public"]) => {
13097
+ serializePg = async (path3, schemaFilter) => {
13095
13098
  const filenames = prepareFilenames(path3);
13096
13099
  const { prepareFromPgImports: prepareFromPgImports2 } = await Promise.resolve().then(() => (init_pgImports(), pgImports_exports));
13097
13100
  const { generatePgSnapshot: generatePgSnapshot2 } = await Promise.resolve().then(() => (init_pgSerializer(), pgSerializer_exports));
@@ -13149,7 +13152,7 @@ var init_migrationPreparator = __esm({
13149
13152
  const result = { version: version2, dialect: dialect6, id, prevId: idPrev, ...rest };
13150
13153
  return { prev, cur: result };
13151
13154
  };
13152
- preparePgDbPushSnapshot = async (prev, schemaPath, schemaFilter) => {
13155
+ preparePgDbPushSnapshot = async (prev, schemaPath, schemaFilter = ["public"]) => {
13153
13156
  const serialized = await serializePg(schemaPath, schemaFilter);
13154
13157
  const id = (0, import_crypto.randomUUID)();
13155
13158
  const idPrev = prev.id;
@@ -16568,6 +16571,7 @@ var init_jsonStatements = __esm({
16568
16571
  const columnNotNull = json2.tables[tableName].columns[columnName].notNull;
16569
16572
  const columnAutoIncrement = json2.tables[tableName].columns[columnName].autoincrement;
16570
16573
  const columnPk = json2.tables[tableName].columns[columnName].primaryKey;
16574
+ const compositePk = json2.tables[tableName].compositePrimaryKeys[`${tableName}_${columnName}`];
16571
16575
  if (typeof column7.name !== "string") {
16572
16576
  statements.push({
16573
16577
  type: "alter_table_rename_column",
@@ -16592,7 +16596,7 @@ var init_jsonStatements = __esm({
16592
16596
  columnPk
16593
16597
  });
16594
16598
  }
16595
- 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") {
16596
16600
  dropPkStatements.push({
16597
16601
  ////
16598
16602
  type: "alter_table_alter_column_drop_pk",
@@ -16871,15 +16875,22 @@ var init_jsonStatements = __esm({
16871
16875
  };
16872
16876
  });
16873
16877
  };
16874
- prepareAddCompositePrimaryKeyMySql = (tableName, pks, json2) => {
16875
- return Object.values(pks).map((it) => {
16876
- 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({
16877
16887
  type: "create_composite_pk",
16878
16888
  tableName,
16879
16889
  data: it,
16880
- constraintName: json2.tables[tableName].compositePrimaryKeys[`${tableName}_${MySqlSquasher.unsquashPK(it).columns.join("_")}`].name
16881
- };
16882
- });
16890
+ constraintName: json2.tables[tableName].compositePrimaryKeys[`${tableName}_${unsquashed.columns.join("_")}`].name
16891
+ });
16892
+ }
16893
+ return res;
16883
16894
  };
16884
16895
  prepareDeleteCompositePrimaryKeyMySql = (tableName, pks, json1) => {
16885
16896
  return Object.values(pks).map((it) => {
@@ -17272,6 +17283,7 @@ var init_snapshotsDiffer = __esm({
17272
17283
  addedCompositePKs = prepareAddCompositePrimaryKeyMySql(
17273
17284
  it.name,
17274
17285
  it.addedCompositePKs,
17286
+ prevFull,
17275
17287
  curFull
17276
17288
  );
17277
17289
  deletedCompositePKs = prepareDeleteCompositePrimaryKeyMySql(
@@ -43072,6 +43084,9 @@ import { sql } from "drizzle-orm"
43072
43084
  if (defaultValue === "NULL") {
43073
43085
  return `sql\`NULL\``;
43074
43086
  }
43087
+ if (typeof defaultValue === "string" && defaultValue.startsWith("'") && defaultValue.endsWith("'")) {
43088
+ return defaultValue.substring(1, defaultValue.length - 1);
43089
+ }
43075
43090
  return defaultValue;
43076
43091
  };
43077
43092
  column6 = (type, name, defaultValue, autoincrement, casing) => {
@@ -43088,7 +43103,7 @@ import { sql } from "drizzle-orm"
43088
43103
  }
43089
43104
  if (lowered === "text") {
43090
43105
  let out = `${withCasing3(name, casing)}: text("${name}")`;
43091
- out += defaultValue ? `.default(${mapColumnDefault2(defaultValue)})` : "";
43106
+ out += defaultValue ? `.default("${mapColumnDefault2(defaultValue)}")` : "";
43092
43107
  return out;
43093
43108
  }
43094
43109
  if (lowered === "blob") {
@@ -52110,7 +52125,7 @@ init_source();
52110
52125
  // package.json
52111
52126
  var package_default = {
52112
52127
  name: "drizzle-kit",
52113
- version: "0.19.10",
52128
+ version: "0.19.11",
52114
52129
  repository: "https://github.com/drizzle-team/drizzle-kit-mirror",
52115
52130
  author: "Drizzle Team",
52116
52131
  license: "MIT",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "drizzle-kit",
3
- "version": "0.19.10",
3
+ "version": "0.19.11-052f5fd",
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(