drizzle-kit 0.17.0-c6501de → 0.17.0-edc772a

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 (4) hide show
  1. package/index.js +1584 -430
  2. package/package.json +4 -2
  3. package/readme.md +2 -2
  4. package/utils.js +152 -78
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "drizzle-kit",
3
- "version": "0.17.0-c6501de",
3
+ "version": "0.17.0-edc772a",
4
4
  "repository": "https://github.com/drizzle-team/drizzle-kit-mirror",
5
5
  "author": "Drizzle Team",
6
6
  "license": "MIT",
@@ -13,7 +13,7 @@
13
13
  "migrate:old:mysql": "drizzle-kit generate:mysql --out ./dev/migrations-mysql --schema ./dev/migrations-mysql/schema.ts",
14
14
  "start:pg": "node -r esbuild-register ./src/cli/index.ts generate:pg --out ./dev/migrations-pg --schema ./dev/migrations-pg/schema.ts",
15
15
  "start:sqlite": "node -r esbuild-register ./src/cli/index.ts generate:sqlite --out ./dev/migrations-sqlite --schema ./dev/migrations-sqlite/schema.ts",
16
- "start:mysql": "node -r esbuild-register ./src/cli/index.ts generate:mysql --out ./dev/migrations-mysql --schema ./dev/migrations-mysql/schema.ts",
16
+ "start:mysql": "node -r esbuild-register ./src/cli/index.ts generate:mysql --out ./dev/introspect-mysql --schema ./dev/introspect-mysql/schema.ts",
17
17
  "check:pg": "node -r esbuild-register ./src/cli/index.ts check --out ./dev/migrations --dialect pg",
18
18
  "introspect:mysql": "node -r esbuild-register ./src/cli/index.ts introspect:mysql",
19
19
  "introspect:pg": "node -r esbuild-register ./src/cli/index.ts introspect:pg --out ./dev/introspect-pg --connectionString=postgresql://postgres@localhost:5432/introspect",
@@ -56,11 +56,13 @@
56
56
  "glob": "^8.1.0",
57
57
  "hanji": "^0.0.5",
58
58
  "json-diff": "0.9.0",
59
+ "minimatch": "^7.4.3",
59
60
  "zod": "^3.20.2"
60
61
  },
61
62
  "devDependencies": {
62
63
  "@types/dockerode": "^3.3.14",
63
64
  "@types/glob": "^8.1.0",
65
+ "@types/minimatch": "^5.1.2",
64
66
  "@types/node": "^18.11.15",
65
67
  "@types/pg": "^8.6.5",
66
68
  "@typescript-eslint/eslint-plugin": "^5.46.1",
package/readme.md CHANGED
@@ -13,7 +13,7 @@ For schema file:
13
13
  ```typescript
14
14
  // ./src/db/schema.ts
15
15
 
16
- import { integer, pgTable, serial, text, varchar } from "drizzle-orm-pg";
16
+ import { integer, pgTable, serial, text, varchar } from "drizzle-orm/pg-core";
17
17
 
18
18
  const users = pgTable("users", {
19
19
  id: serial("id").primaryKey(),
@@ -62,7 +62,7 @@ npm install -D drizzle-kit
62
62
  Running with CLI options
63
63
 
64
64
  ```shell
65
- npm exec drizzle-kit generate --out migrations-folder --dialect pg --schema src/db/schema.ts
65
+ npx drizzle-kit generate:pg --out migrations-folder --schema src/db/schema.ts
66
66
  ```
67
67
 
68
68
  Or put your file to `drizzle.config.json` configuration file:
package/utils.js CHANGED
@@ -11095,6 +11095,19 @@ var alternationsInColumn = (column4) => {
11095
11095
  return { ...others, notNull: { type: "deleted", value: it.notNull__deleted } };
11096
11096
  }
11097
11097
  return it;
11098
+ }).map((it) => {
11099
+ if ("primaryKey" in it) {
11100
+ return { ...it, primaryKey: { type: "changed", old: it.primaryKey.__old, new: it.primaryKey.__new } };
11101
+ }
11102
+ if ("primaryKey__added" in it) {
11103
+ const { notNull__added, ...others } = it;
11104
+ return { ...others, primaryKey: { type: "added", value: it.primaryKey__added } };
11105
+ }
11106
+ if ("primaryKey__deleted" in it) {
11107
+ const { notNull__deleted, ...others } = it;
11108
+ return { ...others, primaryKey: { type: "deleted", value: it.primaryKey__deleted } };
11109
+ }
11110
+ return it;
11098
11111
  }).map((it) => {
11099
11112
  if ("onUpdate" in it) {
11100
11113
  return { ...it, onUpdate: { type: "changed", old: it.onUpdate.__old, new: it.onUpdate.__new } };
@@ -11218,25 +11231,24 @@ var MySqlCreateTableConvertor = class extends Convertor {
11218
11231
  `;
11219
11232
  for (let i = 0; i < columns.length; i++) {
11220
11233
  const column4 = columns[i];
11221
- const primaryKeyStatement = column4.primaryKey ? "PRIMARY KEY" : "";
11222
- const notNullStatement = column4.notNull ? "NOT NULL" : "";
11223
- const defaultStatement = column4.default !== void 0 ? `DEFAULT ${column4.default}` : "";
11224
- const onUpdateStatement = column4.onUpdate ? `ON UPDATE CURRENT_TIMESTAMP` : "";
11225
- const autoincrementStatement = column4.autoincrement ? "AUTO_INCREMENT" : "";
11226
- statement += " " + `\`${column4.name}\` ${column4.type} ${autoincrementStatement} ${primaryKeyStatement} ${notNullStatement} ${defaultStatement} ${onUpdateStatement}`.replace(/ +/g, " ").trim();
11227
- statement += (i === columns.length - 1 ? "" : ",") + "\n";
11234
+ const primaryKeyStatement = column4.primaryKey ? " PRIMARY KEY" : "";
11235
+ const notNullStatement = column4.notNull ? " NOT NULL" : "";
11236
+ const defaultStatement = column4.default !== void 0 ? ` DEFAULT ${column4.default}` : "";
11237
+ const onUpdateStatement = column4.onUpdate ? ` ON UPDATE CURRENT_TIMESTAMP` : "";
11238
+ const autoincrementStatement = column4.autoincrement ? " AUTO_INCREMENT" : "";
11239
+ statement += " " + `\`${column4.name}\` ${column4.type}${autoincrementStatement}${primaryKeyStatement}${notNullStatement}${defaultStatement}${onUpdateStatement}`.trim();
11240
+ statement += i === columns.length - 1 ? "" : ",\n";
11228
11241
  }
11229
- statement += `);`;
11230
- statement += `
11231
- `;
11232
11242
  if (typeof compositePKs !== "undefined" && compositePKs.length > 0) {
11243
+ statement += ",\n";
11233
11244
  const compositePK4 = MySqlSquasher.unsquashPK(compositePKs[0]);
11234
- statement += `ALTER TABLE ${tName} ADD PRIMARY KEY(\`${compositePK4.columns.join(
11235
- "`,`"
11236
- )}\`);`;
11245
+ statement += ` PRIMARY KEY(\`${compositePK4.columns.join("`,`")}\`)`;
11237
11246
  statement += `
11238
11247
  `;
11239
11248
  }
11249
+ statement += `);`;
11250
+ statement += `
11251
+ `;
11240
11252
  return statement;
11241
11253
  }
11242
11254
  };
@@ -11435,12 +11447,13 @@ var MySqlAlterTableAddColumnConvertor = class extends Convertor {
11435
11447
  }
11436
11448
  convert(statement) {
11437
11449
  const { tableName, column: column4 } = statement;
11438
- const { name, type, notNull, primaryKey, autoincrement } = column4;
11439
- const defaultStatement = `${column4.default !== void 0 ? `DEFAULT ${column4.default}` : ""}`;
11440
- const notNullStatement = `${notNull ? "NOT NULL" : ""}`;
11441
- const primaryKeyStatement = `${primaryKey ? "PRIMARY KEY" : ""}`;
11442
- const autoincrementStatement = `${autoincrement ? "AUTO_INCREMENT" : ""}`;
11443
- return `ALTER TABLE ${tableName} ADD \`${name}\` ${type} ${primaryKeyStatement} ${autoincrementStatement} ${defaultStatement} ${notNullStatement}`.replace(/ +/g, " ").trim() + ";";
11450
+ const { name, type, notNull, primaryKey, autoincrement, onUpdate } = column4;
11451
+ const defaultStatement = `${column4.default !== void 0 ? ` DEFAULT ${column4.default}` : ""}`;
11452
+ const notNullStatement = `${notNull ? " NOT NULL" : ""}`;
11453
+ const primaryKeyStatement = `${primaryKey ? " PRIMARY KEY" : ""}`;
11454
+ const autoincrementStatement = `${autoincrement ? " AUTO_INCREMENT" : ""}`;
11455
+ const onUpdateStatement = `${onUpdate ? " ON UPDATE CURRENT_TIMESTAMP" : ""}`;
11456
+ return `ALTER TABLE ${tableName} ADD \`${name}\` ${type}${primaryKeyStatement}${autoincrementStatement}${defaultStatement}${notNullStatement}${onUpdateStatement};`;
11444
11457
  }
11445
11458
  };
11446
11459
  var SQLiteAlterTableAddColumnConvertor = class extends Convertor {
@@ -11515,6 +11528,22 @@ var PgAlterTableAlterColumnDropDefaultConvertor = class extends Convertor {
11515
11528
  return `ALTER TABLE ${tableName} ALTER COLUMN "${columnName}" DROP DEFAULT;`;
11516
11529
  }
11517
11530
  };
11531
+ var MySqlAlterTableAddPk = class extends Convertor {
11532
+ can(statement, dialect3) {
11533
+ return statement.type === "alter_table_alter_column_set_pk" && dialect3 === "mysql";
11534
+ }
11535
+ convert(statement) {
11536
+ return `ALTER TABLE \`${statement.tableName}\` ADD PRIMARY KEY (\`${statement.columnName}\`);`;
11537
+ }
11538
+ };
11539
+ var MySqlAlterTableDropPk = class extends Convertor {
11540
+ can(statement, dialect3) {
11541
+ return statement.type === "alter_table_alter_column_drop_pk" && dialect3 === "mysql";
11542
+ }
11543
+ convert(statement) {
11544
+ return `ALTER TABLE \`${statement.tableName}\` DROP PRIMARY KEY`;
11545
+ }
11546
+ };
11518
11547
  var MySqlModifyColumn = class extends Convertor {
11519
11548
  can(statement, dialect3) {
11520
11549
  return (statement.type === "alter_table_alter_column_set_type" || statement.type === "alter_table_alter_column_set_notnull" || statement.type === "alter_table_alter_column_drop_notnull" || statement.type === "alter_table_alter_column_drop_on_update" || statement.type === "alter_table_alter_column_set_on_update" || statement.type === "alter_table_alter_column_set_autoincrement" || statement.type === "alter_table_alter_column_drop_autoincrement" || statement.type === "alter_table_alter_column_set_default" || statement.type === "alter_table_alter_column_drop_default") && dialect3 === "mysql";
@@ -11526,6 +11555,7 @@ var MySqlModifyColumn = class extends Convertor {
11526
11555
  let columnNotNull = "";
11527
11556
  let columnOnUpdate = "";
11528
11557
  let columnAutoincrement = "";
11558
+ let primaryKey = statement.columnPk ? " PRIMARY KEY" : "";
11529
11559
  if (statement.type === "alter_table_alter_column_drop_notnull") {
11530
11560
  columnType = ` ${statement.newDataType}`;
11531
11561
  columnDefault = statement.columnDefault ? ` DEFAULT ${statement.columnDefault}` : "";
@@ -11555,7 +11585,7 @@ var MySqlModifyColumn = class extends Convertor {
11555
11585
  columnOnUpdate = columnOnUpdate = statement.columnOnUpdate ? ` ON UPDATE CURRENT_TIMESTAMP` : "";
11556
11586
  columnType = ` ${statement.newDataType}`;
11557
11587
  columnDefault = statement.columnDefault ? ` DEFAULT ${statement.columnDefault}` : "";
11558
- columnAutoincrement = "AUTO_INCREMENT";
11588
+ columnAutoincrement = " AUTO_INCREMENT";
11559
11589
  } else if (statement.type === "alter_table_alter_column_drop_autoincrement") {
11560
11590
  columnNotNull = statement.columnNotNull ? ` NOT NULL` : "";
11561
11591
  columnOnUpdate = columnOnUpdate = statement.columnOnUpdate ? ` ON UPDATE CURRENT_TIMESTAMP` : "";
@@ -11579,7 +11609,7 @@ var MySqlModifyColumn = class extends Convertor {
11579
11609
  columnNotNull = statement.columnNotNull ? ` NOT NULL` : "";
11580
11610
  columnOnUpdate = columnOnUpdate = statement.columnOnUpdate ? ` ON UPDATE CURRENT_TIMESTAMP` : "";
11581
11611
  columnDefault = statement.columnDefault ? ` DEFAULT ${statement.columnDefault}` : "";
11582
- columnAutoincrement = statement.columnAutoIncrement ? "AUTO_INCREMENT" : "";
11612
+ columnAutoincrement = statement.columnAutoIncrement ? " AUTO_INCREMENT" : "";
11583
11613
  }
11584
11614
  columnDefault = columnDefault instanceof Date ? columnDefault.toISOString() : columnDefault;
11585
11615
  return `ALTER TABLE ${tableName} MODIFY COLUMN \`${columnName}\`${columnType}${columnAutoincrement}${columnNotNull}${columnDefault}${columnOnUpdate};`;
@@ -12168,8 +12198,10 @@ convertors.push(new SqliteAlterTableAlterCompositePrimaryKeyConvertor());
12168
12198
  convertors.push(new PgAlterTableCreateCompositePrimaryKeyConvertor());
12169
12199
  convertors.push(new PgAlterTableDeleteCompositePrimaryKeyConvertor());
12170
12200
  convertors.push(new PgAlterTableAlterCompositePrimaryKeyConvertor());
12171
- convertors.push(new MySqlAlterTableCreateCompositePrimaryKeyConvertor());
12172
12201
  convertors.push(new MySqlAlterTableDeleteCompositePrimaryKeyConvertor());
12202
+ convertors.push(new MySqlAlterTableDropPk());
12203
+ convertors.push(new MySqlAlterTableCreateCompositePrimaryKeyConvertor());
12204
+ convertors.push(new MySqlAlterTableAddPk());
12173
12205
  convertors.push(new MySqlAlterTableAlterCompositePrimaryKeyConvertor());
12174
12206
  var fromJson = (statements, dialect3) => {
12175
12207
  const result = statements.map((statement) => {
@@ -12179,10 +12211,10 @@ var fromJson = (statements, dialect3) => {
12179
12211
  const convertor = filtered.length === 1 ? filtered[0] : void 0;
12180
12212
  if (!convertor) {
12181
12213
  console.log("no convertor:", statement.type, dialect3);
12182
- return "dry run";
12214
+ return "";
12183
12215
  }
12184
12216
  return convertor.convert(statement);
12185
- });
12217
+ }).filter((it) => it !== "");
12186
12218
  return result;
12187
12219
  };
12188
12220
  https:
@@ -12373,7 +12405,7 @@ var _prepareSQLiteAddColumns = (tableName, columns, referenceData) => {
12373
12405
  });
12374
12406
  };
12375
12407
  var _prepareAlterColumns = (tableName, schema3, columns, json2) => {
12376
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
12408
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p;
12377
12409
  let statements = [];
12378
12410
  for (const column4 of columns) {
12379
12411
  const columnName = typeof column4.name !== "string" ? column4.name.new : column4.name;
@@ -12382,110 +12414,134 @@ var _prepareAlterColumns = (tableName, schema3, columns, json2) => {
12382
12414
  const columnOnUpdate = json2.tables[tableName].columns[columnName].onUpdate;
12383
12415
  const columnNotNull = json2.tables[tableName].columns[columnName].notNull;
12384
12416
  const columnAutoIncrement = json2.tables[tableName].columns[columnName].autoincrement;
12385
- if (typeof column4.name !== "string") {
12417
+ const columnPk = json2.tables[tableName].columns[columnName].primaryKey;
12418
+ if (((_a = column4.autoincrement) == null ? void 0 : _a.type) === "added") {
12386
12419
  statements.push({
12387
- type: "alter_table_rename_column",
12388
- tableName,
12389
- oldColumnName: column4.name.old,
12390
- newColumnName: column4.name.new,
12391
- schema: schema3
12392
- });
12393
- }
12394
- if (((_a = column4.type) == null ? void 0 : _a.type) === "changed") {
12395
- statements.push({
12396
- type: "alter_table_alter_column_set_type",
12420
+ type: "alter_table_alter_column_set_autoincrement",
12397
12421
  tableName,
12398
12422
  columnName,
12399
- newDataType: column4.type.new,
12400
12423
  schema: schema3,
12424
+ newDataType: columnType,
12401
12425
  columnDefault,
12402
12426
  columnOnUpdate,
12403
12427
  columnNotNull,
12404
- columnAutoIncrement
12428
+ columnAutoIncrement,
12429
+ columnPk
12405
12430
  });
12406
12431
  }
12407
- if (((_b = column4.default) == null ? void 0 : _b.type) === "added") {
12432
+ if (((_b = column4.autoincrement) == null ? void 0 : _b.type) === "changed") {
12433
+ const type = column4.autoincrement.new ? "alter_table_alter_column_set_autoincrement" : "alter_table_alter_column_drop_autoincrement";
12408
12434
  statements.push({
12409
- type: "alter_table_alter_column_set_default",
12435
+ type,
12410
12436
  tableName,
12411
12437
  columnName,
12412
- newDefaultValue: column4.default.value,
12413
12438
  schema: schema3,
12439
+ newDataType: columnType,
12440
+ columnDefault,
12414
12441
  columnOnUpdate,
12415
12442
  columnNotNull,
12416
12443
  columnAutoIncrement,
12417
- newDataType: columnType
12444
+ columnPk
12418
12445
  });
12419
12446
  }
12420
- if (((_c = column4.default) == null ? void 0 : _c.type) === "changed") {
12447
+ if (((_c = column4.autoincrement) == null ? void 0 : _c.type) === "deleted") {
12421
12448
  statements.push({
12422
- type: "alter_table_alter_column_set_default",
12449
+ type: "alter_table_alter_column_drop_autoincrement",
12423
12450
  tableName,
12424
12451
  columnName,
12425
- newDefaultValue: column4.default.new,
12426
12452
  schema: schema3,
12453
+ newDataType: columnType,
12454
+ columnDefault,
12427
12455
  columnOnUpdate,
12428
12456
  columnNotNull,
12429
12457
  columnAutoIncrement,
12430
- newDataType: columnType
12458
+ columnPk
12459
+ });
12460
+ }
12461
+ }
12462
+ for (const column4 of columns) {
12463
+ const columnName = typeof column4.name !== "string" ? column4.name.new : column4.name;
12464
+ const columnType = json2.tables[tableName].columns[columnName].type;
12465
+ const columnDefault = json2.tables[tableName].columns[columnName].default;
12466
+ const columnOnUpdate = json2.tables[tableName].columns[columnName].onUpdate;
12467
+ const columnNotNull = json2.tables[tableName].columns[columnName].notNull;
12468
+ const columnAutoIncrement = json2.tables[tableName].columns[columnName].autoincrement;
12469
+ const columnPk = json2.tables[tableName].columns[columnName].primaryKey;
12470
+ if (typeof column4.name !== "string") {
12471
+ statements.push({
12472
+ type: "alter_table_rename_column",
12473
+ tableName,
12474
+ oldColumnName: column4.name.old,
12475
+ newColumnName: column4.name.new,
12476
+ schema: schema3
12431
12477
  });
12432
12478
  }
12433
- if (((_d = column4.default) == null ? void 0 : _d.type) === "deleted") {
12479
+ if (((_d = column4.type) == null ? void 0 : _d.type) === "changed") {
12434
12480
  statements.push({
12435
- type: "alter_table_alter_column_drop_default",
12481
+ type: "alter_table_alter_column_set_type",
12436
12482
  tableName,
12437
12483
  columnName,
12484
+ newDataType: column4.type.new,
12438
12485
  schema: schema3,
12439
12486
  columnDefault,
12440
12487
  columnOnUpdate,
12441
12488
  columnNotNull,
12442
12489
  columnAutoIncrement,
12443
- newDataType: columnType
12490
+ columnPk
12444
12491
  });
12445
12492
  }
12446
- if (((_e = column4.notNull) == null ? void 0 : _e.type) === "added") {
12493
+ if (((_e = column4.primaryKey) == null ? void 0 : _e.type) === "deleted" || ((_f = column4.primaryKey) == null ? void 0 : _f.type) === "changed" && !column4.primaryKey.new) {
12447
12494
  statements.push({
12448
- type: "alter_table_alter_column_set_notnull",
12495
+ type: "alter_table_alter_column_drop_pk",
12496
+ tableName,
12497
+ columnName
12498
+ });
12499
+ }
12500
+ if (((_g = column4.default) == null ? void 0 : _g.type) === "added") {
12501
+ statements.push({
12502
+ type: "alter_table_alter_column_set_default",
12449
12503
  tableName,
12450
12504
  columnName,
12505
+ newDefaultValue: column4.default.value,
12451
12506
  schema: schema3,
12452
- newDataType: columnType,
12453
- columnDefault,
12454
12507
  columnOnUpdate,
12455
12508
  columnNotNull,
12456
- columnAutoIncrement
12509
+ columnAutoIncrement,
12510
+ newDataType: columnType,
12511
+ columnPk
12457
12512
  });
12458
12513
  }
12459
- if (((_f = column4.notNull) == null ? void 0 : _f.type) === "changed") {
12460
- const type = column4.notNull.new ? "alter_table_alter_column_set_notnull" : "alter_table_alter_column_drop_notnull";
12514
+ if (((_h = column4.default) == null ? void 0 : _h.type) === "changed") {
12461
12515
  statements.push({
12462
- type,
12516
+ type: "alter_table_alter_column_set_default",
12463
12517
  tableName,
12464
12518
  columnName,
12519
+ newDefaultValue: column4.default.new,
12465
12520
  schema: schema3,
12466
- newDataType: columnType,
12467
- columnDefault,
12468
12521
  columnOnUpdate,
12469
12522
  columnNotNull,
12470
- columnAutoIncrement
12523
+ columnAutoIncrement,
12524
+ newDataType: columnType,
12525
+ columnPk
12471
12526
  });
12472
12527
  }
12473
- if (((_g = column4.notNull) == null ? void 0 : _g.type) === "deleted") {
12528
+ if (((_i = column4.default) == null ? void 0 : _i.type) === "deleted") {
12474
12529
  statements.push({
12475
- type: "alter_table_alter_column_drop_notnull",
12530
+ type: "alter_table_alter_column_drop_default",
12476
12531
  tableName,
12477
12532
  columnName,
12478
12533
  schema: schema3,
12479
- newDataType: columnType,
12480
12534
  columnDefault,
12481
12535
  columnOnUpdate,
12482
12536
  columnNotNull,
12483
- columnAutoIncrement
12537
+ columnAutoIncrement,
12538
+ newDataType: columnType,
12539
+ columnPk
12484
12540
  });
12485
12541
  }
12486
- if (((_h = column4.autoincrement) == null ? void 0 : _h.type) === "added") {
12542
+ if (((_j = column4.notNull) == null ? void 0 : _j.type) === "added") {
12487
12543
  statements.push({
12488
- type: "alter_table_alter_column_set_autoincrement",
12544
+ type: "alter_table_alter_column_set_notnull",
12489
12545
  tableName,
12490
12546
  columnName,
12491
12547
  schema: schema3,
@@ -12493,11 +12549,12 @@ var _prepareAlterColumns = (tableName, schema3, columns, json2) => {
12493
12549
  columnDefault,
12494
12550
  columnOnUpdate,
12495
12551
  columnNotNull,
12496
- columnAutoIncrement
12552
+ columnAutoIncrement,
12553
+ columnPk
12497
12554
  });
12498
12555
  }
12499
- if (((_i = column4.autoincrement) == null ? void 0 : _i.type) === "changed") {
12500
- const type = column4.autoincrement.new ? "alter_table_alter_column_set_notnull" : "alter_table_alter_column_drop_notnull";
12556
+ if (((_k = column4.notNull) == null ? void 0 : _k.type) === "changed") {
12557
+ const type = column4.notNull.new ? "alter_table_alter_column_set_notnull" : "alter_table_alter_column_drop_notnull";
12501
12558
  statements.push({
12502
12559
  type,
12503
12560
  tableName,
@@ -12507,12 +12564,13 @@ var _prepareAlterColumns = (tableName, schema3, columns, json2) => {
12507
12564
  columnDefault,
12508
12565
  columnOnUpdate,
12509
12566
  columnNotNull,
12510
- columnAutoIncrement
12567
+ columnAutoIncrement,
12568
+ columnPk
12511
12569
  });
12512
12570
  }
12513
- if (((_j = column4.autoincrement) == null ? void 0 : _j.type) === "deleted") {
12571
+ if (((_l = column4.notNull) == null ? void 0 : _l.type) === "deleted") {
12514
12572
  statements.push({
12515
- type: "alter_table_alter_column_drop_autoincrement",
12573
+ type: "alter_table_alter_column_drop_notnull",
12516
12574
  tableName,
12517
12575
  columnName,
12518
12576
  schema: schema3,
@@ -12520,10 +12578,23 @@ var _prepareAlterColumns = (tableName, schema3, columns, json2) => {
12520
12578
  columnDefault,
12521
12579
  columnOnUpdate,
12522
12580
  columnNotNull,
12523
- columnAutoIncrement
12581
+ columnAutoIncrement,
12582
+ columnPk
12524
12583
  });
12525
12584
  }
12526
- if (((_k = column4.onUpdate) == null ? void 0 : _k.type) === "added") {
12585
+ if (((_m = column4.primaryKey) == null ? void 0 : _m.type) === "added" || ((_n = column4.primaryKey) == null ? void 0 : _n.type) === "changed" && column4.primaryKey.new) {
12586
+ const wasAutoincrement = statements.filter(
12587
+ (it) => it.type === "alter_table_alter_column_set_autoincrement"
12588
+ );
12589
+ if (wasAutoincrement.length === 0) {
12590
+ statements.push({
12591
+ type: "alter_table_alter_column_set_pk",
12592
+ tableName,
12593
+ columnName
12594
+ });
12595
+ }
12596
+ }
12597
+ if (((_o = column4.onUpdate) == null ? void 0 : _o.type) === "added") {
12527
12598
  statements.push({
12528
12599
  type: "alter_table_alter_column_set_on_update",
12529
12600
  tableName,
@@ -12533,10 +12604,11 @@ var _prepareAlterColumns = (tableName, schema3, columns, json2) => {
12533
12604
  columnDefault,
12534
12605
  columnOnUpdate,
12535
12606
  columnNotNull,
12536
- columnAutoIncrement
12607
+ columnAutoIncrement,
12608
+ columnPk
12537
12609
  });
12538
12610
  }
12539
- if (((_l = column4.onUpdate) == null ? void 0 : _l.type) === "deleted") {
12611
+ if (((_p = column4.onUpdate) == null ? void 0 : _p.type) === "deleted") {
12540
12612
  statements.push({
12541
12613
  type: "alter_table_alter_column_drop_on_update",
12542
12614
  tableName,
@@ -12546,7 +12618,8 @@ var _prepareAlterColumns = (tableName, schema3, columns, json2) => {
12546
12618
  columnDefault,
12547
12619
  columnOnUpdate,
12548
12620
  columnNotNull,
12549
- columnAutoIncrement
12621
+ columnAutoIncrement,
12622
+ columnPk
12550
12623
  });
12551
12624
  }
12552
12625
  }
@@ -12778,6 +12851,7 @@ var alteredColumnSchema = objectType({
12778
12851
  name: makeSelfOrChanged(stringType()),
12779
12852
  type: makeChanged(stringType()).optional(),
12780
12853
  default: makePatched(anyType()).optional(),
12854
+ primaryKey: makePatched(booleanType()).optional(),
12781
12855
  notNull: makePatched(booleanType()).optional(),
12782
12856
  onUpdate: makePatched(booleanType()).optional(),
12783
12857
  autoincrement: makePatched(booleanType()).optional()
@@ -13110,6 +13184,7 @@ var applySnapshotsDiff = async (json1, json2, dialect3, schemasResolver, tablesR
13110
13184
  jsonStatements.push(...jsonDropTables);
13111
13185
  jsonStatements.push(...jsonRenameTables);
13112
13186
  jsonStatements.push(...jsonRenameColumnsStatements);
13187
+ jsonStatements.push(...jsonDeletedCompositePKs);
13113
13188
  jsonStatements.push(...jsonTableAlternations.alterColumns);
13114
13189
  jsonStatements.push(...jsonTableAlternations.createColumns);
13115
13190
  jsonStatements.push(...jsonAlterReferencesForAlteredTables);
@@ -13119,7 +13194,6 @@ var applySnapshotsDiff = async (json1, json2, dialect3, schemasResolver, tablesR
13119
13194
  jsonStatements.push(...jsonDropIndexesForAllAlteredTables);
13120
13195
  jsonStatements.push(...jsonCreateIndexesForCreatedTables);
13121
13196
  jsonStatements.push(...jsonCreateIndexesForAllAlteredTables);
13122
- jsonStatements.push(...jsonDeletedCompositePKs);
13123
13197
  jsonStatements.push(...jsonAddedCompositePKs);
13124
13198
  jsonStatements.push(...jsonAlteredCompositePKs);
13125
13199
  jsonStatements.push(...jsonSetTableSchemas);