drizzle-kit 0.19.5 → 0.19.6-8c1d0e5

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 +77 -15
  2. package/package.json +1 -1
  3. package/utils.js +35 -6
package/index.cjs CHANGED
@@ -4656,7 +4656,8 @@ var init_mysqlSchema = __esm({
4656
4656
  columns: recordType(stringType(), column),
4657
4657
  indexes: recordType(stringType(), stringType()),
4658
4658
  foreignKeys: recordType(stringType(), stringType()),
4659
- compositePrimaryKeys: recordType(stringType(), stringType())
4659
+ compositePrimaryKeys: recordType(stringType(), stringType()),
4660
+ uniqueConstraints: recordType(stringType(), stringType()).default({})
4660
4661
  }).strict();
4661
4662
  schemaSquashed = objectType({
4662
4663
  version: literalType("5"),
@@ -5228,7 +5229,8 @@ var init_sqliteSchema = __esm({
5228
5229
  columns: recordType(stringType(), column3),
5229
5230
  indexes: recordType(stringType(), stringType()),
5230
5231
  foreignKeys: recordType(stringType(), stringType()),
5231
- compositePrimaryKeys: recordType(stringType(), stringType())
5232
+ compositePrimaryKeys: recordType(stringType(), stringType()),
5233
+ uniqueConstraints: recordType(stringType(), stringType()).default({})
5232
5234
  }).strict();
5233
5235
  schemaSquashed2 = objectType({
5234
5236
  version: latestVersion,
@@ -11645,6 +11647,27 @@ The unique constraint ${source_default.underline.blue(
11645
11647
  return it.name;
11646
11648
  }
11647
11649
  });
11650
+ if (value.config.unique) {
11651
+ if (typeof uniqueConstraintObject[name] !== "undefined") {
11652
+ console.log(
11653
+ `
11654
+ ${withStyle.errorWarning(
11655
+ `We've found duplicated unique constraint names in ${source_default.underline.blue(
11656
+ tableName
11657
+ )} table.
11658
+ The unique index ${source_default.underline.blue(
11659
+ name
11660
+ )} on the ${source_default.underline.blue(
11661
+ indexColumns.join(",")
11662
+ )} columns is confilcting with a unique constraint name already defined for ${source_default.underline.blue(
11663
+ uniqueConstraintObject[name].columns.join(",")
11664
+ )} columns
11665
+ `
11666
+ )}`
11667
+ );
11668
+ process.exit(1);
11669
+ }
11670
+ }
11648
11671
  indexesObject[name] = {
11649
11672
  name,
11650
11673
  columns: indexColumns,
@@ -11690,7 +11713,6 @@ The unique constraint ${source_default.underline.blue(
11690
11713
  let tablesCount = /* @__PURE__ */ new Set();
11691
11714
  let indexesCount = 0;
11692
11715
  let foreignKeysCount = 0;
11693
- const tableToPk = {};
11694
11716
  for (const column7 of response) {
11695
11717
  if (!tablesFilter(column7["TABLE_NAME"]))
11696
11718
  continue;
@@ -11719,13 +11741,6 @@ The unique constraint ${source_default.underline.blue(
11719
11741
  isAutoincrement = column7["EXTRA"] === "auto_increment";
11720
11742
  isDefaultAnExpression = column7["EXTRA"].includes("DEFAULT_GENERATED");
11721
11743
  }
11722
- if (isPrimary) {
11723
- if (typeof tableToPk[tableName] === "undefined") {
11724
- tableToPk[tableName] = [columnName];
11725
- } else {
11726
- tableToPk[tableName].push(columnName);
11727
- }
11728
- }
11729
11744
  if (schema4 !== inputSchema) {
11730
11745
  schemas.push(schema4);
11731
11746
  }
@@ -11763,6 +11778,26 @@ The unique constraint ${source_default.underline.blue(
11763
11778
  result[tableName].columns[columnName] = newColumn;
11764
11779
  }
11765
11780
  }
11781
+ const tablePks = await db.execute(
11782
+ `SELECT table_name, column_name
11783
+ FROM information_schema.table_constraints t
11784
+ LEFT JOIN information_schema.key_column_usage k
11785
+ USING(constraint_name,table_schema,table_name)
11786
+ WHERE t.constraint_type='PRIMARY KEY'
11787
+ AND t.table_schema='${inputSchema}'`,
11788
+ []
11789
+ );
11790
+ const tableToPk = {};
11791
+ const tableToPkRows = tablePks[0];
11792
+ for (const tableToPkRow of tableToPkRows) {
11793
+ const tableName = tableToPkRow["TABLE_NAME"];
11794
+ const columnName = tableToPkRow["COLUMN_NAME"];
11795
+ if (typeof tableToPk[tableName] === "undefined") {
11796
+ tableToPk[tableName] = [columnName];
11797
+ } else {
11798
+ tableToPk[tableName].push(columnName);
11799
+ }
11800
+ }
11766
11801
  for (const [key, value] of Object.entries(tableToPk)) {
11767
11802
  if (value.length > 1) {
11768
11803
  result[key].compositePrimaryKeys = {
@@ -15657,7 +15692,6 @@ ${BREAKPOINT}ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT ${statement.newCo
15657
15692
  }
15658
15693
  convert(statement) {
15659
15694
  const { tableName, columnName } = statement;
15660
- console.log(statement);
15661
15695
  const tableNameWithSchema = statement.schema ? `"${statement.schema}"."${statement.tableName}"` : `"${statement.tableName}"`;
15662
15696
  return `ALTER TABLE ${tableNameWithSchema} ADD PRIMARY KEY ("${columnName}");`;
15663
15697
  }
@@ -16954,7 +16988,37 @@ var init_snapshotsDiffer = __esm({
16954
16988
  }).strict();
16955
16989
  applySnapshotsDiff = async (json1, json2, dialect6, schemasResolver, tablesResolver, columnsResolver, prevFull, curFull) => {
16956
16990
  var _a, _b;
16957
- const diffResult = applyJsonDiff(json1, json2);
16991
+ let diffResult;
16992
+ if (dialect6 === "mysql") {
16993
+ for (const tableName in json1.tables) {
16994
+ const table4 = json1.tables[tableName];
16995
+ for (const indexName4 in table4.indexes) {
16996
+ const index4 = MySqlSquasher.unsquashIdx(table4.indexes[indexName4]);
16997
+ if (index4.isUnique) {
16998
+ table4.uniqueConstraints[indexName4] = MySqlSquasher.squashUnique({
16999
+ name: index4.name,
17000
+ columns: index4.columns
17001
+ });
17002
+ delete json1.tables[tableName].indexes[index4.name];
17003
+ }
17004
+ }
17005
+ }
17006
+ for (const tableName in json2.tables) {
17007
+ const table4 = json2.tables[tableName];
17008
+ for (const indexName4 in table4.indexes) {
17009
+ const index4 = MySqlSquasher.unsquashIdx(table4.indexes[indexName4]);
17010
+ if (index4.isUnique) {
17011
+ table4.uniqueConstraints[indexName4] = MySqlSquasher.squashUnique({
17012
+ name: index4.name,
17013
+ columns: index4.columns
17014
+ });
17015
+ delete json2.tables[tableName].indexes[index4.name];
17016
+ }
17017
+ }
17018
+ }
17019
+ diffResult = applyJsonDiff(json1, json2);
17020
+ }
17021
+ diffResult = applyJsonDiff(json1, json2);
16958
17022
  if (Object.keys(diffResult).length === 0) {
16959
17023
  return { statements: [], sqlStatements: [], _meta: void 0 };
16960
17024
  }
@@ -17125,7 +17189,6 @@ var init_snapshotsDiffer = __esm({
17125
17189
  prevFull
17126
17190
  );
17127
17191
  }
17128
- ;
17129
17192
  alteredCompositePKs = prepareAlterCompositePrimaryKeyMySql(
17130
17193
  it.name,
17131
17194
  it.alteredCompositePKs,
@@ -17319,7 +17382,6 @@ var init_snapshotsDiffer = __esm({
17319
17382
  jsonStatements.push(...jsonSQLiteCreateTables);
17320
17383
  } else if (dialect6 === "pg") {
17321
17384
  const jsonPgCreateTables = created.map((it) => {
17322
- console.log(it);
17323
17385
  return preparePgCreateTableJson(it, curFull);
17324
17386
  });
17325
17387
  jsonStatements.push(...jsonPgCreateTables);
@@ -51861,7 +51923,7 @@ init_source();
51861
51923
  // package.json
51862
51924
  var package_default = {
51863
51925
  name: "drizzle-kit",
51864
- version: "0.19.5",
51926
+ version: "0.19.6",
51865
51927
  repository: "https://github.com/drizzle-team/drizzle-kit-mirror",
51866
51928
  author: "Drizzle Team",
51867
51929
  license: "MIT",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "drizzle-kit",
3
- "version": "0.19.5",
3
+ "version": "0.19.6-8c1d0e5",
4
4
  "repository": "https://github.com/drizzle-team/drizzle-kit-mirror",
5
5
  "author": "Drizzle Team",
6
6
  "license": "MIT",
package/utils.js CHANGED
@@ -12822,7 +12822,8 @@ var tableSquashed = objectType({
12822
12822
  columns: recordType(stringType(), column),
12823
12823
  indexes: recordType(stringType(), stringType()),
12824
12824
  foreignKeys: recordType(stringType(), stringType()),
12825
- compositePrimaryKeys: recordType(stringType(), stringType())
12825
+ compositePrimaryKeys: recordType(stringType(), stringType()),
12826
+ uniqueConstraints: recordType(stringType(), stringType()).default({})
12826
12827
  }).strict();
12827
12828
  var schemaSquashed = objectType({
12828
12829
  version: literalType("5"),
@@ -13285,7 +13286,8 @@ var tableSquashed3 = objectType({
13285
13286
  columns: recordType(stringType(), column3),
13286
13287
  indexes: recordType(stringType(), stringType()),
13287
13288
  foreignKeys: recordType(stringType(), stringType()),
13288
- compositePrimaryKeys: recordType(stringType(), stringType())
13289
+ compositePrimaryKeys: recordType(stringType(), stringType()),
13290
+ uniqueConstraints: recordType(stringType(), stringType()).default({})
13289
13291
  }).strict();
13290
13292
  var schemaSquashed2 = objectType({
13291
13293
  version: latestVersion,
@@ -14371,7 +14373,6 @@ var PgAlterTableAlterColumnSetPrimaryKeyConvertor = class extends Convertor {
14371
14373
  }
14372
14374
  convert(statement) {
14373
14375
  const { tableName, columnName } = statement;
14374
- console.log(statement);
14375
14376
  const tableNameWithSchema = statement.schema ? `"${statement.schema}"."${statement.tableName}"` : `"${statement.tableName}"`;
14376
14377
  return `ALTER TABLE ${tableNameWithSchema} ADD PRIMARY KEY ("${columnName}");`;
14377
14378
  }
@@ -15651,7 +15652,37 @@ var diffResultScheme = objectType({
15651
15652
  }).strict();
15652
15653
  var applySnapshotsDiff = async (json1, json2, dialect3, schemasResolver, tablesResolver, columnsResolver, prevFull, curFull) => {
15653
15654
  var _a, _b;
15654
- const diffResult = applyJsonDiff(json1, json2);
15655
+ let diffResult;
15656
+ if (dialect3 === "mysql") {
15657
+ for (const tableName in json1.tables) {
15658
+ const table4 = json1.tables[tableName];
15659
+ for (const indexName in table4.indexes) {
15660
+ const index4 = MySqlSquasher.unsquashIdx(table4.indexes[indexName]);
15661
+ if (index4.isUnique) {
15662
+ table4.uniqueConstraints[indexName] = MySqlSquasher.squashUnique({
15663
+ name: index4.name,
15664
+ columns: index4.columns
15665
+ });
15666
+ delete json1.tables[tableName].indexes[index4.name];
15667
+ }
15668
+ }
15669
+ }
15670
+ for (const tableName in json2.tables) {
15671
+ const table4 = json2.tables[tableName];
15672
+ for (const indexName in table4.indexes) {
15673
+ const index4 = MySqlSquasher.unsquashIdx(table4.indexes[indexName]);
15674
+ if (index4.isUnique) {
15675
+ table4.uniqueConstraints[indexName] = MySqlSquasher.squashUnique({
15676
+ name: index4.name,
15677
+ columns: index4.columns
15678
+ });
15679
+ delete json2.tables[tableName].indexes[index4.name];
15680
+ }
15681
+ }
15682
+ }
15683
+ diffResult = applyJsonDiff(json1, json2);
15684
+ }
15685
+ diffResult = applyJsonDiff(json1, json2);
15655
15686
  if (Object.keys(diffResult).length === 0) {
15656
15687
  return { statements: [], sqlStatements: [], _meta: void 0 };
15657
15688
  }
@@ -15822,7 +15853,6 @@ var applySnapshotsDiff = async (json1, json2, dialect3, schemasResolver, tablesR
15822
15853
  prevFull
15823
15854
  );
15824
15855
  }
15825
- ;
15826
15856
  alteredCompositePKs = prepareAlterCompositePrimaryKeyMySql(
15827
15857
  it.name,
15828
15858
  it.alteredCompositePKs,
@@ -16016,7 +16046,6 @@ var applySnapshotsDiff = async (json1, json2, dialect3, schemasResolver, tablesR
16016
16046
  jsonStatements.push(...jsonSQLiteCreateTables);
16017
16047
  } else if (dialect3 === "pg") {
16018
16048
  const jsonPgCreateTables = created.map((it) => {
16019
- console.log(it);
16020
16049
  return preparePgCreateTableJson(it, curFull);
16021
16050
  });
16022
16051
  jsonStatements.push(...jsonPgCreateTables);