drizzle-kit 0.20.7-3bc340d → 0.20.7-4f47c46

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/bin.cjs +50 -7
  2. package/package.json +1 -1
  3. package/utils.js +24 -5
package/bin.cjs CHANGED
@@ -11995,9 +11995,9 @@ We have encountered a collision between the index name on columns ${source_defau
11995
11995
  }
11996
11996
  try {
11997
11997
  const fks = await db.execute(
11998
- `SELECT INFORMATION_SCHEMA.KEY_COLUMN_USAGE.TABLE_SCHEMA,INFORMATION_SCHEMA.KEY_COLUMN_USAGE.TABLE_NAME,INFORMATION_SCHEMA.KEY_COLUMN_USAGE.CONSTRAINT_NAME,INFORMATION_SCHEMA.KEY_COLUMN_USAGE.COLUMN_NAME,INFORMATION_SCHEMA.KEY_COLUMN_USAGE.REFERENCED_TABLE_SCHEMA,INFORMATION_SCHEMA.KEY_COLUMN_USAGE.REFERENCED_TABLE_NAME, INFORMATION_SCHEMA.KEY_COLUMN_USAGE.REFERENCED_COLUMN_NAME,information_schema.referential_constraints.UPDATE_RULE, information_schema.referential_constraints.DELETE_RULE
11998
+ `SELECT INFORMATION_SCHEMA.KEY_COLUMN_USAGE.TABLE_SCHEMA,INFORMATION_SCHEMA.KEY_COLUMN_USAGE.TABLE_NAME,INFORMATION_SCHEMA.KEY_COLUMN_USAGE.CONSTRAINT_NAME,INFORMATION_SCHEMA.KEY_COLUMN_USAGE.COLUMN_NAME,INFORMATION_SCHEMA.KEY_COLUMN_USAGE.REFERENCED_TABLE_SCHEMA,INFORMATION_SCHEMA.KEY_COLUMN_USAGE.REFERENCED_TABLE_NAME, INFORMATION_SCHEMA.KEY_COLUMN_USAGE.REFERENCED_COLUMN_NAME,INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS.UPDATE_RULE, INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS.DELETE_RULE
11999
11999
  FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE
12000
- LEFT JOIN information_schema.referential_constraints on information_schema.referential_constraints.constraint_name = information_schema.KEY_COLUMN_USAGE.CONSTRAINT_NAME
12000
+ LEFT JOIN INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS on INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS.CONSTRAINT_NAME = INFORMATION_SCHEMA.KEY_COLUMN_USAGE.CONSTRAINT_NAME
12001
12001
  WHERE INFORMATION_SCHEMA.KEY_COLUMN_USAGE.TABLE_SCHEMA = ? AND INFORMATION_SCHEMA.KEY_COLUMN_USAGE.CONSTRAINT_NAME != 'PRIMARY' and INFORMATION_SCHEMA.KEY_COLUMN_USAGE.REFERENCED_TABLE_NAME is not null;
12002
12002
  `,
12003
12003
  [inputSchema]
@@ -12180,6 +12180,7 @@ var init_pgSerializer = __esm({
12180
12180
  };
12181
12181
  generatePgSnapshot = (tables, enums, schemas, schemaFilter) => {
12182
12182
  const result = {};
12183
+ const indexesInSchema = {};
12183
12184
  for (const table4 of tables) {
12184
12185
  const {
12185
12186
  name: tableName,
@@ -12331,6 +12332,24 @@ ${withStyle.errorWarning(`We've found duplicated unique constraint names in ${so
12331
12332
  return it.name;
12332
12333
  }
12333
12334
  });
12335
+ if (typeof indexesInSchema[schema4 ?? "public"] !== "undefined") {
12336
+ if (indexesInSchema[schema4 ?? "public"].includes(name)) {
12337
+ console.log(
12338
+ `
12339
+ ${withStyle.errorWarning(
12340
+ `We've found duplicated index name across ${source_default.underline.blue(
12341
+ schema4 ?? "public"
12342
+ )} schema. Please rename your index in either the ${source_default.underline.blue(
12343
+ tableName
12344
+ )} table or the table with the duplicated index name`
12345
+ )}`
12346
+ );
12347
+ process.exit(1);
12348
+ }
12349
+ indexesInSchema[schema4 ?? "public"].push(name);
12350
+ } else {
12351
+ indexesInSchema[schema4 ?? "public"] = [name];
12352
+ }
12334
12353
  indexesObject[name] = {
12335
12354
  name,
12336
12355
  columns: indexColumns,
@@ -15458,7 +15477,7 @@ var init_sqlgenerator = __esm({
15458
15477
  if (typeof compositePKs !== "undefined" && compositePKs.length > 0) {
15459
15478
  statement += ",\n";
15460
15479
  const compositePK4 = PgSquasher.unsquashPK(compositePKs[0]);
15461
- statement += ` CONSTRAINT ${st.compositePkName} PRIMARY KEY("${compositePK4.columns.join(`","`)}")`;
15480
+ statement += ` CONSTRAINT "${st.compositePkName}" PRIMARY KEY("${compositePK4.columns.join(`","`)}")`;
15462
15481
  }
15463
15482
  if (typeof uniqueConstraints !== "undefined" && uniqueConstraints.length > 0) {
15464
15483
  for (const uniqueConstraint4 of uniqueConstraints) {
@@ -17850,13 +17869,14 @@ var init_snapshotsDiffer = __esm({
17850
17869
  jsonStatements.push(...jsonDropTables);
17851
17870
  jsonStatements.push(...jsonRenameTables);
17852
17871
  jsonStatements.push(...jsonRenameColumnsStatements);
17853
- jsonStatements.push(...jsonDeletedCompositePKs);
17854
17872
  if (dialect6 !== "mysql") {
17855
17873
  jsonStatements.push(...jsonDeletedUniqueConstraints);
17856
17874
  }
17857
17875
  jsonStatements.push(...jsonDroppedReferencesForAlteredTables);
17858
17876
  jsonStatements.push(...jsonDropIndexesForAllAlteredTables);
17877
+ jsonStatements.push(...jsonDeletedCompositePKs);
17859
17878
  jsonStatements.push(...jsonTableAlternations.alterColumns);
17879
+ jsonStatements.push(...jsonAddedCompositePKs);
17860
17880
  if (dialect6 === "mysql") {
17861
17881
  jsonStatements.push(...jsonAddedUniqueConstraints);
17862
17882
  jsonStatements.push(...jsonDeletedUniqueConstraints);
@@ -17868,7 +17888,6 @@ var init_snapshotsDiffer = __esm({
17868
17888
  jsonStatements.push(...jsonTableAlternations.dropColumns);
17869
17889
  if (dialect6 !== "sqlite")
17870
17890
  jsonStatements.push(...jsonCreateReferences);
17871
- jsonStatements.push(...jsonAddedCompositePKs);
17872
17891
  jsonStatements.push(...jsonAlteredCompositePKs);
17873
17892
  if (dialect6 !== "mysql") {
17874
17893
  jsonStatements.push(...jsonAddedUniqueConstraints);
@@ -62383,6 +62402,7 @@ init_source();
62383
62402
  var import_hanji9 = __toESM(require_hanji());
62384
62403
  init_mysqlSchema();
62385
62404
  init_selector_ui();
62405
+ init_outputs();
62386
62406
  var filterStatements = (statements, currentSchema, prevSchema) => {
62387
62407
  return statements.filter((statement) => {
62388
62408
  if (statement.type === "alter_table_alter_column_set_type") {
@@ -62426,7 +62446,8 @@ var filterStatements = (statements, currentSchema, prevSchema) => {
62426
62446
  };
62427
62447
  var logSuggestionsAndReturn = async ({
62428
62448
  connection,
62429
- statements
62449
+ statements,
62450
+ json2
62430
62451
  }) => {
62431
62452
  let shouldAskForApprove = false;
62432
62453
  const statementsToExecute = [];
@@ -62533,6 +62554,16 @@ var logSuggestionsAndReturn = async ({
62533
62554
  const res = await connection.query(
62534
62555
  `select count(*) as count from \`${statement.tableName}\``
62535
62556
  );
62557
+ if (Object.values(json2.tables[statement.tableName].columns).filter(
62558
+ (column7) => column7.autoincrement
62559
+ ).length > 0) {
62560
+ console.log(
62561
+ `${withStyle.errorWarning(
62562
+ `You have removed the primary key from a ${statement.tableName} table without removing the auto-increment property from this table. As the database error states: 'there can be only one auto column, and it must be defined as a key. Make sure to remove autoincrement from ${statement.tableName} table`
62563
+ )}`
62564
+ );
62565
+ process.exit(1);
62566
+ }
62536
62567
  const count = Number(res[0][0].count);
62537
62568
  if (count > 0) {
62538
62569
  infoToPrint.push(
@@ -62543,6 +62574,17 @@ var logSuggestionsAndReturn = async ({
62543
62574
  tablesToTruncate.push(statement.tableName);
62544
62575
  shouldAskForApprove = true;
62545
62576
  }
62577
+ } else if (statement.type === "delete_composite_pk") {
62578
+ if (Object.values(json2.tables[statement.tableName].columns).filter(
62579
+ (column7) => column7.autoincrement
62580
+ ).length > 0) {
62581
+ console.log(
62582
+ `${withStyle.errorWarning(
62583
+ `You have removed the primary key from a ${statement.tableName} table without removing the auto-increment property from this table. As the database error states: 'there can be only one auto column, and it must be defined as a key. Make sure to remove autoincrement from ${statement.tableName} table`
62584
+ )}`
62585
+ );
62586
+ process.exit(1);
62587
+ }
62546
62588
  } else if (statement.type === "alter_table_add_column") {
62547
62589
  if (statement.column.notNull && typeof statement.column.default === "undefined") {
62548
62590
  const res = await connection.query(
@@ -63015,7 +63057,8 @@ var dbPushMysqlCommand = new import_commander.Command("push:mysql").option(
63015
63057
  schemasToRemove
63016
63058
  } = await logSuggestionsAndReturn({
63017
63059
  connection: connection.client,
63018
- statements: filteredStatements
63060
+ statements: filteredStatements,
63061
+ json2: statements == null ? void 0 : statements.validatedCur
63019
63062
  });
63020
63063
  const filteredSqlStatements = filteredStatements.map(
63021
63064
  (filteredStatement) => fromJson([filteredStatement], "mysql")[0]
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "drizzle-kit",
3
- "version": "0.20.7-3bc340d",
3
+ "version": "0.20.7-4f47c46",
4
4
  "repository": "https://github.com/drizzle-team/drizzle-kit-mirror",
5
5
  "author": "Drizzle Team",
6
6
  "license": "MIT",
package/utils.js CHANGED
@@ -11721,9 +11721,9 @@ We have encountered a collision between the index name on columns ${source_defau
11721
11721
  }
11722
11722
  try {
11723
11723
  const fks = await db.execute(
11724
- `SELECT INFORMATION_SCHEMA.KEY_COLUMN_USAGE.TABLE_SCHEMA,INFORMATION_SCHEMA.KEY_COLUMN_USAGE.TABLE_NAME,INFORMATION_SCHEMA.KEY_COLUMN_USAGE.CONSTRAINT_NAME,INFORMATION_SCHEMA.KEY_COLUMN_USAGE.COLUMN_NAME,INFORMATION_SCHEMA.KEY_COLUMN_USAGE.REFERENCED_TABLE_SCHEMA,INFORMATION_SCHEMA.KEY_COLUMN_USAGE.REFERENCED_TABLE_NAME, INFORMATION_SCHEMA.KEY_COLUMN_USAGE.REFERENCED_COLUMN_NAME,information_schema.referential_constraints.UPDATE_RULE, information_schema.referential_constraints.DELETE_RULE
11724
+ `SELECT INFORMATION_SCHEMA.KEY_COLUMN_USAGE.TABLE_SCHEMA,INFORMATION_SCHEMA.KEY_COLUMN_USAGE.TABLE_NAME,INFORMATION_SCHEMA.KEY_COLUMN_USAGE.CONSTRAINT_NAME,INFORMATION_SCHEMA.KEY_COLUMN_USAGE.COLUMN_NAME,INFORMATION_SCHEMA.KEY_COLUMN_USAGE.REFERENCED_TABLE_SCHEMA,INFORMATION_SCHEMA.KEY_COLUMN_USAGE.REFERENCED_TABLE_NAME, INFORMATION_SCHEMA.KEY_COLUMN_USAGE.REFERENCED_COLUMN_NAME,INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS.UPDATE_RULE, INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS.DELETE_RULE
11725
11725
  FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE
11726
- LEFT JOIN information_schema.referential_constraints on information_schema.referential_constraints.constraint_name = information_schema.KEY_COLUMN_USAGE.CONSTRAINT_NAME
11726
+ LEFT JOIN INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS on INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS.CONSTRAINT_NAME = INFORMATION_SCHEMA.KEY_COLUMN_USAGE.CONSTRAINT_NAME
11727
11727
  WHERE INFORMATION_SCHEMA.KEY_COLUMN_USAGE.TABLE_SCHEMA = ? AND INFORMATION_SCHEMA.KEY_COLUMN_USAGE.CONSTRAINT_NAME != 'PRIMARY' and INFORMATION_SCHEMA.KEY_COLUMN_USAGE.REFERENCED_TABLE_NAME is not null;
11728
11728
  `,
11729
11729
  [inputSchema]
@@ -11906,6 +11906,7 @@ var init_pgSerializer = __esm({
11906
11906
  };
11907
11907
  generatePgSnapshot = (tables, enums, schemas, schemaFilter) => {
11908
11908
  const result = {};
11909
+ const indexesInSchema = {};
11909
11910
  for (const table4 of tables) {
11910
11911
  const {
11911
11912
  name: tableName,
@@ -12057,6 +12058,24 @@ ${withStyle.errorWarning(`We've found duplicated unique constraint names in ${so
12057
12058
  return it.name;
12058
12059
  }
12059
12060
  });
12061
+ if (typeof indexesInSchema[schema4 ?? "public"] !== "undefined") {
12062
+ if (indexesInSchema[schema4 ?? "public"].includes(name)) {
12063
+ console.log(
12064
+ `
12065
+ ${withStyle.errorWarning(
12066
+ `We've found duplicated index name across ${source_default.underline.blue(
12067
+ schema4 ?? "public"
12068
+ )} schema. Please rename your index in either the ${source_default.underline.blue(
12069
+ tableName
12070
+ )} table or the table with the duplicated index name`
12071
+ )}`
12072
+ );
12073
+ process.exit(1);
12074
+ }
12075
+ indexesInSchema[schema4 ?? "public"].push(name);
12076
+ } else {
12077
+ indexesInSchema[schema4 ?? "public"] = [name];
12078
+ }
12060
12079
  indexesObject[name] = {
12061
12080
  name,
12062
12081
  columns: indexColumns,
@@ -15176,7 +15195,7 @@ var init_sqlgenerator = __esm({
15176
15195
  if (typeof compositePKs !== "undefined" && compositePKs.length > 0) {
15177
15196
  statement += ",\n";
15178
15197
  const compositePK4 = PgSquasher.unsquashPK(compositePKs[0]);
15179
- statement += ` CONSTRAINT ${st.compositePkName} PRIMARY KEY("${compositePK4.columns.join(`","`)}")`;
15198
+ statement += ` CONSTRAINT "${st.compositePkName}" PRIMARY KEY("${compositePK4.columns.join(`","`)}")`;
15180
15199
  }
15181
15200
  if (typeof uniqueConstraints !== "undefined" && uniqueConstraints.length > 0) {
15182
15201
  for (const uniqueConstraint4 of uniqueConstraints) {
@@ -17568,13 +17587,14 @@ var init_snapshotsDiffer = __esm({
17568
17587
  jsonStatements.push(...jsonDropTables);
17569
17588
  jsonStatements.push(...jsonRenameTables);
17570
17589
  jsonStatements.push(...jsonRenameColumnsStatements);
17571
- jsonStatements.push(...jsonDeletedCompositePKs);
17572
17590
  if (dialect6 !== "mysql") {
17573
17591
  jsonStatements.push(...jsonDeletedUniqueConstraints);
17574
17592
  }
17575
17593
  jsonStatements.push(...jsonDroppedReferencesForAlteredTables);
17576
17594
  jsonStatements.push(...jsonDropIndexesForAllAlteredTables);
17595
+ jsonStatements.push(...jsonDeletedCompositePKs);
17577
17596
  jsonStatements.push(...jsonTableAlternations.alterColumns);
17597
+ jsonStatements.push(...jsonAddedCompositePKs);
17578
17598
  if (dialect6 === "mysql") {
17579
17599
  jsonStatements.push(...jsonAddedUniqueConstraints);
17580
17600
  jsonStatements.push(...jsonDeletedUniqueConstraints);
@@ -17586,7 +17606,6 @@ var init_snapshotsDiffer = __esm({
17586
17606
  jsonStatements.push(...jsonTableAlternations.dropColumns);
17587
17607
  if (dialect6 !== "sqlite")
17588
17608
  jsonStatements.push(...jsonCreateReferences);
17589
- jsonStatements.push(...jsonAddedCompositePKs);
17590
17609
  jsonStatements.push(...jsonAlteredCompositePKs);
17591
17610
  if (dialect6 !== "mysql") {
17592
17611
  jsonStatements.push(...jsonAddedUniqueConstraints);