drizzle-kit 0.19.4-befd1c5 → 0.19.5-4035c5a

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 +496 -153
  2. package/package.json +2 -2
  3. package/utils.js +75 -21
package/index.cjs CHANGED
@@ -4189,7 +4189,7 @@ var require_hanji = __commonJS({
4189
4189
  }
4190
4190
  };
4191
4191
  exports.TaskTerminal = TaskTerminal;
4192
- function render6(view) {
4192
+ function render7(view) {
4193
4193
  const { stdin, stdout, closable } = (0, readline_1.prepareReadLine)();
4194
4194
  if (view instanceof Prompt3) {
4195
4195
  const terminal = new Terminal(view, stdin, stdout, closable);
@@ -4201,7 +4201,7 @@ var require_hanji = __commonJS({
4201
4201
  closable.close();
4202
4202
  return;
4203
4203
  }
4204
- exports.render = render6;
4204
+ exports.render = render7;
4205
4205
  function renderWithTask4(view, task) {
4206
4206
  return __awaiter(this, void 0, void 0, function* () {
4207
4207
  const terminal = new TaskTerminal(view, process.stdout);
@@ -5142,7 +5142,7 @@ var init_pgSchema = __esm({
5142
5142
  });
5143
5143
 
5144
5144
  // src/serializer/sqliteSchema.ts
5145
- var index3, fk3, compositePK3, column3, tableV33, table3, dialect2, schemaHash3, schemaInternalV32, schemaInternalV42, latestVersion, schemaInternal2, schemaV32, schemaV42, schema3, tableSquashed3, schemaSquashed2, SQLiteSquasher, squashSqliteScheme, drySQLite, sqliteSchemaV3, sqliteSchemaV4, sqliteSchema, backwardCompatibleSqliteSchema;
5145
+ var index3, fk3, compositePK3, column3, tableV33, uniqueConstraint3, table3, dialect2, schemaHash3, schemaInternalV32, schemaInternalV42, latestVersion, schemaInternal2, schemaV32, schemaV42, schema3, tableSquashed3, schemaSquashed2, SQLiteSquasher, squashSqliteScheme, drySQLite, sqliteSchemaV3, sqliteSchemaV4, sqliteSchema, backwardCompatibleSqliteSchema;
5146
5146
  var init_sqliteSchema = __esm({
5147
5147
  "src/serializer/sqliteSchema.ts"() {
5148
5148
  init_global();
@@ -5180,12 +5180,17 @@ var init_sqliteSchema = __esm({
5180
5180
  indexes: recordType(stringType(), index3),
5181
5181
  foreignKeys: recordType(stringType(), fk3)
5182
5182
  }).strict();
5183
+ uniqueConstraint3 = objectType({
5184
+ name: stringType(),
5185
+ columns: stringType().array()
5186
+ }).strict();
5183
5187
  table3 = objectType({
5184
5188
  name: stringType(),
5185
5189
  columns: recordType(stringType(), column3),
5186
5190
  indexes: recordType(stringType(), index3),
5187
5191
  foreignKeys: recordType(stringType(), fk3),
5188
- compositePrimaryKeys: recordType(stringType(), compositePK3)
5192
+ compositePrimaryKeys: recordType(stringType(), compositePK3),
5193
+ uniqueConstraints: recordType(stringType(), uniqueConstraint3).default({})
5189
5194
  }).strict();
5190
5195
  dialect2 = enumType(["sqlite"]);
5191
5196
  schemaHash3 = objectType({
@@ -5246,6 +5251,13 @@ var init_sqliteSchema = __esm({
5246
5251
  });
5247
5252
  return result;
5248
5253
  },
5254
+ squashUnique: (unq) => {
5255
+ return `${unq.name};${unq.columns.join(",")}`;
5256
+ },
5257
+ unsquashUnique: (unq) => {
5258
+ const [name, columns] = unq.split(";");
5259
+ return { name, columns: columns.split(",") };
5260
+ },
5249
5261
  squashFK: (fk4) => {
5250
5262
  return `${fk4.name};${fk4.tableFrom};${fk4.columnsFrom.join(",")};${fk4.tableTo};${fk4.columnsTo.join(",")};${fk4.onUpdate ?? ""};${fk4.onDelete ?? ""}`;
5251
5263
  },
@@ -5289,6 +5301,9 @@ var init_sqliteSchema = __esm({
5289
5301
  const squashedPKs = mapValues(it[1].compositePrimaryKeys, (pk) => {
5290
5302
  return SQLiteSquasher.squashPK(pk);
5291
5303
  });
5304
+ const squashedUniqueConstraints = mapValues(it[1].uniqueConstraints, (unq) => {
5305
+ return SQLiteSquasher.squashUnique(unq);
5306
+ });
5292
5307
  return [
5293
5308
  it[0],
5294
5309
  {
@@ -5296,7 +5311,8 @@ var init_sqliteSchema = __esm({
5296
5311
  columns: it[1].columns,
5297
5312
  indexes: squashedIndexes,
5298
5313
  foreignKeys: squashedFKs,
5299
- compositePrimaryKeys: squashedPKs
5314
+ compositePrimaryKeys: squashedPKs,
5315
+ uniqueConstraints: squashedUniqueConstraints
5300
5316
  }
5301
5317
  ];
5302
5318
  })
@@ -11368,6 +11384,71 @@ var init_mysqlImports = __esm({
11368
11384
  }
11369
11385
  });
11370
11386
 
11387
+ // src/cli/validations/outputs.ts
11388
+ var withStyle, outputs;
11389
+ var init_outputs = __esm({
11390
+ "src/cli/validations/outputs.ts"() {
11391
+ init_source();
11392
+ withStyle = {
11393
+ error: (str) => `${source_default.red(`${source_default.white.bgRed(" Invalid input ")} ${str}`)}`,
11394
+ warning: (str) => `${source_default.white.bgGray(" Warning ")} ${str}`,
11395
+ errorWarning: (str) => `${source_default.red(`${source_default.white.bgRed(" Warning ")} ${str}`)}`,
11396
+ fullWarning: (str) => `${source_default.black.bgYellow("[Warning]")} ${source_default.bold(str)}`
11397
+ };
11398
+ outputs = {
11399
+ studio: {
11400
+ drivers: (param) => withStyle.error(
11401
+ `"${param}" is not a valid driver. Available drivers: "pg", "mysql2", "better-sqlite", "libsql", "turso". You can read more about drizzle.config: https://orm.drizzle.team/kit-docs/config-reference`
11402
+ ),
11403
+ noCredentials: () => withStyle.error(
11404
+ `You need to specify a "dbCredentials" param in you config. It will help drizzle to know how to query you database. You can read more about drizzle.config: https://orm.drizzle.team/kit-docs/config-reference`
11405
+ ),
11406
+ noDriver: () => withStyle.error(
11407
+ `You need to specify a "driver" param in you config. It will help drizzle to know how to query you database. You can read more about drizzle.config: https://orm.drizzle.team/kit-docs/config-reference`
11408
+ )
11409
+ },
11410
+ common: {
11411
+ ambiguousParams: (command) => withStyle.error(
11412
+ `You can't use both --config and other cli options for ${command} command`
11413
+ ),
11414
+ schema: (command) => withStyle.error(`"--schema" is a required field for ${command} command`),
11415
+ schemaConfig: (command) => withStyle.error(
11416
+ `"schema" is a required field in drizzle.config for ${command} command`
11417
+ )
11418
+ },
11419
+ postgres: {
11420
+ connection: {
11421
+ driver: () => withStyle.error(`Only "pg" is available options for "--driver"`),
11422
+ required: () => withStyle.error(
11423
+ `Either "connectionString" or "host", "database" are required for database connection`
11424
+ )
11425
+ }
11426
+ },
11427
+ mysql: {
11428
+ connection: {
11429
+ driver: () => withStyle.error(`Only "mysql2" is available options for "--driver"`),
11430
+ required: () => withStyle.error(
11431
+ `Either "connectionString" or "host", "database" are required for database connection`
11432
+ )
11433
+ }
11434
+ },
11435
+ sqlite: {
11436
+ connection: {
11437
+ driver: () => withStyle.error(
11438
+ `Either "turso", "libsql", "better-sqlite" are available options for "--driver"`
11439
+ ),
11440
+ url: (driver) => withStyle.error(`"url" is a required option for driver "${driver}". You can read more about drizzle.config: https://orm.drizzle.team/kit-docs/config-reference`),
11441
+ authToken: (driver) => withStyle.error(
11442
+ `"authToken" is a required option for driver "${driver}". You can read more about drizzle.config: https://orm.drizzle.team/kit-docs/config-reference`
11443
+ )
11444
+ },
11445
+ introspect: {},
11446
+ push: {}
11447
+ }
11448
+ };
11449
+ }
11450
+ });
11451
+
11371
11452
  // src/serializer/mysqlSerializer.ts
11372
11453
  var mysqlSerializer_exports = {};
11373
11454
  __export(mysqlSerializer_exports, {
@@ -11400,6 +11481,8 @@ var init_mysqlSerializer = __esm({
11400
11481
  import_mysql_core3 = require("drizzle-orm/mysql-core");
11401
11482
  import_drizzle_orm3 = require("drizzle-orm");
11402
11483
  init_serializer();
11484
+ init_outputs();
11485
+ init_source();
11403
11486
  dialect3 = new import_mysql_core2.MySqlDialect();
11404
11487
  indexName = (tableName, columns) => {
11405
11488
  return `${tableName}_${columns.join("_")}_index`;
@@ -11442,6 +11525,24 @@ var init_mysqlSerializer = __esm({
11442
11525
  // : undefined,
11443
11526
  };
11444
11527
  if (column7.isUnique) {
11528
+ const existingUnique = uniqueConstraintObject[column7.uniqueName];
11529
+ if (typeof existingUnique !== "undefined") {
11530
+ console.log(
11531
+ `
11532
+ ${withStyle.errorWarning(`We've found duplicated unique constraint names in ${source_default.underline.blue(
11533
+ tableName
11534
+ )} table.
11535
+ The unique constraint ${source_default.underline.blue(
11536
+ column7.uniqueName
11537
+ )} on the ${source_default.underline.blue(
11538
+ column7.name
11539
+ )} column is confilcting with a unique constraint name already defined for ${source_default.underline.blue(
11540
+ existingUnique.columns.join(",")
11541
+ )} columns
11542
+ `)}`
11543
+ );
11544
+ process.exit(1);
11545
+ }
11445
11546
  uniqueConstraintObject[column7.uniqueName] = {
11446
11547
  name: column7.uniqueName,
11447
11548
  columns: [columnToSet.name]
@@ -11483,9 +11584,29 @@ var init_mysqlSerializer = __esm({
11483
11584
  columnsObject[column7.name].notNull = true;
11484
11585
  }
11485
11586
  });
11486
- uniqueConstraints.map((unq) => {
11587
+ uniqueConstraints == null ? void 0 : uniqueConstraints.map((unq) => {
11487
11588
  const columnNames = unq.columns.map((c) => c.name);
11488
11589
  const name = unq.name ?? (0, import_mysql_core2.uniqueKeyName)(table4, columnNames);
11590
+ const existingUnique = uniqueConstraintObject[name];
11591
+ if (typeof existingUnique !== "undefined") {
11592
+ console.log(
11593
+ `
11594
+ ${withStyle.errorWarning(
11595
+ `We've found duplicated unique constraint names in ${source_default.underline.blue(
11596
+ tableName
11597
+ )} table.
11598
+ The unique constraint ${source_default.underline.blue(
11599
+ name
11600
+ )} on the ${source_default.underline.blue(
11601
+ columnNames.join(",")
11602
+ )} columns is confilcting with a unique constraint name already defined for ${source_default.underline.blue(
11603
+ existingUnique.columns.join(",")
11604
+ )} columns
11605
+ `
11606
+ )}`
11607
+ );
11608
+ process.exit(1);
11609
+ }
11489
11610
  uniqueConstraintObject[name] = {
11490
11611
  name: unq.name,
11491
11612
  columns: columnNames
@@ -11618,7 +11739,7 @@ var init_mysqlSerializer = __esm({
11618
11739
  onUpdate = true;
11619
11740
  }
11620
11741
  const newColumn = {
11621
- default: columnDefault === null ? void 0 : /^-?[\d.]+(?:e-?\d+)?$/.test(columnDefault) ? Number(columnDefault) : isDefaultAnExpression ? clearDefaults(columnDefault, collation) : `'${columnDefault}'`,
11742
+ default: columnDefault === null ? void 0 : /^-?[\d.]+(?:e-?\d+)?$/.test(columnDefault) && !columnType.startsWith("decimal") ? Number(columnDefault) : isDefaultAnExpression ? clearDefaults(columnDefault, collation) : `'${columnDefault}'`,
11622
11743
  autoincrement: isAutoincrement,
11623
11744
  name: columnName,
11624
11745
  type: changedType,
@@ -11635,7 +11756,8 @@ var init_mysqlSerializer = __esm({
11635
11756
  },
11636
11757
  compositePrimaryKeys: {},
11637
11758
  indexes: {},
11638
- foreignKeys: {}
11759
+ foreignKeys: {},
11760
+ uniqueConstraints: {}
11639
11761
  };
11640
11762
  } else {
11641
11763
  result[tableName].columns[columnName] = newColumn;
@@ -11734,14 +11856,27 @@ var init_mysqlSerializer = __esm({
11734
11856
  if (progressCallback) {
11735
11857
  progressCallback("indexes", indexesCount, "fetching");
11736
11858
  }
11737
- if (typeof tableInResult.indexes[constraintName] !== "undefined") {
11738
- tableInResult.indexes[constraintName].columns.push(columnName);
11859
+ if (isUnique) {
11860
+ if (typeof tableInResult.uniqueConstraints[constraintName] !== "undefined") {
11861
+ tableInResult.uniqueConstraints[constraintName].columns.push(
11862
+ columnName
11863
+ );
11864
+ } else {
11865
+ tableInResult.uniqueConstraints[constraintName] = {
11866
+ name: constraintName,
11867
+ columns: [columnName]
11868
+ };
11869
+ }
11739
11870
  } else {
11740
- tableInResult.indexes[constraintName] = {
11741
- name: constraintName,
11742
- columns: [columnName],
11743
- isUnique
11744
- };
11871
+ if (typeof tableInResult.indexes[constraintName] !== "undefined") {
11872
+ tableInResult.indexes[constraintName].columns.push(columnName);
11873
+ } else {
11874
+ tableInResult.indexes[constraintName] = {
11875
+ name: constraintName,
11876
+ columns: [columnName],
11877
+ isUnique
11878
+ };
11879
+ }
11745
11880
  }
11746
11881
  }
11747
11882
  if (progressCallback) {
@@ -11818,6 +11953,8 @@ var init_pgSerializer = __esm({
11818
11953
  import_drizzle_orm5 = require("drizzle-orm");
11819
11954
  import_drizzle_orm6 = require("drizzle-orm");
11820
11955
  init_serializer();
11956
+ init_source();
11957
+ init_outputs();
11821
11958
  dialect4 = new import_pg_core2.PgDialect();
11822
11959
  indexName2 = (tableName, columns) => {
11823
11960
  return `${tableName}_${columns.join("_")}_index`;
@@ -11851,6 +11988,24 @@ var init_pgSerializer = __esm({
11851
11988
  notNull
11852
11989
  };
11853
11990
  if (column7.isUnique) {
11991
+ const existingUnique = uniqueConstraintObject[column7.uniqueName];
11992
+ if (typeof existingUnique !== "undefined") {
11993
+ console.log(
11994
+ `
11995
+ ${withStyle.errorWarning(`We've found duplicated unique constraint names in ${source_default.underline.blue(
11996
+ tableName
11997
+ )} table.
11998
+ The unique constraint ${source_default.underline.blue(
11999
+ column7.uniqueName
12000
+ )} on the ${source_default.underline.blue(
12001
+ column7.name
12002
+ )} column is confilcting with a unique constraint name already defined for ${source_default.underline.blue(
12003
+ existingUnique.columns.join(",")
12004
+ )} columns
12005
+ `)}`
12006
+ );
12007
+ process.exit(1);
12008
+ }
11854
12009
  uniqueConstraintObject[column7.uniqueName] = {
11855
12010
  name: column7.uniqueName,
11856
12011
  nullsNotDistinct: column7.uniqueType === "not distinct",
@@ -11891,9 +12046,27 @@ var init_pgSerializer = __esm({
11891
12046
  columns: columnNames
11892
12047
  };
11893
12048
  });
11894
- uniqueConstraints.map((unq) => {
12049
+ uniqueConstraints == null ? void 0 : uniqueConstraints.map((unq) => {
11895
12050
  const columnNames = unq.columns.map((c) => c.name);
11896
12051
  const name = unq.name ?? (0, import_pg_core2.uniqueKeyName)(table4, columnNames);
12052
+ const existingUnique = uniqueConstraintObject[name];
12053
+ if (typeof existingUnique !== "undefined") {
12054
+ console.log(
12055
+ `
12056
+ ${withStyle.errorWarning(`We've found duplicated unique constraint names in ${source_default.underline.blue(
12057
+ tableName
12058
+ )} table.
12059
+ The unique constraint ${source_default.underline.blue(
12060
+ name
12061
+ )} on the ${source_default.underline.blue(
12062
+ columnNames.join(",")
12063
+ )} columns is confilcting with a unique constraint name already defined for ${source_default.underline.blue(
12064
+ existingUnique.columns.join(",")
12065
+ )} columns
12066
+ `)}`
12067
+ );
12068
+ process.exit(1);
12069
+ }
11897
12070
  uniqueConstraintObject[name] = {
11898
12071
  name: unq.name,
11899
12072
  nullsNotDistinct: unq.nullsNotDistinct,
@@ -12009,6 +12182,7 @@ var init_pgSerializer = __esm({
12009
12182
  const indexToReturn = {};
12010
12183
  const foreignKeysToReturn = {};
12011
12184
  const primaryKeys = {};
12185
+ const uniqueConstrains = {};
12012
12186
  const tableResponse = await db.query(
12013
12187
  `SELECT a.attrelid::regclass::text, a.attname, is_nullable, a.attndims as array_dimensions
12014
12188
  , CASE WHEN a.atttypid = ANY ('{int,int8,int2}'::regtype[])
@@ -12102,6 +12276,22 @@ var init_pgSerializer = __esm({
12102
12276
  ...new Set(foreignKeysToReturn[foreignKeyName].columnsTo)
12103
12277
  ];
12104
12278
  }
12279
+ const uniqueConstrainsRows = tableConstraints.rows.filter(
12280
+ (mapRow) => mapRow.constraint_type === "UNIQUE"
12281
+ );
12282
+ for (const unqs of uniqueConstrainsRows) {
12283
+ const columnName = unqs.column_name;
12284
+ const constraintName = unqs.constraint_name;
12285
+ if (typeof uniqueConstrains[constraintName] !== "undefined") {
12286
+ uniqueConstrains[constraintName].columns.push(columnName);
12287
+ } else {
12288
+ uniqueConstrains[constraintName] = {
12289
+ columns: [columnName],
12290
+ nullsNotDistinct: false,
12291
+ name: constraintName
12292
+ };
12293
+ }
12294
+ }
12105
12295
  for (const columnResponse of tableResponse.rows) {
12106
12296
  const columnName = columnResponse.attname;
12107
12297
  const columnAdditionalDT = columnResponse.additional_dt;
@@ -12127,9 +12317,6 @@ var init_pgSerializer = __esm({
12127
12317
  columns: cprimaryKey.map((c) => c.column_name)
12128
12318
  };
12129
12319
  }
12130
- const uniqueKey = tableConstraints.rows.filter(
12131
- (mapRow) => columnName === mapRow.column_name && mapRow.constraint_type === "UNIQUE"
12132
- );
12133
12320
  const defaultValue = defaultForColumn(columnResponse);
12134
12321
  const isSerial = columnType === "serial";
12135
12322
  let columnTypeMapped = columnType;
@@ -12177,10 +12364,25 @@ var init_pgSerializer = __esm({
12177
12364
  t.relname,
12178
12365
  i.relname;`
12179
12366
  );
12367
+ const dbIndexFromConstraint = await db.query(
12368
+ `SELECT
12369
+ idx.indexrelname AS index_name,
12370
+ idx.relname AS table_name,
12371
+ con.conname,
12372
+ CASE WHEN con.conname IS NOT NULL THEN 1 ELSE 0 END AS generated_by_constraint
12373
+ FROM
12374
+ pg_stat_user_indexes idx
12375
+ LEFT JOIN
12376
+ pg_constraint con ON con.conindid = idx.indexrelid
12377
+ WHERE idx.relname = '${tableName}';`
12378
+ );
12379
+ const idxsInConsteraint = dbIndexFromConstraint.rows.filter((it) => it.generated_by_constraint === 1).map((it) => it.index_name);
12180
12380
  for (const dbIndex of dbIndexes.rows) {
12181
12381
  const indexName4 = dbIndex.index_name;
12182
12382
  const indexColumnName = dbIndex.column_name;
12183
12383
  const indexIsUnique = dbIndex.is_unique;
12384
+ if (idxsInConsteraint.includes(indexName4))
12385
+ continue;
12184
12386
  if (typeof indexToReturn[indexName4] !== "undefined") {
12185
12387
  indexToReturn[indexName4].columns.push(indexColumnName);
12186
12388
  } else {
@@ -12201,7 +12403,8 @@ var init_pgSerializer = __esm({
12201
12403
  columns: columnToReturn,
12202
12404
  indexes: indexToReturn,
12203
12405
  foreignKeys: foreignKeysToReturn,
12204
- compositePrimaryKeys: primaryKeys
12406
+ compositePrimaryKeys: primaryKeys,
12407
+ uniqueConstraints: uniqueConstrains
12205
12408
  };
12206
12409
  } catch (e) {
12207
12410
  rej(e);
@@ -12396,6 +12599,8 @@ var init_sqliteSerializer = __esm({
12396
12599
  import_drizzle_orm9 = require("drizzle-orm");
12397
12600
  import_sqlite_core2 = require("drizzle-orm/sqlite-core");
12398
12601
  init_serializer();
12602
+ init_outputs();
12603
+ init_source();
12399
12604
  dialect5 = new import_sqlite_core2.SQLiteSyncDialect();
12400
12605
  generateSqliteSnapshot = (tables, enums) => {
12401
12606
  const result = {};
@@ -12404,12 +12609,14 @@ var init_sqliteSerializer = __esm({
12404
12609
  const indexesObject = {};
12405
12610
  const foreignKeysObject = {};
12406
12611
  const primaryKeysObject = {};
12612
+ const uniqueConstraintObject = {};
12407
12613
  const {
12408
12614
  name: tableName,
12409
12615
  columns,
12410
12616
  indexes,
12411
12617
  foreignKeys: tableForeignKeys,
12412
- primaryKeys
12618
+ primaryKeys,
12619
+ uniqueConstraints
12413
12620
  } = (0, import_sqlite_core2.getTableConfig)(table4);
12414
12621
  columns.forEach((column7) => {
12415
12622
  const notNull = column7.notNull;
@@ -12429,6 +12636,31 @@ var init_sqliteSerializer = __esm({
12429
12636
  }
12430
12637
  }
12431
12638
  columnsObject[column7.name] = columnToSet;
12639
+ if (column7.isUnique) {
12640
+ const existingUnique = indexesObject[column7.uniqueName];
12641
+ if (typeof existingUnique !== "undefined") {
12642
+ console.log(
12643
+ `
12644
+ ${withStyle.errorWarning(`We've found duplicated unique constraint names in ${source_default.underline.blue(
12645
+ tableName
12646
+ )} table.
12647
+ The unique constraint ${source_default.underline.blue(
12648
+ column7.uniqueName
12649
+ )} on the ${source_default.underline.blue(
12650
+ column7.name
12651
+ )} column is confilcting with a unique constraint name already defined for ${source_default.underline.blue(
12652
+ existingUnique.columns.join(",")
12653
+ )} columns
12654
+ `)}`
12655
+ );
12656
+ process.exit(1);
12657
+ }
12658
+ indexesObject[column7.uniqueName] = {
12659
+ name: column7.uniqueName,
12660
+ columns: [columnToSet.name],
12661
+ isUnique: true
12662
+ };
12663
+ }
12432
12664
  });
12433
12665
  const foreignKeys = tableForeignKeys.map((fk4) => {
12434
12666
  const name = fk4.getName();
@@ -12476,6 +12708,35 @@ var init_sqliteSerializer = __esm({
12476
12708
  where
12477
12709
  };
12478
12710
  });
12711
+ uniqueConstraints == null ? void 0 : uniqueConstraints.map((unq) => {
12712
+ const columnNames = unq.columns.map((c) => c.name);
12713
+ const name = unq.name ?? (0, import_sqlite_core2.uniqueKeyName)(table4, columnNames);
12714
+ const existingUnique = indexesObject[name];
12715
+ if (typeof existingUnique !== "undefined") {
12716
+ console.log(
12717
+ `
12718
+ ${withStyle.errorWarning(
12719
+ `We've found duplicated unique constraint names in ${source_default.underline.blue(
12720
+ tableName
12721
+ )} table.
12722
+ The unique constraint ${source_default.underline.blue(
12723
+ name
12724
+ )} on the ${source_default.underline.blue(
12725
+ columnNames.join(",")
12726
+ )} columns is confilcting with a unique constraint name already defined for ${source_default.underline.blue(
12727
+ existingUnique.columns.join(",")
12728
+ )} columns
12729
+ `
12730
+ )}`
12731
+ );
12732
+ process.exit(1);
12733
+ }
12734
+ indexesObject[name] = {
12735
+ name: unq.name,
12736
+ columns: columnNames,
12737
+ isUnique: true
12738
+ };
12739
+ });
12479
12740
  primaryKeys.forEach((it) => {
12480
12741
  if (it.columns.length > 1) {
12481
12742
  primaryKeysObject[it.getName()] = {
@@ -12490,7 +12751,8 @@ var init_sqliteSerializer = __esm({
12490
12751
  columns: columnsObject,
12491
12752
  indexes: indexesObject,
12492
12753
  foreignKeys: foreignKeysObject,
12493
- compositePrimaryKeys: primaryKeysObject
12754
+ compositePrimaryKeys: primaryKeysObject,
12755
+ uniqueConstraints: uniqueConstraintObject
12494
12756
  };
12495
12757
  }
12496
12758
  return {
@@ -12574,7 +12836,8 @@ var init_sqliteSerializer = __esm({
12574
12836
  },
12575
12837
  compositePrimaryKeys: {},
12576
12838
  indexes: {},
12577
- foreignKeys: {}
12839
+ foreignKeys: {},
12840
+ uniqueConstraints: {}
12578
12841
  };
12579
12842
  } else {
12580
12843
  result[tableName].columns[columnName] = newColumn;
@@ -12659,7 +12922,7 @@ FROM sqlite_master AS m,
12659
12922
  pragma_index_list(m.name) AS il,
12660
12923
  pragma_index_info(il.name) AS ii
12661
12924
  WHERE
12662
- m.type = 'table' and il.name NOT LIKE 'sqlite_autoindex_%';`
12925
+ m.type = 'table';`
12663
12926
  );
12664
12927
  for (const idxRow of idxs) {
12665
12928
  const tableName = idxRow.tableName;
@@ -14630,7 +14893,7 @@ ${sql}
14630
14893
  });
14631
14894
 
14632
14895
  // src/sqlgenerator.ts
14633
- var pgNativeTypes, isPgNativeType, Convertor, PgCreateTableConvertor, MySqlCreateTableConvertor, SQLiteCreateTableConvertor, PgAlterTableAddUniqueConstraintConvertor, PgAlterTableDropUniqueConstraintConvertor, MySQLAlterTableAddUniqueConstraintConvertor, MySQLAlterTableDropUniqueConstraintConvertor, CreateTypeEnumConvertor, AlterTypeAddValueConvertor, PgDropTableConvertor, MySQLDropTableConvertor, SQLiteDropTableConvertor, PgRenameTableConvertor, SqliteRenameTableConvertor, MySqlRenameTableConvertor, PgAlterTableRenameColumnConvertor, MySqlAlterTableRenameColumnConvertor, SQLiteAlterTableRenameColumnConvertor, PgAlterTableDropColumnConvertor, MySqlAlterTableDropColumnConvertor, SQLiteAlterTableDropColumnConvertor, PgAlterTableAddColumnConvertor, MySqlAlterTableAddColumnConvertor, SQLiteAlterTableAddColumnConvertor, PgAlterTableAlterColumnSetTypeConvertor, SQLiteAlterTableAlterColumnSetTypeConvertor, PgAlterTableAlterColumnSetDefaultConvertor, SqliteAlterTableAlterColumnSetDefaultConvertor, PgAlterTableAlterColumnDropDefaultConvertor, MySqlAlterTableAddPk, MySqlAlterTableDropPk, MySqlModifyColumn, SqliteAlterTableAlterColumnDropDefaultConvertor, PgAlterTableCreateCompositePrimaryKeyConvertor, PgAlterTableDeleteCompositePrimaryKeyConvertor, PgAlterTableAlterCompositePrimaryKeyConvertor, MySqlAlterTableCreateCompositePrimaryKeyConvertor, MySqlAlterTableDeleteCompositePrimaryKeyConvertor, MySqlAlterTableAlterCompositePrimaryKeyConvertor, SqliteAlterTableCreateCompositePrimaryKeyConvertor, SqliteAlterTableDeleteCompositePrimaryKeyConvertor, SqliteAlterTableAlterCompositePrimaryKeyConvertor, PgAlterTableAlterColumnSetPrimaryKeyConvertor, PgAlterTableAlterColumnDropPrimaryKeyConvertor, PgAlterTableAlterColumnSetNotNullConvertor, SqliteAlterTableAlterColumnSetNotNullConvertor, SqliteAlterTableAlterColumnSetAutoincrementConvertor, SqliteAlterTableAlterColumnDropAutoincrementConvertor, PgAlterTableAlterColumnDropNotNullConvertor, SqliteAlterTableAlterColumnDropNotNullConvertor, PgCreateForeignKeyConvertor, SqliteCreateForeignKeyConvertor, MySqlCreateForeignKeyConvertor, PgAlterForeignKeyConvertor, SqliteAlterForeignKeyConvertor, PgDeleteForeignKeyConvertor, SqliteDeleteForeignKeyConvertor, MySqlDeleteForeignKeyConvertor, CreatePgIndexConvertor, CreateMySqlIndexConvertor, CreateSqliteIndexConvertor, PgDropIndexConvertor, PgCreateSchemaConvertor, PgRenameSchemaConvertor, PgDropSchemaConvertor, PgAlterTableSetSchemaConvertor, PgAlterTableSetNewSchemaConvertor, PgAlterTableRemoveFromSchemaConvertor, SqliteDropIndexConvertor, MysqlCreateSchemaConvertor, MysqlDropSchemaConvertor, MysqlAlterTableSetSchemaConvertor, MysqlAlterTableSetNewSchemaConvertor, MysqlAlterTableRemoveFromSchemaConvertor, MySqlDropIndexConvertor, convertors, fromJson;
14896
+ var pgNativeTypes, isPgNativeType, Convertor, PgCreateTableConvertor, MySqlCreateTableConvertor, SQLiteCreateTableConvertor, PgAlterTableAddUniqueConstraintConvertor, PgAlterTableDropUniqueConstraintConvertor, MySQLAlterTableAddUniqueConstraintConvertor, MySQLAlterTableDropUniqueConstraintConvertor, SQLiteAlterTableAddUniqueConstraintConvertor, SQLiteAlterTableDropUniqueConstraintConvertor, CreateTypeEnumConvertor, AlterTypeAddValueConvertor, PgDropTableConvertor, MySQLDropTableConvertor, SQLiteDropTableConvertor, PgRenameTableConvertor, SqliteRenameTableConvertor, MySqlRenameTableConvertor, PgAlterTableRenameColumnConvertor, MySqlAlterTableRenameColumnConvertor, SQLiteAlterTableRenameColumnConvertor, PgAlterTableDropColumnConvertor, MySqlAlterTableDropColumnConvertor, SQLiteAlterTableDropColumnConvertor, PgAlterTableAddColumnConvertor, MySqlAlterTableAddColumnConvertor, SQLiteAlterTableAddColumnConvertor, PgAlterTableAlterColumnSetTypeConvertor, SQLiteAlterTableAlterColumnSetTypeConvertor, PgAlterTableAlterColumnSetDefaultConvertor, SqliteAlterTableAlterColumnSetDefaultConvertor, PgAlterTableAlterColumnDropDefaultConvertor, MySqlAlterTableAddPk, MySqlAlterTableDropPk, MySqlModifyColumn, SqliteAlterTableAlterColumnDropDefaultConvertor, PgAlterTableCreateCompositePrimaryKeyConvertor, PgAlterTableDeleteCompositePrimaryKeyConvertor, PgAlterTableAlterCompositePrimaryKeyConvertor, MySqlAlterTableCreateCompositePrimaryKeyConvertor, MySqlAlterTableDeleteCompositePrimaryKeyConvertor, MySqlAlterTableAlterCompositePrimaryKeyConvertor, SqliteAlterTableCreateCompositePrimaryKeyConvertor, SqliteAlterTableDeleteCompositePrimaryKeyConvertor, SqliteAlterTableAlterCompositePrimaryKeyConvertor, PgAlterTableAlterColumnSetPrimaryKeyConvertor, PgAlterTableAlterColumnDropPrimaryKeyConvertor, PgAlterTableAlterColumnSetNotNullConvertor, SqliteAlterTableAlterColumnSetNotNullConvertor, SqliteAlterTableAlterColumnSetAutoincrementConvertor, SqliteAlterTableAlterColumnDropAutoincrementConvertor, PgAlterTableAlterColumnDropNotNullConvertor, SqliteAlterTableAlterColumnDropNotNullConvertor, PgCreateForeignKeyConvertor, SqliteCreateForeignKeyConvertor, MySqlCreateForeignKeyConvertor, PgAlterForeignKeyConvertor, SqliteAlterForeignKeyConvertor, PgDeleteForeignKeyConvertor, SqliteDeleteForeignKeyConvertor, MySqlDeleteForeignKeyConvertor, CreatePgIndexConvertor, CreateMySqlIndexConvertor, CreateSqliteIndexConvertor, PgDropIndexConvertor, PgCreateSchemaConvertor, PgRenameSchemaConvertor, PgDropSchemaConvertor, PgAlterTableSetSchemaConvertor, PgAlterTableSetNewSchemaConvertor, PgAlterTableRemoveFromSchemaConvertor, SqliteDropIndexConvertor, MysqlCreateSchemaConvertor, MysqlDropSchemaConvertor, MysqlAlterTableSetSchemaConvertor, MysqlAlterTableSetNewSchemaConvertor, MysqlAlterTableRemoveFromSchemaConvertor, MySqlDropIndexConvertor, convertors, fromJson;
14634
14897
  var init_sqlgenerator = __esm({
14635
14898
  "src/sqlgenerator.ts"() {
14636
14899
  init_migrate();
@@ -14701,9 +14964,9 @@ var init_sqlgenerator = __esm({
14701
14964
  const primaryKeyStatement = column7.primaryKey ? " PRIMARY KEY" : "";
14702
14965
  const notNullStatement = column7.notNull ? " NOT NULL" : "";
14703
14966
  const defaultStatement = column7.default !== void 0 ? ` DEFAULT ${column7.default}` : "";
14704
- const uniqueConstraint3 = column7.isUnique ? ` CONSTRAINT ${column7.uniqueName} UNIQUE${column7.nullsNotDistinct ? " NULLS NOT DISTINCT" : ""}` : "";
14967
+ const uniqueConstraint4 = column7.isUnique ? ` CONSTRAINT "${column7.uniqueName}" UNIQUE${column7.nullsNotDistinct ? " NULLS NOT DISTINCT" : ""}` : "";
14705
14968
  const type = isPgNativeType(column7.type) ? column7.type : `"${column7.type}"`;
14706
- statement += ` "${column7.name}" ${type}${primaryKeyStatement}${defaultStatement}${notNullStatement}${uniqueConstraint3}`;
14969
+ statement += ` "${column7.name}" ${type}${primaryKeyStatement}${defaultStatement}${notNullStatement}${uniqueConstraint4}`;
14707
14970
  statement += i === columns.length - 1 ? "" : ",\n";
14708
14971
  }
14709
14972
  if (typeof compositePKs !== "undefined" && compositePKs.length > 0) {
@@ -14712,10 +14975,10 @@ var init_sqlgenerator = __esm({
14712
14975
  statement += ` CONSTRAINT ${st.compositePkName} PRIMARY KEY("${compositePK4.columns.join(`","`)}")`;
14713
14976
  }
14714
14977
  if (typeof uniqueConstraints !== "undefined" && uniqueConstraints.length > 0) {
14715
- for (const uniqueConstraint3 of uniqueConstraints) {
14978
+ for (const uniqueConstraint4 of uniqueConstraints) {
14716
14979
  statement += ",\n";
14717
- const unsquashedUnique = PgSquasher.unsquashUnique(uniqueConstraint3);
14718
- statement += ` CONSTRAINT ${unsquashedUnique.name} UNIQUE("${unsquashedUnique.columns.join(`","`)}")`;
14980
+ const unsquashedUnique = PgSquasher.unsquashUnique(uniqueConstraint4);
14981
+ statement += ` CONSTRAINT "${unsquashedUnique.name}" UNIQUE${unsquashedUnique.nullsNotDistinct ? " NULLS NOT DISTINCT" : ""}("${unsquashedUnique.columns.join(`","`)}")`;
14719
14982
  }
14720
14983
  }
14721
14984
  statement += `
@@ -14748,13 +15011,13 @@ var init_sqlgenerator = __esm({
14748
15011
  if (typeof compositePKs !== "undefined" && compositePKs.length > 0) {
14749
15012
  statement += ",\n";
14750
15013
  const compositePK4 = MySqlSquasher.unsquashPK(compositePKs[0]);
14751
- statement += ` CONSTRAINT ${st.compositePkName} PRIMARY KEY("${compositePK4.columns.join(`","`)}")`;
15014
+ statement += ` CONSTRAINT \`${st.compositePkName}\` PRIMARY KEY(\`${compositePK4.columns.join(`\`,\``)}\`)`;
14752
15015
  }
14753
15016
  if (typeof uniqueConstraints !== "undefined" && uniqueConstraints.length > 0) {
14754
- for (const uniqueConstraint3 of uniqueConstraints) {
15017
+ for (const uniqueConstraint4 of uniqueConstraints) {
14755
15018
  statement += ",\n";
14756
- const unsquashedUnique = MySqlSquasher.unsquashUnique(uniqueConstraint3);
14757
- statement += ` CONSTRAINT ${unsquashedUnique.name} UNIQUE(\`${unsquashedUnique.columns.join(`\`,\``)}\`)`;
15019
+ const unsquashedUnique = MySqlSquasher.unsquashUnique(uniqueConstraint4);
15020
+ statement += ` CONSTRAINT \`${unsquashedUnique.name}\` UNIQUE(\`${unsquashedUnique.columns.join(`\`,\``)}\`)`;
14758
15021
  }
14759
15022
  }
14760
15023
  statement += `
@@ -14769,22 +15032,29 @@ var init_sqlgenerator = __esm({
14769
15032
  return statement.type === "sqlite_create_table" && dialect6 === "sqlite";
14770
15033
  }
14771
15034
  convert(st) {
14772
- const { tableName, columns, referenceData, compositePKs } = st;
15035
+ const {
15036
+ tableName,
15037
+ columns,
15038
+ referenceData,
15039
+ compositePKs,
15040
+ uniqueConstraints
15041
+ } = st;
14773
15042
  let statement = "";
14774
- statement += `CREATE TABLE \`${tableName}\` (`;
15043
+ statement += `CREATE TABLE \`${tableName}\` (
15044
+ `;
14775
15045
  for (let i = 0; i < columns.length; i++) {
14776
15046
  const column7 = columns[i];
14777
15047
  const primaryKeyStatement = column7.primaryKey ? " PRIMARY KEY" : "";
14778
15048
  const notNullStatement = column7.notNull ? " NOT NULL" : "";
14779
15049
  const defaultStatement = column7.default !== void 0 ? ` DEFAULT ${column7.default}` : "";
14780
15050
  const autoincrementStatement = column7.autoincrement ? " AUTOINCREMENT" : "";
14781
- statement += "\n ";
15051
+ statement += " ";
14782
15052
  statement += `\`${column7.name}\` ${column7.type}${primaryKeyStatement}${autoincrementStatement}${defaultStatement}${notNullStatement}`;
14783
- statement += ",";
15053
+ statement += i === columns.length - 1 ? "" : ",\n";
14784
15054
  }
14785
15055
  compositePKs.forEach((it) => {
14786
- statement += "\n ";
14787
- statement += `PRIMARY KEY(${it.map((it2) => `\`${it2}\``).join(", ")}),`;
15056
+ statement += ",\n ";
15057
+ statement += `PRIMARY KEY(${it.map((it2) => `\`${it2}\``).join(", ")})`;
14788
15058
  });
14789
15059
  for (let i = 0; i < referenceData.length; i++) {
14790
15060
  const referenceAsString = referenceData[i];
@@ -14801,11 +15071,17 @@ var init_sqlgenerator = __esm({
14801
15071
  const onUpdateStatement = onUpdate ? ` ON UPDATE ${onUpdate}` : "";
14802
15072
  const fromColumnsString = columnsFrom.map((it) => `\`${it}\``).join(",");
14803
15073
  const toColumnsString = columnsTo.map((it) => `\`${it}\``).join(",");
15074
+ statement += ",";
14804
15075
  statement += "\n ";
14805
15076
  statement += `FOREIGN KEY (${fromColumnsString}) REFERENCES \`${tableTo}\`(${toColumnsString})${onUpdateStatement}${onDeleteStatement}`;
14806
- statement += ",";
14807
15077
  }
14808
- statement = statement.trimChar(",");
15078
+ if (typeof uniqueConstraints !== "undefined" && uniqueConstraints.length > 0) {
15079
+ for (const uniqueConstraint4 of uniqueConstraints) {
15080
+ statement += ",\n";
15081
+ const unsquashedUnique = MySqlSquasher.unsquashUnique(uniqueConstraint4);
15082
+ statement += ` CONSTRAINT ${unsquashedUnique.name} UNIQUE(\`${unsquashedUnique.columns.join(`\`,\``)}\`)`;
15083
+ }
15084
+ }
14809
15085
  statement += `
14810
15086
  `;
14811
15087
  statement += `);`;
@@ -14821,7 +15097,7 @@ var init_sqlgenerator = __esm({
14821
15097
  convert(statement) {
14822
15098
  const unsquashed = PgSquasher.unsquashUnique(statement.data);
14823
15099
  const tableNameWithSchema = statement.schema ? `"${statement.schema}"."${statement.tableName}"` : `"${statement.tableName}"`;
14824
- return `ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT "${unsquashed.name}" UNIQUE("${unsquashed.columns.join('","')}");`;
15100
+ return `ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT "${unsquashed.name}" UNIQUE${unsquashed.nullsNotDistinct ? " NULLS NOT DISTINCT" : ""}("${unsquashed.columns.join('","')}");`;
14825
15101
  }
14826
15102
  };
14827
15103
  PgAlterTableDropUniqueConstraintConvertor = class extends Convertor {
@@ -14854,6 +15130,32 @@ var init_sqlgenerator = __esm({
14854
15130
  return `ALTER TABLE ${tableNameWithSchema} DROP CONSTRAINT \`${unsquashed.name}\`;`;
14855
15131
  }
14856
15132
  };
15133
+ SQLiteAlterTableAddUniqueConstraintConvertor = class extends Convertor {
15134
+ can(statement, dialect6) {
15135
+ return statement.type === "create_unique_constraint" && dialect6 === "sqlite";
15136
+ }
15137
+ convert(statement) {
15138
+ return `/*
15139
+ SQLite does not support "Adding unique constraint to an existing table" out of the box, we do not generate automatic migration for that, so it has to be done manually
15140
+ Please refer to: https://www.techonthenet.com/sqlite/unique.php
15141
+
15142
+ Due to that we don't generate migration automatically and it has to be done manually
15143
+ */`;
15144
+ }
15145
+ };
15146
+ SQLiteAlterTableDropUniqueConstraintConvertor = class extends Convertor {
15147
+ can(statement, dialect6) {
15148
+ return statement.type === "delete_unique_constraint" && dialect6 === "sqlite";
15149
+ }
15150
+ convert(statement) {
15151
+ return `/*
15152
+ SQLite does not support "Dropping unique constraint from an existing table" out of the box, we do not generate automatic migration for that, so it has to be done manually
15153
+ Please refer to: https://www.techonthenet.com/sqlite/unique.php
15154
+
15155
+ Due to that we don't generate migration automatically and it has to be done manually
15156
+ */`;
15157
+ }
15158
+ };
14857
15159
  CreateTypeEnumConvertor = class extends Convertor {
14858
15160
  can(statement) {
14859
15161
  return statement.type === "create_type_enum";
@@ -15847,6 +16149,8 @@ ${BREAKPOINT}ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT ${statement.newCo
15847
16149
  convertors.push(new SqliteAlterForeignKeyConvertor());
15848
16150
  convertors.push(new SqliteDeleteForeignKeyConvertor());
15849
16151
  convertors.push(new SqliteCreateForeignKeyConvertor());
16152
+ convertors.push(new SQLiteAlterTableAddUniqueConstraintConvertor());
16153
+ convertors.push(new SQLiteAlterTableDropUniqueConstraintConvertor());
15850
16154
  convertors.push(new SqliteAlterTableAlterColumnSetNotNullConvertor());
15851
16155
  convertors.push(new SqliteAlterTableAlterColumnDropNotNullConvertor());
15852
16156
  convertors.push(new SqliteAlterTableAlterColumnSetDefaultConvertor());
@@ -15940,7 +16244,7 @@ var init_jsonStatements = __esm({
15940
16244
  };
15941
16245
  };
15942
16246
  prepareSQLiteCreateTable = (table4) => {
15943
- const { name, columns } = table4;
16247
+ const { name, columns, uniqueConstraints } = table4;
15944
16248
  const references2 = Object.values(table4.foreignKeys);
15945
16249
  const composites = Object.values(table4.compositePrimaryKeys).map(
15946
16250
  (it) => SQLiteSquasher.unsquashPK(it)
@@ -15950,7 +16254,8 @@ var init_jsonStatements = __esm({
15950
16254
  tableName: name,
15951
16255
  columns: Object.values(columns),
15952
16256
  referenceData: references2,
15953
- compositePKs: composites
16257
+ compositePKs: composites,
16258
+ uniqueConstraints: Object.values(uniqueConstraints)
15954
16259
  };
15955
16260
  };
15956
16261
  prepareDropTableJson = (table4) => {
@@ -18271,70 +18576,6 @@ var init_sqliteUtils = __esm({
18271
18576
  }
18272
18577
  });
18273
18578
 
18274
- // src/cli/validations/outputs.ts
18275
- var withStyle, outputs;
18276
- var init_outputs = __esm({
18277
- "src/cli/validations/outputs.ts"() {
18278
- init_source();
18279
- withStyle = {
18280
- error: (str) => `${source_default.red(`${source_default.white.bgRed(" Invalid input ")} ${str}`)}`,
18281
- warning: (str) => `${source_default.white.bgGray(" Warning ")} ${str}`,
18282
- fullWarning: (str) => `${source_default.black.bgYellow("[Warning]")} ${source_default.bold(str)}`
18283
- };
18284
- outputs = {
18285
- studio: {
18286
- drivers: (param) => withStyle.error(
18287
- `"${param}" is not a valid driver. Available drivers: "pg", "mysql2", "better-sqlite", "libsql", "turso". You can read more about drizzle.config: https://orm.drizzle.team/kit-docs/config-reference`
18288
- ),
18289
- noCredentials: () => withStyle.error(
18290
- `You need to specify a "dbCredentials" param in you config. It will help drizzle to know how to query you database. You can read more about drizzle.config: https://orm.drizzle.team/kit-docs/config-reference`
18291
- ),
18292
- noDriver: () => withStyle.error(
18293
- `You need to specify a "driver" param in you config. It will help drizzle to know how to query you database. You can read more about drizzle.config: https://orm.drizzle.team/kit-docs/config-reference`
18294
- )
18295
- },
18296
- common: {
18297
- ambiguousParams: (command) => withStyle.error(
18298
- `You can't use both --config and other cli options for ${command} command`
18299
- ),
18300
- schema: (command) => withStyle.error(`"--schema" is a required field for ${command} command`),
18301
- schemaConfig: (command) => withStyle.error(
18302
- `"schema" is a required field in drizzle.config for ${command} command`
18303
- )
18304
- },
18305
- postgres: {
18306
- connection: {
18307
- driver: () => withStyle.error(`Only "pg" is available options for "--driver"`),
18308
- required: () => withStyle.error(
18309
- `Either "connectionString" or "host", "database" are required for database connection`
18310
- )
18311
- }
18312
- },
18313
- mysql: {
18314
- connection: {
18315
- driver: () => withStyle.error(`Only "mysql2" is available options for "--driver"`),
18316
- required: () => withStyle.error(
18317
- `Either "connectionString" or "host", "database" are required for database connection`
18318
- )
18319
- }
18320
- },
18321
- sqlite: {
18322
- connection: {
18323
- driver: () => withStyle.error(
18324
- `Either "turso", "libsql", "better-sqlite" are available options for "--driver"`
18325
- ),
18326
- url: (driver) => withStyle.error(`"url" is a required option for driver "${driver}". You can read more about drizzle.config: https://orm.drizzle.team/kit-docs/config-reference`),
18327
- authToken: (driver) => withStyle.error(
18328
- `"authToken" is a required option for driver "${driver}". You can read more about drizzle.config: https://orm.drizzle.team/kit-docs/config-reference`
18329
- )
18330
- },
18331
- introspect: {},
18332
- push: {}
18333
- }
18334
- };
18335
- }
18336
- });
18337
-
18338
18579
  // src/cli/validations/common.ts
18339
18580
  var checkCollisions;
18340
18581
  var init_common = __esm({
@@ -35363,7 +35604,7 @@ var require_promise = __commonJS({
35363
35604
  });
35364
35605
 
35365
35606
  // src/mysql-introspect.ts
35366
- var mysqlImportsList, objToStatement2, timeConfig, binaryConfig, importsPatch, relations, withCasing, schemaToTypeScript, isCyclic, isSelf, mapColumnDefault, mapColumnDefaultForJson, column4, createTableColumns, createTableIndexes, createTablePKs, createTableFKs;
35607
+ var mysqlImportsList, objToStatement2, timeConfig, binaryConfig, importsPatch, relations, withCasing, schemaToTypeScript, isCyclic, isSelf, mapColumnDefault, mapColumnDefaultForJson, column4, createTableColumns, createTableIndexes, createTableUniques, createTablePKs, createTableFKs;
35367
35608
  var init_mysql_introspect = __esm({
35368
35609
  "src/mysql-introspect.ts"() {
35369
35610
  init_utils3();
@@ -35463,9 +35704,13 @@ var init_mysql_introspect = __esm({
35463
35704
  const pkImports = Object.values(it.compositePrimaryKeys).map(
35464
35705
  (it2) => "primaryKey"
35465
35706
  );
35707
+ const uniqueImports = Object.values(it.uniqueConstraints).map(
35708
+ (it2) => "unique"
35709
+ );
35466
35710
  res.mysql.push(...idxImports);
35467
35711
  res.mysql.push(...fkImpots);
35468
35712
  res.mysql.push(...pkImports);
35713
+ res.mysql.push(...uniqueImports);
35469
35714
  const columnImports = Object.values(it.columns).map((col) => {
35470
35715
  let patched = importsPatch[col.type] ?? col.type;
35471
35716
  patched = patched.startsWith("varchar(") ? "varchar" : patched;
@@ -35512,7 +35757,7 @@ var init_mysql_introspect = __esm({
35512
35757
  const filteredFKs = Object.values(table4.foreignKeys).filter((it) => {
35513
35758
  return it.columnsFrom.length > 1 || isSelf(it);
35514
35759
  });
35515
- if (Object.keys(table4.indexes).length > 0 || filteredFKs.length > 0 || Object.keys(table4.compositePrimaryKeys).length > 0) {
35760
+ if (Object.keys(table4.indexes).length > 0 || filteredFKs.length > 0 || Object.keys(table4.compositePrimaryKeys).length > 0 || Object.keys(table4.uniqueConstraints).length > 0) {
35516
35761
  statement += ",\n";
35517
35762
  statement += "(table) => {\n";
35518
35763
  statement += " return {\n";
@@ -35526,6 +35771,10 @@ var init_mysql_introspect = __esm({
35526
35771
  Object.values(table4.compositePrimaryKeys),
35527
35772
  casing
35528
35773
  );
35774
+ statement += createTableUniques(
35775
+ Object.values(table4.uniqueConstraints),
35776
+ casing
35777
+ );
35529
35778
  statement += " }\n";
35530
35779
  statement += "}";
35531
35780
  }
@@ -35836,6 +36085,19 @@ import { sql } from "drizzle-orm"
35836
36085
  statement += `${escapedIndexName})`;
35837
36086
  statement += `.on(${it.columns.map((it2) => `table.${withCasing(it2, casing)}`).join(", ")}),`;
35838
36087
  statement += `
36088
+ `;
36089
+ });
36090
+ return statement;
36091
+ };
36092
+ createTableUniques = (unqs, casing) => {
36093
+ let statement = "";
36094
+ unqs.forEach((it) => {
36095
+ const idxKey = withCasing(it.name, casing);
36096
+ statement += ` ${idxKey}: `;
36097
+ statement += "unique(";
36098
+ statement += `"${it.name}")`;
36099
+ statement += `.on(${it.columns.map((it2) => `table.${withCasing(it2, casing)}`).join(", ")}),`;
36100
+ statement += `
35839
36101
  `;
35840
36102
  });
35841
36103
  return statement;
@@ -37164,10 +37426,10 @@ __export(mysqlIntrospect_exports, {
37164
37426
  mysqlIntrospect: () => mysqlIntrospect,
37165
37427
  mysqlPushIntrospect: () => mysqlPushIntrospect
37166
37428
  });
37167
- var import_hanji5, import_promise, connectToMySQL, mysqlIntrospect, mysqlPushIntrospect;
37429
+ var import_hanji6, import_promise, connectToMySQL, mysqlIntrospect, mysqlPushIntrospect;
37168
37430
  var init_mysqlIntrospect = __esm({
37169
37431
  "src/cli/commands/mysqlIntrospect.ts"() {
37170
- import_hanji5 = __toESM(require_hanji());
37432
+ import_hanji6 = __toESM(require_hanji());
37171
37433
  init_views();
37172
37434
  import_promise = __toESM(require_promise());
37173
37435
  init_mysqlSerializer();
@@ -37216,7 +37478,7 @@ var init_mysqlIntrospect = __esm({
37216
37478
  return false;
37217
37479
  };
37218
37480
  const progress = new IntrospectProgress();
37219
- const res = await (0, import_hanji5.renderWithTask)(
37481
+ const res = await (0, import_hanji6.renderWithTask)(
37220
37482
  progress,
37221
37483
  fromDatabase(
37222
37484
  client,
@@ -37254,7 +37516,7 @@ var init_mysqlIntrospect = __esm({
37254
37516
  });
37255
37517
 
37256
37518
  // src/sqlite-introspect.ts
37257
- var sqliteImportsList, indexName3, objToStatement22, relations2, withCasing2, schemaToTypeScript2, isCyclic2, isSelf2, mapColumnDefault2, column5, createTableColumns2, createTableIndexes2, createTablePKs2, createTableFKs2;
37519
+ var sqliteImportsList, indexName3, objToStatement22, relations2, withCasing2, schemaToTypeScript2, isCyclic2, isSelf2, mapColumnDefault2, column5, createTableColumns2, createTableIndexes2, createTableUniques2, createTablePKs2, createTableFKs2;
37258
37520
  var init_sqlite_introspect = __esm({
37259
37521
  "src/sqlite-introspect.ts"() {
37260
37522
  init_utils3();
@@ -37305,9 +37567,13 @@ var init_sqlite_introspect = __esm({
37305
37567
  const pkImports = Object.values(it.compositePrimaryKeys).map(
37306
37568
  (it2) => "primaryKey"
37307
37569
  );
37570
+ const uniqueImports = Object.values(it.uniqueConstraints).map(
37571
+ (it2) => "unique"
37572
+ );
37308
37573
  res.sqlite.push(...idxImports);
37309
37574
  res.sqlite.push(...fkImpots);
37310
37575
  res.sqlite.push(...pkImports);
37576
+ res.sqlite.push(...uniqueImports);
37311
37577
  const columnImports = Object.values(it.columns).map((col) => {
37312
37578
  return col.type;
37313
37579
  }).filter((type) => {
@@ -37340,7 +37606,7 @@ var init_sqlite_introspect = __esm({
37340
37606
  const filteredFKs = Object.values(table4.foreignKeys).filter((it) => {
37341
37607
  return it.columnsFrom.length > 1 || isSelf2(it);
37342
37608
  });
37343
- if (Object.keys(table4.indexes).length > 0 || filteredFKs.length > 0 || Object.keys(table4.compositePrimaryKeys).length > 0) {
37609
+ if (Object.keys(table4.indexes).length > 0 || filteredFKs.length > 0 || Object.keys(table4.compositePrimaryKeys).length > 0 || Object.keys(table4.uniqueConstraints).length > 0) {
37344
37610
  statement += ",\n";
37345
37611
  statement += "(table) => {\n";
37346
37612
  statement += " return {\n";
@@ -37354,6 +37620,10 @@ var init_sqlite_introspect = __esm({
37354
37620
  Object.values(table4.compositePrimaryKeys),
37355
37621
  casing
37356
37622
  );
37623
+ statement += createTableUniques2(
37624
+ Object.values(table4.uniqueConstraints),
37625
+ casing
37626
+ );
37357
37627
  statement += " }\n";
37358
37628
  statement += "}";
37359
37629
  }
@@ -37387,6 +37657,9 @@ import { sql } from "drizzle-orm"
37387
37657
  if (typeof defaultValue === "string" && defaultValue.startsWith("(") && defaultValue.endsWith(")")) {
37388
37658
  return `sql\`${defaultValue}\``;
37389
37659
  }
37660
+ if (defaultValue === "NULL") {
37661
+ return `sql\`NULL\``;
37662
+ }
37390
37663
  return defaultValue;
37391
37664
  };
37392
37665
  column5 = (type, name, defaultValue, autoincrement, casing) => {
@@ -37473,6 +37746,19 @@ import { sql } from "drizzle-orm"
37473
37746
  statement += `${escapedIndexName})`;
37474
37747
  statement += `.on(${it.columns.map((it2) => `table.${withCasing2(it2, casing)}`).join(", ")}),`;
37475
37748
  statement += `
37749
+ `;
37750
+ });
37751
+ return statement;
37752
+ };
37753
+ createTableUniques2 = (unqs, casing) => {
37754
+ let statement = "";
37755
+ unqs.forEach((it) => {
37756
+ const idxKey = withCasing2(it.name, casing);
37757
+ statement += ` ${idxKey}: `;
37758
+ statement += "unique(";
37759
+ statement += `"${it.name}")`;
37760
+ statement += `.on(${it.columns.map((it2) => `table.${withCasing2(it2, casing)}`).join(", ")}),`;
37761
+ statement += `
37476
37762
  `;
37477
37763
  });
37478
37764
  return statement;
@@ -46062,7 +46348,7 @@ __export(sqliteIntrospect_exports, {
46062
46348
  sqliteIntrospect: () => sqliteIntrospect,
46063
46349
  sqlitePushIntrospect: () => sqlitePushIntrospect
46064
46350
  });
46065
- var import_hanji6, SqliteClient, BetterSqlite, TursoSqlite, connectToSQLite, sqliteIntrospect, sqlitePushIntrospect;
46351
+ var import_hanji7, SqliteClient, BetterSqlite, TursoSqlite, connectToSQLite, sqliteIntrospect, sqlitePushIntrospect;
46066
46352
  var init_sqliteIntrospect = __esm({
46067
46353
  "src/cli/commands/sqliteIntrospect.ts"() {
46068
46354
  init_views();
@@ -46071,7 +46357,7 @@ var init_sqliteIntrospect = __esm({
46071
46357
  init_sqlite_introspect();
46072
46358
  init_mjs();
46073
46359
  init_lib_esm2();
46074
- import_hanji6 = __toESM(require_hanji());
46360
+ import_hanji7 = __toESM(require_hanji());
46075
46361
  SqliteClient = class {
46076
46362
  constructor(db) {
46077
46363
  this.db = db;
@@ -46137,7 +46423,7 @@ var init_sqliteIntrospect = __esm({
46137
46423
  return false;
46138
46424
  };
46139
46425
  const progress = new IntrospectProgress();
46140
- const res = await (0, import_hanji6.renderWithTask)(
46426
+ const res = await (0, import_hanji7.renderWithTask)(
46141
46427
  progress,
46142
46428
  fromDatabase3(
46143
46429
  client,
@@ -50711,7 +50997,7 @@ var require_lib5 = __commonJS({
50711
50997
  });
50712
50998
 
50713
50999
  // src/introspect.ts
50714
- var pgImportsList, objToStatement23, timeConfig2, possibleIntervals, intervalStrToObj, intervalConfig, importsPatch2, relations3, withCasing3, schemaToTypeScript3, isCyclic3, isSelf3, column6, dimensionsInArray, createTableColumns3, createTableIndexes3, createTablePKs3, createTableFKs3;
51000
+ var pgImportsList, objToStatement23, timeConfig2, possibleIntervals, intervalStrToObj, intervalConfig, importsPatch2, relations3, withCasing3, schemaToTypeScript3, isCyclic3, isSelf3, column6, dimensionsInArray, createTableColumns3, createTableIndexes3, createTablePKs3, createTableUniques3, createTableFKs3;
50715
51001
  var init_introspect = __esm({
50716
51002
  "src/introspect.ts"() {
50717
51003
  init_utils3();
@@ -50854,9 +51140,13 @@ var init_introspect = __esm({
50854
51140
  const pkImports = Object.values(it.compositePrimaryKeys).map(
50855
51141
  (it2) => "primaryKey"
50856
51142
  );
51143
+ const uniqueImports = Object.values(it.uniqueConstraints).map(
51144
+ (it2) => "unique"
51145
+ );
50857
51146
  res.pg.push(...idxImports);
50858
51147
  res.pg.push(...fkImpots);
50859
51148
  res.pg.push(...pkImports);
51149
+ res.pg.push(...uniqueImports);
50860
51150
  const columnImports = Object.values(it.columns).map((col) => {
50861
51151
  let patched = importsPatch2[col.type] ?? col.type;
50862
51152
  patched = patched.startsWith("varchar(") ? "varchar" : patched;
@@ -50900,7 +51190,7 @@ var init_introspect = __esm({
50900
51190
  const filteredFKs = Object.values(table4.foreignKeys).filter((it) => {
50901
51191
  return it.columnsFrom.length > 1 || isSelf3(it);
50902
51192
  });
50903
- if (Object.keys(table4.indexes).length > 0 || filteredFKs.length > 0 || Object.keys(table4.compositePrimaryKeys).length > 0) {
51193
+ if (Object.keys(table4.indexes).length > 0 || filteredFKs.length > 0 || Object.keys(table4.compositePrimaryKeys).length > 0 || Object.keys(table4.uniqueConstraints).length > 0) {
50904
51194
  statement += ",\n";
50905
51195
  statement += "(table) => {\n";
50906
51196
  statement += " return {\n";
@@ -50914,6 +51204,10 @@ var init_introspect = __esm({
50914
51204
  Object.values(table4.compositePrimaryKeys),
50915
51205
  casing
50916
51206
  );
51207
+ statement += createTableUniques3(
51208
+ Object.values(table4.uniqueConstraints),
51209
+ casing
51210
+ );
50917
51211
  statement += " }\n";
50918
51212
  statement += "}";
50919
51213
  }
@@ -51156,7 +51450,13 @@ var init_introspect = __esm({
51156
51450
  return res;
51157
51451
  }, {});
51158
51452
  columns.forEach((it) => {
51159
- const columnStatement = column6(it.type, it.name, enumTypes, it.default, casing);
51453
+ const columnStatement = column6(
51454
+ it.type,
51455
+ it.name,
51456
+ enumTypes,
51457
+ it.default,
51458
+ casing
51459
+ );
51160
51460
  statement += " ";
51161
51461
  statement += columnStatement;
51162
51462
  statement += dimensionsInArray(it.type);
@@ -51215,6 +51515,20 @@ var init_introspect = __esm({
51215
51515
  }).join(", ")}`;
51216
51516
  statement += ")";
51217
51517
  statement += `
51518
+ `;
51519
+ });
51520
+ return statement;
51521
+ };
51522
+ createTableUniques3 = (unqs, casing) => {
51523
+ let statement = "";
51524
+ unqs.forEach((it) => {
51525
+ const idxKey = withCasing3(it.name, casing);
51526
+ statement += ` ${idxKey}: `;
51527
+ statement += "unique(";
51528
+ statement += `"${it.name}")`;
51529
+ statement += `.on(${it.columns.map((it2) => `table.${withCasing3(it2, casing)}`).join(", ")})`;
51530
+ statement += it.nullsNotDistinct ? `.nullsNotDistinct()` : "";
51531
+ statement += `,
51218
51532
  `;
51219
51533
  });
51220
51534
  return statement;
@@ -51246,10 +51560,10 @@ var pgIntrospect_exports = {};
51246
51560
  __export(pgIntrospect_exports, {
51247
51561
  pgIntrospect: () => pgIntrospect
51248
51562
  });
51249
- var import_hanji7, import_pg, pgIntrospect;
51563
+ var import_hanji8, import_pg, pgIntrospect;
51250
51564
  var init_pgIntrospect = __esm({
51251
51565
  "src/cli/commands/pgIntrospect.ts"() {
51252
- import_hanji7 = __toESM(require_hanji());
51566
+ import_hanji8 = __toESM(require_hanji());
51253
51567
  init_views();
51254
51568
  import_pg = __toESM(require_lib5());
51255
51569
  init_pgSerializer();
@@ -51272,7 +51586,7 @@ var init_pgIntrospect = __esm({
51272
51586
  return false;
51273
51587
  };
51274
51588
  const progress = new IntrospectProgress();
51275
- const res = await (0, import_hanji7.renderWithTask)(
51589
+ const res = await (0, import_hanji8.renderWithTask)(
51276
51590
  progress,
51277
51591
  fromDatabase2(pool, filter2, (stage, count, status) => {
51278
51592
  progress.update(stage, count, status);
@@ -51492,7 +51806,7 @@ var checkHandler = (out, dialect6) => {
51492
51806
  };
51493
51807
 
51494
51808
  // src/cli/index.ts
51495
- var import_hanji8 = __toESM(require_hanji());
51809
+ var import_hanji9 = __toESM(require_hanji());
51496
51810
  var import_path7 = __toESM(require("path"));
51497
51811
 
51498
51812
  // src/cli/utils.ts
@@ -51547,7 +51861,7 @@ init_source();
51547
51861
  // package.json
51548
51862
  var package_default = {
51549
51863
  name: "drizzle-kit",
51550
- version: "0.19.4",
51864
+ version: "0.19.5",
51551
51865
  repository: "https://github.com/drizzle-team/drizzle-kit-mirror",
51552
51866
  author: "Drizzle Team",
51553
51867
  license: "MIT",
@@ -51626,7 +51940,7 @@ var package_default = {
51626
51940
  "better-sqlite3": "^8.4.0",
51627
51941
  dockerode: "^3.3.4",
51628
51942
  dotenv: "^16.0.3",
51629
- "drizzle-orm": "0.27.0-e9da18b",
51943
+ "drizzle-orm": "0.27.1-8a21e7b",
51630
51944
  eslint: "^8.29.0",
51631
51945
  "eslint-config-prettier": "^8.5.0",
51632
51946
  "eslint-plugin-prettier": "^4.2.1",
@@ -51734,6 +52048,8 @@ init_utils();
51734
52048
 
51735
52049
  // src/cli/commands/mysqlPushUtils.ts
51736
52050
  init_source();
52051
+ var import_hanji5 = __toESM(require_hanji());
52052
+ init_mysqlSchema();
51737
52053
  var filterStatements = (statements) => {
51738
52054
  return statements.filter((statement) => {
51739
52055
  if (statement.type === "alter_table_alter_column_set_type") {
@@ -51888,6 +52204,33 @@ var logSuggestionsAndReturn = async ({
51888
52204
  shouldAskForApprove = true;
51889
52205
  }
51890
52206
  }
52207
+ } else if (statement.type === "create_unique_constraint") {
52208
+ const res = await connection.query(
52209
+ `select count(*) as count from \`${statement.tableName}\``
52210
+ );
52211
+ const count = Number(res[0][0].count);
52212
+ if (count > 0) {
52213
+ const unsquashedUnique = MySqlSquasher.unsquashUnique(statement.data);
52214
+ console.log(
52215
+ `\xB7 You're about to add ${source_default.underline(
52216
+ unsquashedUnique.name
52217
+ )} unique constraint to the table, which contains ${count} items. If this statement fails, you will receive an error from the database. Do you want to truncate ${source_default.underline(
52218
+ statement.tableName
52219
+ )} table?
52220
+ `
52221
+ );
52222
+ const { status, data } = await (0, import_hanji5.render)(
52223
+ new Select([
52224
+ "No, add the constraint without truncating the table",
52225
+ `Yes, truncate the table`
52226
+ ])
52227
+ );
52228
+ if ((data == null ? void 0 : data.index) === 1) {
52229
+ tablesToTruncate.push(statement.tableName);
52230
+ statementsToExecute.push(`truncate table ${statement.tableName};`);
52231
+ shouldAskForApprove = true;
52232
+ }
52233
+ }
51891
52234
  }
51892
52235
  }
51893
52236
  return {
@@ -52124,7 +52467,7 @@ var logSuggestionsAndReturn2 = async ({
52124
52467
  if (typeof tablesContext[fk4.tableFrom] === "undefined") {
52125
52468
  tablesContext[fk4.tableFrom] = _moveDataStatements(fk4.tableFrom, json2);
52126
52469
  }
52127
- } else if (statement.type === "create_composite_pk" || statement.type === "alter_composite_pk" || statement.type === "delete_composite_pk") {
52470
+ } else if (statement.type === "create_composite_pk" || statement.type === "alter_composite_pk" || statement.type === "delete_composite_pk" || statement.type === "create_unique_constraint" || statement.type === "delete_unique_constraint") {
52128
52471
  if (typeof tablesContext[statement.tableName] === "undefined") {
52129
52472
  tablesContext[statement.tableName] = _moveDataStatements(
52130
52473
  statement.tableName,
@@ -52222,14 +52565,14 @@ var generateMysqlCommand = new import_commander.Command("generate:mysql").option
52222
52565
  const { prepareAndMigrateMySql: prepareAndMigrateMySql2 } = await Promise.resolve().then(() => (init_migrate(), migrate_exports));
52223
52566
  await prepareAndMigrateMySql2(result);
52224
52567
  });
52225
- var Select = class extends import_hanji8.Prompt {
52568
+ var Select = class extends import_hanji9.Prompt {
52226
52569
  // private readonly spinner: () => string;
52227
52570
  // private timeout: NodeJS.Timer | undefined;
52228
52571
  constructor(items) {
52229
52572
  super();
52230
52573
  this.on("attach", (terminal) => terminal.toggleCursor("hide"));
52231
52574
  this.on("detach", (terminal) => terminal.toggleCursor("show"));
52232
- this.data = new import_hanji8.SelectState(
52575
+ this.data = new import_hanji9.SelectState(
52233
52576
  items.map((it) => ({ label: it, value: `${it}-value` }))
52234
52577
  );
52235
52578
  this.data.bind(this);
@@ -52264,7 +52607,7 @@ var dbPushMysqlCommand = new import_commander.Command("push:mysql").option(
52264
52607
  );
52265
52608
  const fileNames = prepareFilenames(drizzleConfig.schema);
52266
52609
  if (fileNames.length === 0) {
52267
- (0, import_hanji8.render)(
52610
+ (0, import_hanji9.render)(
52268
52611
  `[${source_default.blue("i")}] No schema file in ${drizzleConfig.schema} was found`
52269
52612
  );
52270
52613
  process.exit(0);
@@ -52281,7 +52624,7 @@ var dbPushMysqlCommand = new import_commander.Command("push:mysql").option(
52281
52624
  try {
52282
52625
  if (typeof statements === "undefined") {
52283
52626
  } else if (statements.sqlStatements.length === 0) {
52284
- (0, import_hanji8.render)(`[${source_default.blue("i")}] No changes detected`);
52627
+ (0, import_hanji9.render)(`[${source_default.blue("i")}] No changes detected`);
52285
52628
  } else {
52286
52629
  const filteredStatements = filterStatements(statements.statements);
52287
52630
  const {
@@ -52309,11 +52652,11 @@ var dbPushMysqlCommand = new import_commander.Command("push:mysql").option(
52309
52652
  }
52310
52653
  if (drizzleConfig.strict) {
52311
52654
  if (!shouldAskForApprove) {
52312
- const { status, data } = await (0, import_hanji8.render)(
52655
+ const { status, data } = await (0, import_hanji9.render)(
52313
52656
  new Select(["No, abort", `Yes, I want to execute all statements`])
52314
52657
  );
52315
52658
  if ((data == null ? void 0 : data.index) === 0) {
52316
- (0, import_hanji8.render)(`[${source_default.red("x")}] All changes were aborted`);
52659
+ (0, import_hanji9.render)(`[${source_default.red("x")}] All changes were aborted`);
52317
52660
  process.exit(0);
52318
52661
  }
52319
52662
  }
@@ -52328,14 +52671,14 @@ var dbPushMysqlCommand = new import_commander.Command("push:mysql").option(
52328
52671
  )
52329
52672
  );
52330
52673
  console.log(source_default.white("Do you still want to push changes?"));
52331
- const { status, data } = await (0, import_hanji8.render)(
52674
+ const { status, data } = await (0, import_hanji9.render)(
52332
52675
  new Select([
52333
52676
  "No, abort",
52334
52677
  `Yes, I want to${tablesToRemove.length > 0 ? ` remove ${tablesToRemove.length} ${tablesToRemove.length > 1 ? "tables" : "table"},` : " "}${columnsToRemove.length > 0 ? ` remove ${columnsToRemove.length} ${columnsToRemove.length > 1 ? "columns" : "column"},` : " "}${tablesToTruncate.length > 0 ? ` truncate ${tablesToTruncate.length} ${tablesToTruncate.length > 1 ? "tables" : "table"}` : ""}`.replace(/(^,)|(,$)/g, "").replace(/ +(?= )/g, "")
52335
52678
  ])
52336
52679
  );
52337
52680
  if ((data == null ? void 0 : data.index) === 0) {
52338
- (0, import_hanji8.render)(`[${source_default.red("x")}] All changes were aborted`);
52681
+ (0, import_hanji9.render)(`[${source_default.red("x")}] All changes were aborted`);
52339
52682
  process.exit(0);
52340
52683
  }
52341
52684
  }
@@ -52346,9 +52689,9 @@ var dbPushMysqlCommand = new import_commander.Command("push:mysql").option(
52346
52689
  await connection.client.query(statement);
52347
52690
  }
52348
52691
  if (filteredStatements.length > 0) {
52349
- (0, import_hanji8.render)(`[${source_default.green("\u2713")}] Changes applied`);
52692
+ (0, import_hanji9.render)(`[${source_default.green("\u2713")}] Changes applied`);
52350
52693
  } else {
52351
- (0, import_hanji8.render)(`[${source_default.blue("i")}] No changes detected`);
52694
+ (0, import_hanji9.render)(`[${source_default.blue("i")}] No changes detected`);
52352
52695
  }
52353
52696
  }
52354
52697
  } catch (e) {
@@ -52360,7 +52703,7 @@ var dbPushMysqlCommand = new import_commander.Command("push:mysql").option(
52360
52703
  var dbPushSqliteCommand = new import_commander.Command("push:sqlite").option(
52361
52704
  "--config <config>",
52362
52705
  "Path to a config.ts file, drizzle.config.ts by default"
52363
- ).option("--tableFilters", `Table name filters`).option("--connectionString <connectionString>", "SQLite connection string").option("--driver <driver>", "SQLite database path").option("--url <url>", "SQLite database path").option("--auth-token <authToken>", "SQLite database path").option("--verbose", "Print all statements for each push").option("--strict", "Always ask for confirmation").action(async (options) => {
52706
+ ).option("--schema <schema>", "Path to a schema file or folder").option("--tableFilters", `Table name filters`).option("--connectionString <connectionString>", "SQLite connection string").option("--driver <driver>", "SQLite database path").option("--url <url>", "SQLite database path").option("--auth-token <authToken>", "SQLite database path").option("--verbose", "Print all statements for each push").option("--strict", "Always ask for confirmation").action(async (options) => {
52364
52707
  printVersions();
52365
52708
  assertPackages("drizzle-orm");
52366
52709
  assertOrmCoreVersion();
@@ -52368,7 +52711,7 @@ var dbPushSqliteCommand = new import_commander.Command("push:sqlite").option(
52368
52711
  const res = await validatePush(options);
52369
52712
  const fileNames = prepareFilenames(res.schema);
52370
52713
  if (fileNames.length === 0) {
52371
- (0, import_hanji8.render)(`[${source_default.blue("i")}] No schema file in ${res.schema} was found`);
52714
+ (0, import_hanji9.render)(`[${source_default.blue("i")}] No schema file in ${res.schema} was found`);
52372
52715
  process.exit(0);
52373
52716
  }
52374
52717
  const connection = await connectToSQLite2(res);
@@ -52383,7 +52726,7 @@ var dbPushSqliteCommand = new import_commander.Command("push:sqlite").option(
52383
52726
  try {
52384
52727
  if (typeof statements === "undefined") {
52385
52728
  } else if (statements.sqlStatements.length === 0) {
52386
- (0, import_hanji8.render)(`
52729
+ (0, import_hanji9.render)(`
52387
52730
  [${source_default.blue("i")}] No changes detected`);
52388
52731
  } else {
52389
52732
  const {
@@ -52411,11 +52754,11 @@ var dbPushSqliteCommand = new import_commander.Command("push:sqlite").option(
52411
52754
  }
52412
52755
  if (res.strict) {
52413
52756
  if (!shouldAskForApprove) {
52414
- const { status, data } = await (0, import_hanji8.render)(
52757
+ const { status, data } = await (0, import_hanji9.render)(
52415
52758
  new Select(["No, abort", `Yes, I want to execute all statements`])
52416
52759
  );
52417
52760
  if ((data == null ? void 0 : data.index) === 0) {
52418
- (0, import_hanji8.render)(`[${source_default.red("x")}] All changes were aborted`);
52761
+ (0, import_hanji9.render)(`[${source_default.red("x")}] All changes were aborted`);
52419
52762
  process.exit(0);
52420
52763
  }
52421
52764
  }
@@ -52430,21 +52773,21 @@ var dbPushSqliteCommand = new import_commander.Command("push:sqlite").option(
52430
52773
  )
52431
52774
  );
52432
52775
  console.log(source_default.white("Do you still want to push changes?"));
52433
- const { status, data } = await (0, import_hanji8.render)(
52776
+ const { status, data } = await (0, import_hanji9.render)(
52434
52777
  new Select([
52435
52778
  "No, abort",
52436
52779
  `Yes, I want to${tablesToRemove.length > 0 ? ` remove ${tablesToRemove.length} ${tablesToRemove.length > 1 ? "tables" : "table"},` : " "}${columnsToRemove.length > 0 ? ` remove ${columnsToRemove.length} ${columnsToRemove.length > 1 ? "columns" : "column"},` : " "}${tablesToTruncate.length > 0 ? ` truncate ${tablesToTruncate.length} ${tablesToTruncate.length > 1 ? "tables" : "table"}` : ""}`.trimEnd().replace(/(^,)|(,$)/g, "").replace(/ +(?= )/g, "")
52437
52780
  ])
52438
52781
  );
52439
52782
  if ((data == null ? void 0 : data.index) === 0) {
52440
- (0, import_hanji8.render)(`[${source_default.red("x")}] All changes were aborted`);
52783
+ (0, import_hanji9.render)(`[${source_default.red("x")}] All changes were aborted`);
52441
52784
  process.exit(0);
52442
52785
  }
52443
52786
  }
52444
52787
  for (const dStmnt of statementsToExecute) {
52445
52788
  await connection.client.run(dStmnt);
52446
52789
  }
52447
- (0, import_hanji8.render)(`[${source_default.green("\u2713")}] Changes applied`);
52790
+ (0, import_hanji9.render)(`[${source_default.green("\u2713")}] Changes applied`);
52448
52791
  }
52449
52792
  } catch (e) {
52450
52793
  console.log(e);
@@ -52613,13 +52956,13 @@ var introspectPgCommand = new import_commander.Command("introspect:pg").option("
52613
52956
  "introspect"
52614
52957
  );
52615
52958
  } else {
52616
- (0, import_hanji8.render)(
52959
+ (0, import_hanji9.render)(
52617
52960
  `[${source_default.blue(
52618
52961
  "i"
52619
52962
  )}] No SQL generated, you already have migrations in project`
52620
52963
  );
52621
52964
  }
52622
- (0, import_hanji8.render)(
52965
+ (0, import_hanji9.render)(
52623
52966
  `[${source_default.green(
52624
52967
  "\u2713"
52625
52968
  )}] You schema file is ready \u279C ${source_default.bold.underline.blue(
@@ -52666,13 +53009,13 @@ var introspectMySqlCommand = new import_commander.Command("introspect:mysql").op
52666
53009
  "introspect"
52667
53010
  );
52668
53011
  } else {
52669
- (0, import_hanji8.render)(
53012
+ (0, import_hanji9.render)(
52670
53013
  `[${source_default.blue(
52671
53014
  "i"
52672
53015
  )}] No SQL generated, you already have migrations in project`
52673
53016
  );
52674
53017
  }
52675
- (0, import_hanji8.render)(
53018
+ (0, import_hanji9.render)(
52676
53019
  `[${source_default.green(
52677
53020
  "\u2713"
52678
53021
  )}] You schema file is ready \u279C ${source_default.bold.underline.blue(
@@ -52719,13 +53062,13 @@ var introspectSQLiteCommand = new import_commander.Command("introspect:sqlite").
52719
53062
  "introspect"
52720
53063
  );
52721
53064
  } else {
52722
- (0, import_hanji8.render)(
53065
+ (0, import_hanji9.render)(
52723
53066
  `[${source_default.blue(
52724
53067
  "i"
52725
53068
  )}] No SQL generated, you already have migrations in project`
52726
53069
  );
52727
53070
  }
52728
- (0, import_hanji8.render)(
53071
+ (0, import_hanji9.render)(
52729
53072
  `[${source_default.green(
52730
53073
  "\u2713"
52731
53074
  )}] You schema file is ready \u279C ${source_default.bold.underline.blue(