drizzle-kit 0.19.14-039355d → 0.20.0-f39d8bc

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. package/index.cjs +374 -88
  2. package/index.d.ts +1 -0
  3. package/package.json +2 -2
  4. package/utils.js +37 -24
package/index.cjs CHANGED
@@ -5211,7 +5211,8 @@ var init_sqliteSchema = __esm({
5211
5211
  onDelete: stringType().optional()
5212
5212
  }).strict();
5213
5213
  compositePK3 = objectType({
5214
- columns: stringType().array()
5214
+ columns: stringType().array(),
5215
+ name: stringType()
5215
5216
  }).strict();
5216
5217
  column3 = objectType({
5217
5218
  name: stringType(),
@@ -11452,7 +11453,8 @@ var init_outputs = __esm({
11452
11453
  error: (str) => `${source_default.red(`${source_default.white.bgRed(" Invalid input ")} ${str}`)}`,
11453
11454
  warning: (str) => `${source_default.white.bgGray(" Warning ")} ${str}`,
11454
11455
  errorWarning: (str) => `${source_default.red(`${source_default.white.bgRed(" Warning ")} ${str}`)}`,
11455
- fullWarning: (str) => `${source_default.black.bgYellow("[Warning]")} ${source_default.bold(str)}`
11456
+ fullWarning: (str) => `${source_default.black.bgYellow("[Warning]")} ${source_default.bold(str)}`,
11457
+ suggestion: (str) => `${source_default.white.bgGray(" Suggestion ")} ${str}`
11456
11458
  };
11457
11459
  outputs = {
11458
11460
  studio: {
@@ -11566,12 +11568,15 @@ var init_mysqlSerializer = __esm({
11566
11568
  columns.forEach((column7) => {
11567
11569
  const notNull = column7.notNull;
11568
11570
  const sqlTypeLowered = column7.getSQLType().toLowerCase();
11571
+ const autoIncrement = typeof column7.autoIncrement === "undefined" ? false : column7.autoIncrement;
11569
11572
  const columnToSet = {
11570
11573
  name: column7.name,
11571
11574
  type: column7.getSQLType(),
11572
11575
  primaryKey: false,
11576
+ // If field is autoincrement it's notNull by default
11577
+ // notNull: autoIncrement ? true : notNull,
11573
11578
  notNull,
11574
- autoincrement: typeof column7.autoIncrement === "undefined" ? false : column7.autoIncrement,
11579
+ autoincrement: autoIncrement,
11575
11580
  onUpdate: column7.hasOnUpdateNow
11576
11581
  };
11577
11582
  if (column7.primary) {
@@ -11631,9 +11636,9 @@ ${withStyle.errorWarning(`We've found duplicated unique constraint names in ${so
11631
11636
  columnsObject[column7.name] = columnToSet;
11632
11637
  });
11633
11638
  primaryKeys.map((pk) => {
11634
- const columnNames = pk.columns.map((c) => c.name).sort();
11635
- primaryKeysObject[`${tableName}_${columnNames.join("_")}`] = {
11636
- name: `${tableName}_${columnNames.join("_")}`,
11639
+ const columnNames = pk.columns.map((c) => c.name);
11640
+ primaryKeysObject[pk.getName()] = {
11641
+ name: pk.getName(),
11637
11642
  columns: columnNames
11638
11643
  };
11639
11644
  for (const column7 of pk.columns) {
@@ -11784,6 +11789,12 @@ We have encountered a collision between the index name on columns ${source_defau
11784
11789
  let tablesCount = /* @__PURE__ */ new Set();
11785
11790
  let indexesCount = 0;
11786
11791
  let foreignKeysCount = 0;
11792
+ const idxs = await db.execute(
11793
+ `select * from INFORMATION_SCHEMA.STATISTICS
11794
+ WHERE INFORMATION_SCHEMA.STATISTICS.TABLE_SCHEMA = ? and INFORMATION_SCHEMA.STATISTICS.INDEX_NAME != 'PRIMARY';`,
11795
+ [inputSchema]
11796
+ );
11797
+ const idxRows = idxs[0];
11787
11798
  for (const column7 of response) {
11788
11799
  if (!tablesFilter(column7["TABLE_NAME"]))
11789
11800
  continue;
@@ -11816,7 +11827,15 @@ We have encountered a collision between the index name on columns ${source_defau
11816
11827
  schemas.push(schema4);
11817
11828
  }
11818
11829
  const table4 = result[tableName];
11819
- let changedType = columnType.replace("bigint unsigned", "serial");
11830
+ let changedType = columnType;
11831
+ if (columnType === "bigint unsigned" && !isNullable && isAutoincrement) {
11832
+ const uniqueIdx = idxRows.filter(
11833
+ (it) => it["COLUMN_NAME"] === columnName && it["TABLE_NAME"] === tableName && it["NON_UNIQUE"] === 0
11834
+ );
11835
+ if (uniqueIdx && uniqueIdx.length === 1) {
11836
+ changedType = columnType.replace("bigint unsigned", "serial");
11837
+ }
11838
+ }
11820
11839
  if (columnType.startsWith("tinyint")) {
11821
11840
  changedType = "tinyint";
11822
11841
  }
@@ -11869,13 +11888,14 @@ We have encountered a collision between the index name on columns ${source_defau
11869
11888
  }
11870
11889
  }
11871
11890
  const tablePks = await db.execute(
11872
- `SELECT table_name, column_name
11891
+ `SELECT table_name, column_name, ordinal_position
11873
11892
  FROM information_schema.table_constraints t
11874
11893
  LEFT JOIN information_schema.key_column_usage k
11875
11894
  USING(constraint_name,table_schema,table_name)
11876
11895
  WHERE t.constraint_type='PRIMARY KEY'
11877
11896
  and table_name != '__drizzle_migrations'
11878
- AND t.table_schema = ?`,
11897
+ AND t.table_schema = ?
11898
+ ORDER BY ordinal_position`,
11879
11899
  [inputSchema]
11880
11900
  );
11881
11901
  const tableToPk = {};
@@ -11883,6 +11903,7 @@ We have encountered a collision between the index name on columns ${source_defau
11883
11903
  for (const tableToPkRow of tableToPkRows) {
11884
11904
  const tableName = tableToPkRow["TABLE_NAME"];
11885
11905
  const columnName = tableToPkRow["COLUMN_NAME"];
11906
+ const position = tableToPkRow["ordinal_position"];
11886
11907
  if (typeof result[tableName] === "undefined") {
11887
11908
  continue;
11888
11909
  }
@@ -11894,9 +11915,9 @@ We have encountered a collision between the index name on columns ${source_defau
11894
11915
  }
11895
11916
  for (const [key, value] of Object.entries(tableToPk)) {
11896
11917
  result[key].compositePrimaryKeys = {
11897
- [`${key}_${value.sort().join("_")}`]: {
11898
- name: `${key}_${value.join("_")}`,
11899
- columns: value.sort()
11918
+ [`${key}_${value.join("_")}_pk`]: {
11919
+ name: `${key}_${value.join("_")}_pk`,
11920
+ columns: value
11900
11921
  }
11901
11922
  };
11902
11923
  }
@@ -11959,12 +11980,6 @@ We have encountered a collision between the index name on columns ${source_defau
11959
11980
  if (progressCallback) {
11960
11981
  progressCallback("fks", foreignKeysCount, "done");
11961
11982
  }
11962
- const idxs = await db.execute(
11963
- `select * from INFORMATION_SCHEMA.STATISTICS
11964
- WHERE INFORMATION_SCHEMA.STATISTICS.TABLE_SCHEMA = ? and INFORMATION_SCHEMA.STATISTICS.INDEX_NAME != 'PRIMARY';`,
11965
- [inputSchema]
11966
- );
11967
- const idxRows = idxs[0];
11968
11983
  for (const idxRow of idxRows) {
11969
11984
  const tableSchema = idxRow["TABLE_SCHEMA"];
11970
11985
  const tableName = idxRow["TABLE_NAME"];
@@ -11974,8 +11989,6 @@ We have encountered a collision between the index name on columns ${source_defau
11974
11989
  const tableInResult = result[tableName];
11975
11990
  if (typeof tableInResult === "undefined")
11976
11991
  continue;
11977
- if (tableInResult.columns[columnName].type === "serial")
11978
- continue;
11979
11992
  indexesCount += 1;
11980
11993
  if (progressCallback) {
11981
11994
  progressCallback("indexes", indexesCount, "fetching");
@@ -12939,7 +12952,7 @@ The unique constraint ${source_default.underline.blue(
12939
12952
  `SELECT
12940
12953
  m.name as "tableName", p.name as "columnName", p.type as "columnType", p."notnull" as "notNull", p.dflt_value as "defaultValue", p.pk as pk
12941
12954
  FROM sqlite_master AS m JOIN pragma_table_info(m.name) AS p
12942
- WHERE m.type = 'table' and m.tbl_name != 'sqlite_sequence' and m.tbl_name != 'sqlite_stat1' and m.tbl_name != '_litestream_seq' and m.tbl_name != '_litestream_lock';
12955
+ WHERE m.type = 'table' and m.tbl_name != 'sqlite_sequence' and m.tbl_name != 'sqlite_stat1' and m.tbl_name != '_litestream_seq' and m.tbl_name != '_litestream_lock' and m.tbl_name != 'libsql_wasm_func_table';
12943
12956
  `
12944
12957
  );
12945
12958
  const tablesWithSeq = [];
@@ -14641,13 +14654,17 @@ var init_migrate = __esm({
14641
14654
  init_mysqlSchema();
14642
14655
  init_utils2();
14643
14656
  init_words();
14657
+ init_outputs();
14644
14658
  prepareAndMigratePg = async (config) => {
14645
14659
  const outFolder = config.out;
14646
14660
  const schemaPath = config.schema;
14647
14661
  try {
14648
14662
  assertV1OutFolder(outFolder, "pg");
14649
14663
  const { snapshots, journal } = prepareMigrationFolder(outFolder, "pg");
14650
- const { prev, cur, custom } = await preparePgMigrationSnapshot(snapshots, schemaPath);
14664
+ const { prev, cur, custom } = await preparePgMigrationSnapshot(
14665
+ snapshots,
14666
+ schemaPath
14667
+ );
14651
14668
  const validatedPrev = pgSchema.parse(prev);
14652
14669
  const validatedCur = pgSchema.parse(cur);
14653
14670
  if (config.custom) {
@@ -14690,7 +14707,10 @@ var init_migrate = __esm({
14690
14707
  prepareMySQLPush = async (config, snapshot) => {
14691
14708
  const schemaPath = config.schema;
14692
14709
  try {
14693
- const { prev, cur } = await prepareMySqlDbPushSnapshot(snapshot, schemaPath);
14710
+ const { prev, cur } = await prepareMySqlDbPushSnapshot(
14711
+ snapshot,
14712
+ schemaPath
14713
+ );
14694
14714
  const validatedPrev = mysqlSchema.parse(prev);
14695
14715
  const validatedCur = mysqlSchema.parse(cur);
14696
14716
  const squashedPrev = squashMysqlScheme(validatedPrev);
@@ -14702,7 +14722,7 @@ var init_migrate = __esm({
14702
14722
  validatedPrev,
14703
14723
  validatedCur
14704
14724
  );
14705
- return { sqlStatements, statements };
14725
+ return { sqlStatements, statements, validatedCur, validatedPrev };
14706
14726
  } catch (e) {
14707
14727
  console.error(e);
14708
14728
  }
@@ -14710,7 +14730,10 @@ var init_migrate = __esm({
14710
14730
  prepareSQLitePush = async (config, snapshot) => {
14711
14731
  const schemaPath = config.schema;
14712
14732
  try {
14713
- const { prev, cur } = await prepareSQLiteDbPushSnapshot(snapshot, schemaPath);
14733
+ const { prev, cur } = await prepareSQLiteDbPushSnapshot(
14734
+ snapshot,
14735
+ schemaPath
14736
+ );
14714
14737
  const validatedPrev = sqliteSchema.parse(prev);
14715
14738
  const validatedCur = sqliteSchema.parse(cur);
14716
14739
  const squashedPrev = squashSqliteScheme(validatedPrev);
@@ -14722,7 +14745,13 @@ var init_migrate = __esm({
14722
14745
  validatedPrev,
14723
14746
  validatedCur
14724
14747
  );
14725
- return { sqlStatements, statements, squashedPrev, squashedCur, meta: _meta };
14748
+ return {
14749
+ sqlStatements,
14750
+ statements,
14751
+ squashedPrev,
14752
+ squashedCur,
14753
+ meta: _meta
14754
+ };
14726
14755
  } catch (e) {
14727
14756
  console.error(e);
14728
14757
  }
@@ -14730,7 +14759,11 @@ var init_migrate = __esm({
14730
14759
  preparePgPush = async (config, snapshot, schemaFilter) => {
14731
14760
  const schemaPath = config.schema;
14732
14761
  try {
14733
- const { prev, cur } = await preparePgDbPushSnapshot(snapshot, schemaPath, schemaFilter);
14762
+ const { prev, cur } = await preparePgDbPushSnapshot(
14763
+ snapshot,
14764
+ schemaPath,
14765
+ schemaFilter
14766
+ );
14734
14767
  const validatedPrev = pgSchema.parse(prev);
14735
14768
  const validatedCur = pgSchema.parse(cur);
14736
14769
  const squashedPrev = squashPgScheme(validatedPrev);
@@ -14753,7 +14786,10 @@ var init_migrate = __esm({
14753
14786
  try {
14754
14787
  assertV1OutFolder(outFolder, "mysql");
14755
14788
  const { snapshots, journal } = prepareMigrationFolder(outFolder, "mysql");
14756
- const { prev, cur, custom } = await prepareMySqlMigrationSnapshot(snapshots, schemaPath);
14789
+ const { prev, cur, custom } = await prepareMySqlMigrationSnapshot(
14790
+ snapshots,
14791
+ schemaPath
14792
+ );
14757
14793
  const validatedPrev = mysqlSchema.parse(prev);
14758
14794
  const validatedCur = mysqlSchema.parse(cur);
14759
14795
  if (config.custom) {
@@ -14799,7 +14835,10 @@ var init_migrate = __esm({
14799
14835
  try {
14800
14836
  assertV1OutFolder(outFolder, "sqlite");
14801
14837
  const { snapshots, journal } = prepareMigrationFolder(outFolder, "sqlite");
14802
- const { prev, cur, custom } = await prepareSqliteMigrationSnapshot(snapshots, schemaPath);
14838
+ const { prev, cur, custom } = await prepareSqliteMigrationSnapshot(
14839
+ snapshots,
14840
+ schemaPath
14841
+ );
14803
14842
  const validatedPrev = sqliteSchema.parse(prev);
14804
14843
  const validatedCur = sqliteSchema.parse(cur);
14805
14844
  if (config.custom) {
@@ -15318,7 +15357,7 @@ var init_sqlgenerator = __esm({
15318
15357
  convert(statement) {
15319
15358
  const unsquashed = MySqlSquasher.unsquashUnique(statement.data);
15320
15359
  const tableNameWithSchema = statement.schema ? `\`${statement.schema}\`.\`${statement.tableName}\`` : `\`${statement.tableName}\``;
15321
- return `ALTER TABLE ${tableNameWithSchema} DROP CONSTRAINT \`${unsquashed.name}\`;`;
15360
+ return `ALTER TABLE ${tableNameWithSchema} DROP INDEX \`${unsquashed.name}\`;`;
15322
15361
  }
15323
15362
  };
15324
15363
  SQLiteAlterTableAddUniqueConstraintConvertor = class extends Convertor {
@@ -16427,9 +16466,7 @@ var init_jsonStatements = __esm({
16427
16466
  schema: schema4,
16428
16467
  columns: Object.values(columns),
16429
16468
  compositePKs: Object.values(compositePrimaryKeys),
16430
- compositePkName: Object.values(compositePrimaryKeys).length > 0 ? json2.tables[name].compositePrimaryKeys[`${name}_${MySqlSquasher.unsquashPK(
16431
- Object.values(compositePrimaryKeys)[0]
16432
- ).columns.join("_")}`].name : "",
16469
+ compositePkName: Object.values(compositePrimaryKeys).length > 0 ? json2.tables[name].compositePrimaryKeys[MySqlSquasher.unsquashPK(Object.values(compositePrimaryKeys)[0]).name].name : "",
16433
16470
  uniqueConstraints: Object.values(uniqueConstraints)
16434
16471
  };
16435
16472
  };
@@ -16950,7 +16987,7 @@ var init_jsonStatements = __esm({
16950
16987
  type: "create_composite_pk",
16951
16988
  tableName,
16952
16989
  data: it,
16953
- constraintName: json2.tables[tableName].compositePrimaryKeys[`${tableName}_${unsquashed.columns.join("_")}`].name
16990
+ constraintName: json2.tables[tableName].compositePrimaryKeys[unsquashed.name].name
16954
16991
  });
16955
16992
  }
16956
16993
  return res;
@@ -16961,7 +16998,7 @@ var init_jsonStatements = __esm({
16961
16998
  type: "delete_composite_pk",
16962
16999
  tableName,
16963
17000
  data: it,
16964
- constraintName: json1.tables[tableName].compositePrimaryKeys[`${tableName}_${MySqlSquasher.unsquashPK(it).columns.join("_")}`].name
17001
+ constraintName: json1.tables[tableName].compositePrimaryKeys[MySqlSquasher.unsquashPK(it).name].name
16965
17002
  };
16966
17003
  });
16967
17004
  };
@@ -16972,8 +17009,8 @@ var init_jsonStatements = __esm({
16972
17009
  tableName,
16973
17010
  old: it.__old,
16974
17011
  new: it.__new,
16975
- oldConstraintName: json1.tables[tableName].compositePrimaryKeys[`${tableName}_${MySqlSquasher.unsquashPK(it.__old).columns.join("_")}`].name,
16976
- newConstraintName: json2.tables[tableName].compositePrimaryKeys[`${tableName}_${MySqlSquasher.unsquashPK(it.__new).columns.join("_")}`].name
17012
+ oldConstraintName: json1.tables[tableName].compositePrimaryKeys[MySqlSquasher.unsquashPK(it.__old).name].name,
17013
+ newConstraintName: json2.tables[tableName].compositePrimaryKeys[MySqlSquasher.unsquashPK(it.__new).name].name
16977
17014
  };
16978
17015
  });
16979
17016
  };
@@ -17342,19 +17379,17 @@ var init_snapshotsDiffer = __esm({
17342
17379
  curFull
17343
17380
  );
17344
17381
  } else {
17345
- if (doPerformDeleteAndCreate) {
17346
- addedCompositePKs = prepareAddCompositePrimaryKeyMySql(
17347
- it.name,
17348
- it.addedCompositePKs,
17349
- prevFull,
17350
- curFull
17351
- );
17352
- deletedCompositePKs = prepareDeleteCompositePrimaryKeyMySql(
17353
- it.name,
17354
- it.deletedCompositePKs,
17355
- prevFull
17356
- );
17357
- }
17382
+ addedCompositePKs = prepareAddCompositePrimaryKeyMySql(
17383
+ it.name,
17384
+ it.addedCompositePKs,
17385
+ prevFull,
17386
+ curFull
17387
+ );
17388
+ deletedCompositePKs = prepareDeleteCompositePrimaryKeyMySql(
17389
+ it.name,
17390
+ it.deletedCompositePKs,
17391
+ prevFull
17392
+ );
17358
17393
  alteredCompositePKs = prepareAlterCompositePrimaryKeyMySql(
17359
17394
  it.name,
17360
17395
  it.alteredCompositePKs,
@@ -17561,10 +17596,16 @@ var init_snapshotsDiffer = __esm({
17561
17596
  jsonStatements.push(...jsonRenameTables);
17562
17597
  jsonStatements.push(...jsonRenameColumnsStatements);
17563
17598
  jsonStatements.push(...jsonDeletedCompositePKs);
17564
- jsonStatements.push(...jsonDeletedUniqueConstraints);
17599
+ if (dialect6 !== "mysql") {
17600
+ jsonStatements.push(...jsonDeletedUniqueConstraints);
17601
+ }
17565
17602
  jsonStatements.push(...jsonDroppedReferencesForAlteredTables);
17566
17603
  jsonStatements.push(...jsonDropIndexesForAllAlteredTables);
17567
17604
  jsonStatements.push(...jsonTableAlternations.alterColumns);
17605
+ if (dialect6 === "mysql") {
17606
+ jsonStatements.push(...jsonAddedUniqueConstraints);
17607
+ jsonStatements.push(...jsonDeletedUniqueConstraints);
17608
+ }
17568
17609
  jsonStatements.push(...jsonTableAlternations.createColumns);
17569
17610
  jsonStatements.push(...jsonCreateIndexesForCreatedTables);
17570
17611
  jsonStatements.push(...jsonCreateIndexesForAllAlteredTables);
@@ -17574,7 +17615,9 @@ var init_snapshotsDiffer = __esm({
17574
17615
  jsonStatements.push(...jsonCreateReferences);
17575
17616
  jsonStatements.push(...jsonAddedCompositePKs);
17576
17617
  jsonStatements.push(...jsonAlteredCompositePKs);
17577
- jsonStatements.push(...jsonAddedUniqueConstraints);
17618
+ if (dialect6 !== "mysql") {
17619
+ jsonStatements.push(...jsonAddedUniqueConstraints);
17620
+ }
17578
17621
  jsonStatements.push(...jsonAlteredUniqueConstraints);
17579
17622
  jsonStatements.push(...jsonSetTableSchemas);
17580
17623
  jsonStatements.push(...filteredJsonSetNewTableSchemas);
@@ -19325,6 +19368,191 @@ var init_mysql = __esm({
19325
19368
  }
19326
19369
  });
19327
19370
 
19371
+ // node_modules/.pnpm/dotenv@16.0.3/node_modules/dotenv/package.json
19372
+ var require_package = __commonJS({
19373
+ "node_modules/.pnpm/dotenv@16.0.3/node_modules/dotenv/package.json"(exports, module2) {
19374
+ module2.exports = {
19375
+ name: "dotenv",
19376
+ version: "16.0.3",
19377
+ description: "Loads environment variables from .env file",
19378
+ main: "lib/main.js",
19379
+ types: "lib/main.d.ts",
19380
+ exports: {
19381
+ ".": {
19382
+ require: "./lib/main.js",
19383
+ types: "./lib/main.d.ts",
19384
+ default: "./lib/main.js"
19385
+ },
19386
+ "./config": "./config.js",
19387
+ "./config.js": "./config.js",
19388
+ "./lib/env-options": "./lib/env-options.js",
19389
+ "./lib/env-options.js": "./lib/env-options.js",
19390
+ "./lib/cli-options": "./lib/cli-options.js",
19391
+ "./lib/cli-options.js": "./lib/cli-options.js",
19392
+ "./package.json": "./package.json"
19393
+ },
19394
+ scripts: {
19395
+ "dts-check": "tsc --project tests/types/tsconfig.json",
19396
+ lint: "standard",
19397
+ "lint-readme": "standard-markdown",
19398
+ pretest: "npm run lint && npm run dts-check",
19399
+ test: "tap tests/*.js --100 -Rspec",
19400
+ prerelease: "npm test",
19401
+ release: "standard-version"
19402
+ },
19403
+ repository: {
19404
+ type: "git",
19405
+ url: "git://github.com/motdotla/dotenv.git"
19406
+ },
19407
+ keywords: [
19408
+ "dotenv",
19409
+ "env",
19410
+ ".env",
19411
+ "environment",
19412
+ "variables",
19413
+ "config",
19414
+ "settings"
19415
+ ],
19416
+ readmeFilename: "README.md",
19417
+ license: "BSD-2-Clause",
19418
+ devDependencies: {
19419
+ "@types/node": "^17.0.9",
19420
+ decache: "^4.6.1",
19421
+ dtslint: "^3.7.0",
19422
+ sinon: "^12.0.1",
19423
+ standard: "^16.0.4",
19424
+ "standard-markdown": "^7.1.0",
19425
+ "standard-version": "^9.3.2",
19426
+ tap: "^15.1.6",
19427
+ tar: "^6.1.11",
19428
+ typescript: "^4.5.4"
19429
+ },
19430
+ engines: {
19431
+ node: ">=12"
19432
+ }
19433
+ };
19434
+ }
19435
+ });
19436
+
19437
+ // node_modules/.pnpm/dotenv@16.0.3/node_modules/dotenv/lib/main.js
19438
+ var require_main = __commonJS({
19439
+ "node_modules/.pnpm/dotenv@16.0.3/node_modules/dotenv/lib/main.js"(exports, module2) {
19440
+ var fs8 = require("fs");
19441
+ var path4 = require("path");
19442
+ var os2 = require("os");
19443
+ var packageJson = require_package();
19444
+ var version2 = packageJson.version;
19445
+ var LINE = /(?:^|^)\s*(?:export\s+)?([\w.-]+)(?:\s*=\s*?|:\s+?)(\s*'(?:\\'|[^'])*'|\s*"(?:\\"|[^"])*"|\s*`(?:\\`|[^`])*`|[^#\r\n]+)?\s*(?:#.*)?(?:$|$)/mg;
19446
+ function parse(src) {
19447
+ const obj = {};
19448
+ let lines = src.toString();
19449
+ lines = lines.replace(/\r\n?/mg, "\n");
19450
+ let match2;
19451
+ while ((match2 = LINE.exec(lines)) != null) {
19452
+ const key = match2[1];
19453
+ let value = match2[2] || "";
19454
+ value = value.trim();
19455
+ const maybeQuote = value[0];
19456
+ value = value.replace(/^(['"`])([\s\S]*)\1$/mg, "$2");
19457
+ if (maybeQuote === '"') {
19458
+ value = value.replace(/\\n/g, "\n");
19459
+ value = value.replace(/\\r/g, "\r");
19460
+ }
19461
+ obj[key] = value;
19462
+ }
19463
+ return obj;
19464
+ }
19465
+ function _log(message) {
19466
+ console.log(`[dotenv@${version2}][DEBUG] ${message}`);
19467
+ }
19468
+ function _resolveHome(envPath) {
19469
+ return envPath[0] === "~" ? path4.join(os2.homedir(), envPath.slice(1)) : envPath;
19470
+ }
19471
+ function config(options) {
19472
+ let dotenvPath = path4.resolve(process.cwd(), ".env");
19473
+ let encoding = "utf8";
19474
+ const debug = Boolean(options && options.debug);
19475
+ const override = Boolean(options && options.override);
19476
+ if (options) {
19477
+ if (options.path != null) {
19478
+ dotenvPath = _resolveHome(options.path);
19479
+ }
19480
+ if (options.encoding != null) {
19481
+ encoding = options.encoding;
19482
+ }
19483
+ }
19484
+ try {
19485
+ const parsed = DotenvModule.parse(fs8.readFileSync(dotenvPath, { encoding }));
19486
+ Object.keys(parsed).forEach(function(key) {
19487
+ if (!Object.prototype.hasOwnProperty.call(process.env, key)) {
19488
+ process.env[key] = parsed[key];
19489
+ } else {
19490
+ if (override === true) {
19491
+ process.env[key] = parsed[key];
19492
+ }
19493
+ if (debug) {
19494
+ if (override === true) {
19495
+ _log(`"${key}" is already defined in \`process.env\` and WAS overwritten`);
19496
+ } else {
19497
+ _log(`"${key}" is already defined in \`process.env\` and was NOT overwritten`);
19498
+ }
19499
+ }
19500
+ }
19501
+ });
19502
+ return { parsed };
19503
+ } catch (e) {
19504
+ if (debug) {
19505
+ _log(`Failed to load ${dotenvPath} ${e.message}`);
19506
+ }
19507
+ return { error: e };
19508
+ }
19509
+ }
19510
+ var DotenvModule = {
19511
+ config,
19512
+ parse
19513
+ };
19514
+ module2.exports.config = DotenvModule.config;
19515
+ module2.exports.parse = DotenvModule.parse;
19516
+ module2.exports = DotenvModule;
19517
+ }
19518
+ });
19519
+
19520
+ // node_modules/.pnpm/dotenv@16.0.3/node_modules/dotenv/lib/env-options.js
19521
+ var require_env_options = __commonJS({
19522
+ "node_modules/.pnpm/dotenv@16.0.3/node_modules/dotenv/lib/env-options.js"(exports, module2) {
19523
+ var options = {};
19524
+ if (process.env.DOTENV_CONFIG_ENCODING != null) {
19525
+ options.encoding = process.env.DOTENV_CONFIG_ENCODING;
19526
+ }
19527
+ if (process.env.DOTENV_CONFIG_PATH != null) {
19528
+ options.path = process.env.DOTENV_CONFIG_PATH;
19529
+ }
19530
+ if (process.env.DOTENV_CONFIG_DEBUG != null) {
19531
+ options.debug = process.env.DOTENV_CONFIG_DEBUG;
19532
+ }
19533
+ if (process.env.DOTENV_CONFIG_OVERRIDE != null) {
19534
+ options.override = process.env.DOTENV_CONFIG_OVERRIDE;
19535
+ }
19536
+ module2.exports = options;
19537
+ }
19538
+ });
19539
+
19540
+ // node_modules/.pnpm/dotenv@16.0.3/node_modules/dotenv/lib/cli-options.js
19541
+ var require_cli_options = __commonJS({
19542
+ "node_modules/.pnpm/dotenv@16.0.3/node_modules/dotenv/lib/cli-options.js"(exports, module2) {
19543
+ var re = /^dotenv_config_(encoding|path|debug|override)=(.+)$/;
19544
+ module2.exports = function optionMatcher(args) {
19545
+ return args.reduce(function(acc, cur) {
19546
+ const matches = cur.match(re);
19547
+ if (matches) {
19548
+ acc[matches[1]] = matches[2];
19549
+ }
19550
+ return acc;
19551
+ }, {});
19552
+ };
19553
+ }
19554
+ });
19555
+
19328
19556
  // node_modules/.pnpm/sqlstring@2.3.3/node_modules/sqlstring/lib/SqlString.js
19329
19557
  var require_SqlString = __commonJS({
19330
19558
  "node_modules/.pnpm/sqlstring@2.3.3/node_modules/sqlstring/lib/SqlString.js"(exports) {
@@ -36106,34 +36334,36 @@ import { sql } from "drizzle-orm"
36106
36334
  return `${withCasing(name, casing)}: serial("${name}")`;
36107
36335
  }
36108
36336
  if (lowered.startsWith("int")) {
36109
- let out = `${withCasing(name, casing)}: int("${name}")`;
36337
+ const isUnsigned = lowered.startsWith("int unsigned");
36338
+ let out = `${withCasing(name, casing)}: int("${name}"${isUnsigned ? ", { unsigned: true }" : ""})`;
36110
36339
  out += autoincrement ? `.autoincrement()` : "";
36111
36340
  out += typeof defaultValue !== "undefined" ? `.default(${mapColumnDefault(defaultValue, isExpression)})` : "";
36112
36341
  return out;
36113
36342
  }
36114
36343
  if (lowered.startsWith("tinyint")) {
36115
- let out = `${withCasing(name, casing)}: tinyint("${name}")`;
36344
+ const isUnsigned = lowered.startsWith("tinyint unsigned");
36345
+ let out = `${withCasing(name, casing)}: tinyint("${name}"${isUnsigned ? ", { unsigned: true }" : ""})`;
36116
36346
  out += autoincrement ? `.autoincrement()` : "";
36117
36347
  out += typeof defaultValue !== "undefined" ? `.default(${mapColumnDefault(defaultValue, isExpression)})` : "";
36118
36348
  return out;
36119
36349
  }
36120
36350
  if (lowered.startsWith("smallint")) {
36121
- let out = `${withCasing(name, casing)}: smallint("${name}")`;
36351
+ const isUnsigned = lowered.startsWith("smallint unsigned");
36352
+ let out = `${withCasing(name, casing)}: smallint("${name}"${isUnsigned ? ", { unsigned: true }" : ""})`;
36122
36353
  out += autoincrement ? `.autoincrement()` : "";
36123
36354
  out += defaultValue ? `.default(${mapColumnDefault(defaultValue, isExpression)})` : "";
36124
36355
  return out;
36125
36356
  }
36126
36357
  if (lowered.startsWith("mediumint")) {
36127
- let out = `${withCasing(name, casing)}: mediumint("${name}")`;
36358
+ const isUnsigned = lowered.startsWith("mediumint unsigned");
36359
+ let out = `${withCasing(name, casing)}: mediumint("${name}"${isUnsigned ? ", { unsigned: true }" : ""})`;
36128
36360
  out += autoincrement ? `.autoincrement()` : "";
36129
36361
  out += defaultValue ? `.default(${mapColumnDefault(defaultValue, isExpression)})` : "";
36130
36362
  return out;
36131
36363
  }
36132
36364
  if (lowered.startsWith("bigint")) {
36133
- let out = `${withCasing(
36134
- name,
36135
- casing
36136
- )}: bigint("${name}", { mode: "number" })`;
36365
+ const isUnsigned = lowered.startsWith("bigint unsigned");
36366
+ let out = `${withCasing(name, casing)}: bigint("${name}", { mode: "number"${isUnsigned ? ", unsigned: true" : ""} })`;
36137
36367
  out += autoincrement ? `.autoincrement()` : "";
36138
36368
  out += defaultValue ? `.default(${mapColumnDefault(defaultValue, isExpression)})` : "";
36139
36369
  return out;
@@ -36388,10 +36618,10 @@ import { sql } from "drizzle-orm"
36388
36618
  pks.forEach((it) => {
36389
36619
  let idxKey = withCasing(it.name, casing);
36390
36620
  statement += ` ${idxKey}: `;
36391
- statement += "primaryKey(";
36621
+ statement += "primaryKey({ columns: [";
36392
36622
  statement += `${it.columns.map((c) => {
36393
36623
  return `table.${withCasing(c, casing)}`;
36394
- }).join(", ")}`;
36624
+ }).join(", ")}]${it.name ? `, name: "${it.name}"` : ""}}`;
36395
36625
  statement += "),";
36396
36626
  statement += `
36397
36627
  `;
@@ -36407,7 +36637,9 @@ import { sql } from "drizzle-orm"
36407
36637
  `;
36408
36638
  statement += ` columns: [${it.columnsFrom.map((i) => `table.${withCasing(i, casing)}`).join(", ")}],
36409
36639
  `;
36410
- statement += ` foreignColumns: [${it.columnsTo.map((i) => `${tableTo}.${withCasing(i, casing)}`).join(", ")}]
36640
+ statement += ` foreignColumns: [${it.columnsTo.map((i) => `${tableTo}.${withCasing(i, casing)}`).join(", ")}],
36641
+ `;
36642
+ statement += ` name: "${it.name}"
36411
36643
  `;
36412
36644
  statement += ` })`;
36413
36645
  statement += it.onUpdate && it.onUpdate !== "no action" ? `.onUpdate("${it.onUpdate}")` : "";
@@ -41838,7 +42070,7 @@ var require_pg_pool = __commonJS({
41838
42070
  });
41839
42071
 
41840
42072
  // node_modules/.pnpm/pg@8.8.0/node_modules/pg/package.json
41841
- var require_package = __commonJS({
42073
+ var require_package2 = __commonJS({
41842
42074
  "node_modules/.pnpm/pg@8.8.0/node_modules/pg/package.json"(exports, module2) {
41843
42075
  module2.exports = {
41844
42076
  name: "pg",
@@ -42048,7 +42280,7 @@ var require_client3 = __commonJS({
42048
42280
  "use strict";
42049
42281
  var Native = require("pg-native");
42050
42282
  var TypeOverrides = require_type_overrides();
42051
- var pkg = require_package();
42283
+ var pkg = require_package2();
42052
42284
  var EventEmitter = require("events").EventEmitter;
42053
42285
  var util2 = require("util");
42054
42286
  var ConnectionParameters = require_connection_parameters();
@@ -42872,10 +43104,10 @@ var init_introspect = __esm({
42872
43104
  pks.forEach((it) => {
42873
43105
  let idxKey = withCasing2(it.name, casing);
42874
43106
  statement += ` ${idxKey}: `;
42875
- statement += "primaryKey(";
43107
+ statement += "primaryKey({ columns: [";
42876
43108
  statement += `${it.columns.map((c) => {
42877
43109
  return `table.${withCasing2(c, casing)}`;
42878
- }).join(", ")}`;
43110
+ }).join(", ")}]${it.name ? `, name: "${it.name}"` : ""}}`;
42879
43111
  statement += ")";
42880
43112
  statement += `
42881
43113
  `;
@@ -42905,7 +43137,9 @@ var init_introspect = __esm({
42905
43137
  `;
42906
43138
  statement += ` columns: [${it.columnsFrom.map((i) => `table.${withCasing2(i, casing)}`).join(", ")}],
42907
43139
  `;
42908
- statement += ` foreignColumns: [${it.columnsTo.map((i) => `${tableTo}.${withCasing2(i, casing)}`).join(", ")}]
43140
+ statement += ` foreignColumns: [${it.columnsTo.map((i) => `${tableTo}.${withCasing2(i, casing)}`).join(", ")}],
43141
+ `;
43142
+ statement += ` name: "${it.name}"
42909
43143
  `;
42910
43144
  statement += ` })`;
42911
43145
  statement += it.onUpdate && it.onUpdate !== "no action" ? `.onUpdate("${it.onUpdate}")` : "";
@@ -43289,10 +43523,10 @@ import { sql } from "drizzle-orm"
43289
43523
  let statement = "";
43290
43524
  pks.forEach((it, i) => {
43291
43525
  statement += ` pk${i}: `;
43292
- statement += "primaryKey(";
43526
+ statement += "primaryKey({ columns: [";
43293
43527
  statement += `${it.columns.map((c) => {
43294
43528
  return `table.${withCasing3(c, casing)}`;
43295
- }).join(", ")}`;
43529
+ }).join(", ")}]${it.name ? `, name: "${it.name}"` : ""}}`;
43296
43530
  statement += ")";
43297
43531
  statement += `
43298
43532
  `;
@@ -43308,7 +43542,9 @@ import { sql } from "drizzle-orm"
43308
43542
  `;
43309
43543
  statement += ` columns: [${it.columnsFrom.map((i) => `table.${withCasing3(i, casing)}`).join(", ")}],
43310
43544
  `;
43311
- statement += ` foreignColumns: [${it.columnsTo.map((i) => `${tableTo}.${withCasing3(i, casing)}`).join(", ")}]
43545
+ statement += ` foreignColumns: [${it.columnsTo.map((i) => `${tableTo}.${withCasing3(i, casing)}`).join(", ")}],
43546
+ `;
43547
+ statement += ` name: "${it.name}"
43312
43548
  `;
43313
43549
  statement += ` }))`;
43314
43550
  statement += it.onUpdate && it.onUpdate !== "no action" ? `.onUpdate("${it.onUpdate}")` : "";
@@ -67623,7 +67859,7 @@ var init_studioUtils = __esm({
67623
67859
  const imports = prepareFilenames(path4);
67624
67860
  const sqliteSchema2 = {};
67625
67861
  const pgSchema3 = {};
67626
- const mysqlSchema3 = {};
67862
+ const mysqlSchema4 = {};
67627
67863
  const { unregister } = safeRegister();
67628
67864
  for (let i = 0; i < imports.length; i++) {
67629
67865
  const it = imports[i];
@@ -67634,7 +67870,7 @@ var init_studioUtils = __esm({
67634
67870
  pgSchema3[k] = t;
67635
67871
  }
67636
67872
  if ((0, import_drizzle_orm15.is)(t, import_mysql_core4.MySqlTable)) {
67637
- mysqlSchema3[k] = t;
67873
+ mysqlSchema4[k] = t;
67638
67874
  }
67639
67875
  if ((0, import_drizzle_orm15.is)(t, import_sqlite_core5.SQLiteTable)) {
67640
67876
  sqliteSchema2[k] = t;
@@ -67642,12 +67878,12 @@ var init_studioUtils = __esm({
67642
67878
  if ((0, import_drizzle_orm15.is)(t, import_drizzle_orm15.Relations)) {
67643
67879
  sqliteSchema2[k] = t;
67644
67880
  pgSchema3[k] = t;
67645
- mysqlSchema3[k] = t;
67881
+ mysqlSchema4[k] = t;
67646
67882
  }
67647
67883
  });
67648
67884
  }
67649
67885
  unregister();
67650
- return { pgSchema: pgSchema3, mysqlSchema: mysqlSchema3, sqliteSchema: sqliteSchema2 };
67886
+ return { pgSchema: pgSchema3, mysqlSchema: mysqlSchema4, sqliteSchema: sqliteSchema2 };
67651
67887
  };
67652
67888
  drizzleDb = async (drizzleConfig, models, logger) => {
67653
67889
  if (drizzleConfig.driver === "pg") {
@@ -67714,7 +67950,8 @@ var init_studioUtils = __esm({
67714
67950
  var cli_exports = {};
67715
67951
  __export(cli_exports, {
67716
67952
  Select: () => Select,
67717
- checkSchema: () => checkSchema
67953
+ checkSchema: () => checkSchema,
67954
+ defineConfig: () => defineConfig
67718
67955
  });
67719
67956
  module.exports = __toCommonJS(cli_exports);
67720
67957
  var import_commander = require("commander");
@@ -67814,7 +68051,7 @@ init_source();
67814
68051
  // package.json
67815
68052
  var package_default = {
67816
68053
  name: "drizzle-kit",
67817
- version: "0.19.14",
68054
+ version: "0.20.0",
67818
68055
  repository: "https://github.com/drizzle-team/drizzle-kit-mirror",
67819
68056
  author: "Drizzle Team",
67820
68057
  license: "MIT",
@@ -67896,7 +68133,7 @@ var package_default = {
67896
68133
  "better-sqlite3": "^8.4.0",
67897
68134
  dockerode: "^3.3.4",
67898
68135
  dotenv: "^16.0.3",
67899
- "drizzle-orm": "0.28.6",
68136
+ "drizzle-orm": "0.28.7-4e094f0",
67900
68137
  eslint: "^8.29.0",
67901
68138
  "eslint-config-prettier": "^8.5.0",
67902
68139
  "eslint-plugin-prettier": "^4.2.1",
@@ -68006,12 +68243,18 @@ init_utils();
68006
68243
  init_source();
68007
68244
  var import_hanji5 = __toESM(require_hanji());
68008
68245
  init_mysqlSchema();
68009
- var filterStatements = (statements) => {
68246
+ var filterStatements = (statements, currentSchema, prevSchema) => {
68010
68247
  return statements.filter((statement) => {
68011
68248
  if (statement.type === "alter_table_alter_column_set_type") {
68012
68249
  if (statement.oldDataType.startsWith("tinyint") && statement.newDataType.startsWith("boolean")) {
68013
68250
  return false;
68014
68251
  }
68252
+ if (statement.oldDataType.startsWith("bigint unsigned") && statement.newDataType.startsWith("serial")) {
68253
+ return false;
68254
+ }
68255
+ if (statement.oldDataType.startsWith("serial") && statement.newDataType.startsWith("bigint unsigned")) {
68256
+ return false;
68257
+ }
68015
68258
  } else if (statement.type === "alter_table_alter_column_set_default") {
68016
68259
  if (statement.newDefaultValue === false && statement.oldDefaultValue === 0 && statement.newDataType === "boolean") {
68017
68260
  return false;
@@ -68019,6 +68262,24 @@ var filterStatements = (statements) => {
68019
68262
  if (statement.newDefaultValue === true && statement.oldDefaultValue === 1 && statement.newDataType === "boolean") {
68020
68263
  return false;
68021
68264
  }
68265
+ } else if (statement.type === "delete_unique_constraint") {
68266
+ const unsquashed = MySqlSquasher.unsquashUnique(statement.data);
68267
+ if (unsquashed.columns.length === 1 && currentSchema.tables[statement.tableName].columns[unsquashed.columns[0]].type === "serial" && prevSchema.tables[statement.tableName].columns[unsquashed.columns[0]].type === "serial" && currentSchema.tables[statement.tableName].columns[unsquashed.columns[0]].name === unsquashed.columns[0]) {
68268
+ return false;
68269
+ }
68270
+ } else if (statement.type === "alter_table_alter_column_drop_notnull") {
68271
+ const serialStatement = statements.find(
68272
+ (it) => it.type === "alter_table_alter_column_set_type"
68273
+ );
68274
+ if ((serialStatement == null ? void 0 : serialStatement.oldDataType.startsWith("bigint unsigned")) && (serialStatement == null ? void 0 : serialStatement.newDataType.startsWith("serial")) && serialStatement.columnName === statement.columnName && serialStatement.tableName === statement.tableName) {
68275
+ return false;
68276
+ }
68277
+ if (statement.newDataType === "serial" && !statement.columnNotNull) {
68278
+ return false;
68279
+ }
68280
+ if (statement.columnAutoIncrement) {
68281
+ return false;
68282
+ }
68022
68283
  }
68023
68284
  return true;
68024
68285
  });
@@ -68710,6 +68971,20 @@ var pgSuggestions = async ({
68710
68971
  // src/cli/index.ts
68711
68972
  init_outputs();
68712
68973
  var import_studio = require("@drizzle-team/studio");
68974
+ init_sqlgenerator();
68975
+
68976
+ // node_modules/.pnpm/dotenv@16.0.3/node_modules/dotenv/config.js
68977
+ (function() {
68978
+ require_main().config(
68979
+ Object.assign(
68980
+ {},
68981
+ require_env_options(),
68982
+ require_cli_options()(process.argv)
68983
+ )
68984
+ );
68985
+ })();
68986
+
68987
+ // src/cli/index.ts
68713
68988
  var printVersions = async () => {
68714
68989
  const v = await versions();
68715
68990
  console.log(`${source_default.gray(v)}
@@ -68825,12 +69100,16 @@ var dbPushMysqlCommand = new import_commander.Command("push:mysql").option(
68825
69100
  { schema: drizzleConfig.schema },
68826
69101
  schema4
68827
69102
  );
69103
+ const filteredStatements = filterStatements(
69104
+ (statements == null ? void 0 : statements.statements) ?? [],
69105
+ statements == null ? void 0 : statements.validatedCur,
69106
+ statements == null ? void 0 : statements.validatedPrev
69107
+ );
68828
69108
  try {
68829
- if (typeof statements === "undefined") {
68830
- } else if (statements.sqlStatements.length === 0) {
69109
+ if (typeof filteredStatements === "undefined") {
69110
+ } else if (filteredStatements.length === 0) {
68831
69111
  (0, import_hanji10.render)(`[${source_default.blue("i")}] No changes detected`);
68832
69112
  } else {
68833
- const filteredStatements = filterStatements(statements.statements);
68834
69113
  const {
68835
69114
  shouldAskForApprove,
68836
69115
  statementsToExecute,
@@ -68843,6 +69122,9 @@ var dbPushMysqlCommand = new import_commander.Command("push:mysql").option(
68843
69122
  connection: connection.client,
68844
69123
  statements: filteredStatements
68845
69124
  });
69125
+ const filteredSqlStatements = filteredStatements.map(
69126
+ (filteredStatement) => fromJson([filteredStatement], "mysql")[0]
69127
+ );
68846
69128
  if (drizzleConfig.verbose) {
68847
69129
  console.log();
68848
69130
  console.log(
@@ -68850,7 +69132,7 @@ var dbPushMysqlCommand = new import_commander.Command("push:mysql").option(
68850
69132
  );
68851
69133
  console.log();
68852
69134
  console.log(
68853
- [...statementsToExecute, ...statements.sqlStatements].map((s) => source_default.blue(s)).join("\n")
69135
+ [...statementsToExecute, ...filteredSqlStatements].map((s) => source_default.blue(s)).join("\n")
68854
69136
  );
68855
69137
  console.log();
68856
69138
  }
@@ -68889,7 +69171,7 @@ var dbPushMysqlCommand = new import_commander.Command("push:mysql").option(
68889
69171
  for (const dStmnt of statementsToExecute) {
68890
69172
  await connection.client.query(dStmnt);
68891
69173
  }
68892
- for (const statement of statements.sqlStatements) {
69174
+ for (const statement of filteredSqlStatements) {
68893
69175
  await connection.client.query(statement);
68894
69176
  }
68895
69177
  if (filteredStatements.length > 0) {
@@ -69241,7 +69523,7 @@ var upSqliteCommand = new import_commander.Command("up:sqlite").option("--out <o
69241
69523
  var introspectPgCommand = new import_commander.Command("introspect:pg").option("--out <out>", `Migrations folder`).option("--breakpoints", `Prepare SQL statements with breakpoints`).option(
69242
69524
  "--introspect-casing <introspectCasing>",
69243
69525
  "Column object keys naming strategy"
69244
- ).option("--driver <driver>", "Postgres connection string").option("--connectionString <connectionString>", "Postgres connection string").option("--host <host>", "Postgres host").option("--port <port>", "Postgres port").option("--user <user>", "Postgres user").option("--password <password>", "Postgres password").option("--database <database>", "Postgres database name").option("--ssl <ssl>", "Postgres ssl").option("--config <config>", `Config path [default=drizzle.config.ts]`).action(async (options) => {
69526
+ ).option("--tablesFilter", `Table name filters`).option("--driver <driver>", "Postgres connection string").option("--connectionString <connectionString>", "Postgres connection string").option("--host <host>", "Postgres host").option("--port <port>", "Postgres port").option("--user <user>", "Postgres user").option("--password <password>", "Postgres password").option("--database <database>", "Postgres database name").option("--ssl <ssl>", "Postgres ssl").option("--config <config>", `Config path [default=drizzle.config.ts]`).action(async (options) => {
69245
69527
  await printVersions();
69246
69528
  await assertPackages("drizzle-orm");
69247
69529
  await assertOrmCoreVersion();
@@ -69301,7 +69583,7 @@ var introspectMySqlCommand = new import_commander.Command("introspect:mysql").op
69301
69583
  ).option(
69302
69584
  "--introspect-casing <introspectCasing>",
69303
69585
  "Column object keys naming strategy"
69304
- ).option("--out <out>", `Migrations folder`).option("--breakpoints", `Prepare SQL statements with breakpoints`).option("--connectionString <connectionString>", "MySQL connection string").option("--host <host>", "MySQL host").option("--port <port>", "MySQL port").option("--user <user>", "MySQL user").option("--password <password>", "MySQL password").option("--database <database>", "MySQL database name").action(async (options) => {
69586
+ ).option("--tablesFilter", `Table name filters`).option("--out <out>", `Migrations folder`).option("--breakpoints", `Prepare SQL statements with breakpoints`).option("--connectionString <connectionString>", "MySQL connection string").option("--host <host>", "MySQL host").option("--port <port>", "MySQL port").option("--user <user>", "MySQL user").option("--password <password>", "MySQL password").option("--database <database>", "MySQL database name").action(async (options) => {
69305
69587
  await printVersions();
69306
69588
  await assertPackages("drizzle-orm");
69307
69589
  await assertOrmCoreVersion();
@@ -69354,7 +69636,7 @@ var introspectSQLiteCommand = new import_commander.Command("introspect:sqlite").
69354
69636
  ).option(
69355
69637
  "--introspect-casing <introspectCasing>",
69356
69638
  "Column object keys naming strategy"
69357
- ).option("--schema <schema>", `Migrations folder`).option("--out <out>", `Migrations folder`).option("--breakpoints", `Prepare SQL statements with breakpoints`).option("--driver <driver>", "SQLite database path").option("--url <url>", "SQLite database url").option("--auth-token <authToken>", "SQLite database path").action(async (options) => {
69639
+ ).option("--tablesFilter", `Table name filters`).option("--schema <schema>", `Migrations folder`).option("--out <out>", `Migrations folder`).option("--breakpoints", `Prepare SQL statements with breakpoints`).option("--driver <driver>", "SQLite database path").option("--url <url>", "SQLite database url").option("--auth-token <authToken>", "SQLite database path").action(async (options) => {
69358
69640
  printVersions();
69359
69641
  assertPackages("drizzle-orm");
69360
69642
  assertOrmCoreVersion();
@@ -69483,11 +69765,15 @@ var main = async () => {
69483
69765
  import_commander.program.addCommand(studioCommand);
69484
69766
  import_commander.program.parse();
69485
69767
  };
69768
+ function defineConfig(config) {
69769
+ return config;
69770
+ }
69486
69771
  main();
69487
69772
  // Annotate the CommonJS export names for ESM import in node:
69488
69773
  0 && (module.exports = {
69489
69774
  Select,
69490
- checkSchema
69775
+ checkSchema,
69776
+ defineConfig
69491
69777
  });
69492
69778
  /*! Bundled license information:
69493
69779
 
package/index.d.ts CHANGED
@@ -55,3 +55,4 @@ export type Config = {
55
55
  wranglerConfigPath: string;
56
56
  };
57
57
  } | {});
58
+ export declare function defineConfig(config: Config): Config;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "drizzle-kit",
3
- "version": "0.19.14-039355d",
3
+ "version": "0.20.0-f39d8bc",
4
4
  "repository": "https://github.com/drizzle-team/drizzle-kit-mirror",
5
5
  "author": "Drizzle Team",
6
6
  "license": "MIT",
@@ -82,7 +82,7 @@
82
82
  "better-sqlite3": "^8.4.0",
83
83
  "dockerode": "^3.3.4",
84
84
  "dotenv": "^16.0.3",
85
- "drizzle-orm": "0.28.6",
85
+ "drizzle-orm": "0.28.7-4e094f0",
86
86
  "eslint": "^8.29.0",
87
87
  "eslint-config-prettier": "^8.5.0",
88
88
  "eslint-plugin-prettier": "^4.2.1",
package/utils.js CHANGED
@@ -12696,6 +12696,13 @@ var init_serializer = __esm({
12696
12696
  }
12697
12697
  });
12698
12698
 
12699
+ // src/cli/validations/outputs.ts
12700
+ var init_outputs = __esm({
12701
+ "src/cli/validations/outputs.ts"() {
12702
+ init_source();
12703
+ }
12704
+ });
12705
+
12699
12706
  // src/utils.ts
12700
12707
  var utils_exports = {};
12701
12708
  __export(utils_exports, {
@@ -13265,7 +13272,8 @@ var fk3 = objectType({
13265
13272
  onDelete: stringType().optional()
13266
13273
  }).strict();
13267
13274
  var compositePK3 = objectType({
13268
- columns: stringType().array()
13275
+ columns: stringType().array(),
13276
+ name: stringType()
13269
13277
  }).strict();
13270
13278
  var column3 = objectType({
13271
13279
  name: stringType(),
@@ -13656,6 +13664,7 @@ init_serializer();
13656
13664
  var import_hanji2 = __toESM(require_hanji());
13657
13665
  init_views();
13658
13666
  init_source();
13667
+ init_outputs();
13659
13668
  var BREAKPOINT = "--> statement-breakpoint\n";
13660
13669
 
13661
13670
  // src/sqlgenerator.ts
@@ -13886,7 +13895,7 @@ var MySQLAlterTableDropUniqueConstraintConvertor = class extends Convertor {
13886
13895
  convert(statement) {
13887
13896
  const unsquashed = MySqlSquasher.unsquashUnique(statement.data);
13888
13897
  const tableNameWithSchema = statement.schema ? `\`${statement.schema}\`.\`${statement.tableName}\`` : `\`${statement.tableName}\``;
13889
- return `ALTER TABLE ${tableNameWithSchema} DROP CONSTRAINT \`${unsquashed.name}\`;`;
13898
+ return `ALTER TABLE ${tableNameWithSchema} DROP INDEX \`${unsquashed.name}\`;`;
13890
13899
  }
13891
13900
  };
13892
13901
  var SQLiteAlterTableAddUniqueConstraintConvertor = class extends Convertor {
@@ -14990,9 +14999,7 @@ var prepareMySqlCreateTableJson = (table4, json2) => {
14990
14999
  schema: schema4,
14991
15000
  columns: Object.values(columns),
14992
15001
  compositePKs: Object.values(compositePrimaryKeys),
14993
- compositePkName: Object.values(compositePrimaryKeys).length > 0 ? json2.tables[name].compositePrimaryKeys[`${name}_${MySqlSquasher.unsquashPK(
14994
- Object.values(compositePrimaryKeys)[0]
14995
- ).columns.join("_")}`].name : "",
15002
+ compositePkName: Object.values(compositePrimaryKeys).length > 0 ? json2.tables[name].compositePrimaryKeys[MySqlSquasher.unsquashPK(Object.values(compositePrimaryKeys)[0]).name].name : "",
14996
15003
  uniqueConstraints: Object.values(uniqueConstraints)
14997
15004
  };
14998
15005
  };
@@ -15513,7 +15520,7 @@ var prepareAddCompositePrimaryKeyMySql = (tableName, pks, json1, json2) => {
15513
15520
  type: "create_composite_pk",
15514
15521
  tableName,
15515
15522
  data: it,
15516
- constraintName: json2.tables[tableName].compositePrimaryKeys[`${tableName}_${unsquashed.columns.join("_")}`].name
15523
+ constraintName: json2.tables[tableName].compositePrimaryKeys[unsquashed.name].name
15517
15524
  });
15518
15525
  }
15519
15526
  return res;
@@ -15524,7 +15531,7 @@ var prepareDeleteCompositePrimaryKeyMySql = (tableName, pks, json1) => {
15524
15531
  type: "delete_composite_pk",
15525
15532
  tableName,
15526
15533
  data: it,
15527
- constraintName: json1.tables[tableName].compositePrimaryKeys[`${tableName}_${MySqlSquasher.unsquashPK(it).columns.join("_")}`].name
15534
+ constraintName: json1.tables[tableName].compositePrimaryKeys[MySqlSquasher.unsquashPK(it).name].name
15528
15535
  };
15529
15536
  });
15530
15537
  };
@@ -15535,8 +15542,8 @@ var prepareAlterCompositePrimaryKeyMySql = (tableName, pks, json1, json2) => {
15535
15542
  tableName,
15536
15543
  old: it.__old,
15537
15544
  new: it.__new,
15538
- oldConstraintName: json1.tables[tableName].compositePrimaryKeys[`${tableName}_${MySqlSquasher.unsquashPK(it.__old).columns.join("_")}`].name,
15539
- newConstraintName: json2.tables[tableName].compositePrimaryKeys[`${tableName}_${MySqlSquasher.unsquashPK(it.__new).columns.join("_")}`].name
15545
+ oldConstraintName: json1.tables[tableName].compositePrimaryKeys[MySqlSquasher.unsquashPK(it.__old).name].name,
15546
+ newConstraintName: json2.tables[tableName].compositePrimaryKeys[MySqlSquasher.unsquashPK(it.__new).name].name
15540
15547
  };
15541
15548
  });
15542
15549
  };
@@ -15893,19 +15900,17 @@ var applySnapshotsDiff = async (json1, json2, dialect3, schemasResolver, tablesR
15893
15900
  curFull
15894
15901
  );
15895
15902
  } else {
15896
- if (doPerformDeleteAndCreate) {
15897
- addedCompositePKs = prepareAddCompositePrimaryKeyMySql(
15898
- it.name,
15899
- it.addedCompositePKs,
15900
- prevFull,
15901
- curFull
15902
- );
15903
- deletedCompositePKs = prepareDeleteCompositePrimaryKeyMySql(
15904
- it.name,
15905
- it.deletedCompositePKs,
15906
- prevFull
15907
- );
15908
- }
15903
+ addedCompositePKs = prepareAddCompositePrimaryKeyMySql(
15904
+ it.name,
15905
+ it.addedCompositePKs,
15906
+ prevFull,
15907
+ curFull
15908
+ );
15909
+ deletedCompositePKs = prepareDeleteCompositePrimaryKeyMySql(
15910
+ it.name,
15911
+ it.deletedCompositePKs,
15912
+ prevFull
15913
+ );
15909
15914
  alteredCompositePKs = prepareAlterCompositePrimaryKeyMySql(
15910
15915
  it.name,
15911
15916
  it.alteredCompositePKs,
@@ -16112,10 +16117,16 @@ var applySnapshotsDiff = async (json1, json2, dialect3, schemasResolver, tablesR
16112
16117
  jsonStatements.push(...jsonRenameTables);
16113
16118
  jsonStatements.push(...jsonRenameColumnsStatements);
16114
16119
  jsonStatements.push(...jsonDeletedCompositePKs);
16115
- jsonStatements.push(...jsonDeletedUniqueConstraints);
16120
+ if (dialect3 !== "mysql") {
16121
+ jsonStatements.push(...jsonDeletedUniqueConstraints);
16122
+ }
16116
16123
  jsonStatements.push(...jsonDroppedReferencesForAlteredTables);
16117
16124
  jsonStatements.push(...jsonDropIndexesForAllAlteredTables);
16118
16125
  jsonStatements.push(...jsonTableAlternations.alterColumns);
16126
+ if (dialect3 === "mysql") {
16127
+ jsonStatements.push(...jsonAddedUniqueConstraints);
16128
+ jsonStatements.push(...jsonDeletedUniqueConstraints);
16129
+ }
16119
16130
  jsonStatements.push(...jsonTableAlternations.createColumns);
16120
16131
  jsonStatements.push(...jsonCreateIndexesForCreatedTables);
16121
16132
  jsonStatements.push(...jsonCreateIndexesForAllAlteredTables);
@@ -16125,7 +16136,9 @@ var applySnapshotsDiff = async (json1, json2, dialect3, schemasResolver, tablesR
16125
16136
  jsonStatements.push(...jsonCreateReferences);
16126
16137
  jsonStatements.push(...jsonAddedCompositePKs);
16127
16138
  jsonStatements.push(...jsonAlteredCompositePKs);
16128
- jsonStatements.push(...jsonAddedUniqueConstraints);
16139
+ if (dialect3 !== "mysql") {
16140
+ jsonStatements.push(...jsonAddedUniqueConstraints);
16141
+ }
16129
16142
  jsonStatements.push(...jsonAlteredUniqueConstraints);
16130
16143
  jsonStatements.push(...jsonSetTableSchemas);
16131
16144
  jsonStatements.push(...filteredJsonSetNewTableSchemas);