drizzle-kit 0.17.0-16763e2 → 0.17.0-5e8cf70

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 +1589 -431
  2. package/package.json +4 -2
  3. package/readme.md +2 -2
  4. package/utils.js +152 -79
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "drizzle-kit",
3
- "version": "0.17.0-16763e2",
3
+ "version": "0.17.0-5e8cf70",
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:pg --out migrations-folder --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};`;
@@ -11870,7 +11900,6 @@ var PgAlterForeignKeyConvertor = class extends Convertor {
11870
11900
  sql += " WHEN duplicate_object THEN null;\n";
11871
11901
  sql += "END $$;\n";
11872
11902
  return sql;
11873
- throw new Error("TODO");
11874
11903
  }
11875
11904
  };
11876
11905
  var SqliteAlterForeignKeyConvertor = class extends Convertor {
@@ -12168,8 +12197,10 @@ convertors.push(new SqliteAlterTableAlterCompositePrimaryKeyConvertor());
12168
12197
  convertors.push(new PgAlterTableCreateCompositePrimaryKeyConvertor());
12169
12198
  convertors.push(new PgAlterTableDeleteCompositePrimaryKeyConvertor());
12170
12199
  convertors.push(new PgAlterTableAlterCompositePrimaryKeyConvertor());
12171
- convertors.push(new MySqlAlterTableCreateCompositePrimaryKeyConvertor());
12172
12200
  convertors.push(new MySqlAlterTableDeleteCompositePrimaryKeyConvertor());
12201
+ convertors.push(new MySqlAlterTableDropPk());
12202
+ convertors.push(new MySqlAlterTableCreateCompositePrimaryKeyConvertor());
12203
+ convertors.push(new MySqlAlterTableAddPk());
12173
12204
  convertors.push(new MySqlAlterTableAlterCompositePrimaryKeyConvertor());
12174
12205
  var fromJson = (statements, dialect3) => {
12175
12206
  const result = statements.map((statement) => {
@@ -12179,10 +12210,10 @@ var fromJson = (statements, dialect3) => {
12179
12210
  const convertor = filtered.length === 1 ? filtered[0] : void 0;
12180
12211
  if (!convertor) {
12181
12212
  console.log("no convertor:", statement.type, dialect3);
12182
- return "dry run";
12213
+ return "";
12183
12214
  }
12184
12215
  return convertor.convert(statement);
12185
- });
12216
+ }).filter((it) => it !== "");
12186
12217
  return result;
12187
12218
  };
12188
12219
  https:
@@ -12373,7 +12404,7 @@ var _prepareSQLiteAddColumns = (tableName, columns, referenceData) => {
12373
12404
  });
12374
12405
  };
12375
12406
  var _prepareAlterColumns = (tableName, schema3, columns, json2) => {
12376
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
12407
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p;
12377
12408
  let statements = [];
12378
12409
  for (const column4 of columns) {
12379
12410
  const columnName = typeof column4.name !== "string" ? column4.name.new : column4.name;
@@ -12382,110 +12413,134 @@ var _prepareAlterColumns = (tableName, schema3, columns, json2) => {
12382
12413
  const columnOnUpdate = json2.tables[tableName].columns[columnName].onUpdate;
12383
12414
  const columnNotNull = json2.tables[tableName].columns[columnName].notNull;
12384
12415
  const columnAutoIncrement = json2.tables[tableName].columns[columnName].autoincrement;
12385
- if (typeof column4.name !== "string") {
12416
+ const columnPk = json2.tables[tableName].columns[columnName].primaryKey;
12417
+ if (((_a = column4.autoincrement) == null ? void 0 : _a.type) === "added") {
12386
12418
  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",
12419
+ type: "alter_table_alter_column_set_autoincrement",
12397
12420
  tableName,
12398
12421
  columnName,
12399
- newDataType: column4.type.new,
12400
12422
  schema: schema3,
12423
+ newDataType: columnType,
12401
12424
  columnDefault,
12402
12425
  columnOnUpdate,
12403
12426
  columnNotNull,
12404
- columnAutoIncrement
12427
+ columnAutoIncrement,
12428
+ columnPk
12405
12429
  });
12406
12430
  }
12407
- if (((_b = column4.default) == null ? void 0 : _b.type) === "added") {
12431
+ if (((_b = column4.autoincrement) == null ? void 0 : _b.type) === "changed") {
12432
+ const type = column4.autoincrement.new ? "alter_table_alter_column_set_autoincrement" : "alter_table_alter_column_drop_autoincrement";
12408
12433
  statements.push({
12409
- type: "alter_table_alter_column_set_default",
12434
+ type,
12410
12435
  tableName,
12411
12436
  columnName,
12412
- newDefaultValue: column4.default.value,
12413
12437
  schema: schema3,
12438
+ newDataType: columnType,
12439
+ columnDefault,
12414
12440
  columnOnUpdate,
12415
12441
  columnNotNull,
12416
12442
  columnAutoIncrement,
12417
- newDataType: columnType
12443
+ columnPk
12418
12444
  });
12419
12445
  }
12420
- if (((_c = column4.default) == null ? void 0 : _c.type) === "changed") {
12446
+ if (((_c = column4.autoincrement) == null ? void 0 : _c.type) === "deleted") {
12421
12447
  statements.push({
12422
- type: "alter_table_alter_column_set_default",
12448
+ type: "alter_table_alter_column_drop_autoincrement",
12423
12449
  tableName,
12424
12450
  columnName,
12425
- newDefaultValue: column4.default.new,
12426
12451
  schema: schema3,
12452
+ newDataType: columnType,
12453
+ columnDefault,
12427
12454
  columnOnUpdate,
12428
12455
  columnNotNull,
12429
12456
  columnAutoIncrement,
12430
- newDataType: columnType
12457
+ columnPk
12458
+ });
12459
+ }
12460
+ }
12461
+ for (const column4 of columns) {
12462
+ const columnName = typeof column4.name !== "string" ? column4.name.new : column4.name;
12463
+ const columnType = json2.tables[tableName].columns[columnName].type;
12464
+ const columnDefault = json2.tables[tableName].columns[columnName].default;
12465
+ const columnOnUpdate = json2.tables[tableName].columns[columnName].onUpdate;
12466
+ const columnNotNull = json2.tables[tableName].columns[columnName].notNull;
12467
+ const columnAutoIncrement = json2.tables[tableName].columns[columnName].autoincrement;
12468
+ const columnPk = json2.tables[tableName].columns[columnName].primaryKey;
12469
+ if (typeof column4.name !== "string") {
12470
+ statements.push({
12471
+ type: "alter_table_rename_column",
12472
+ tableName,
12473
+ oldColumnName: column4.name.old,
12474
+ newColumnName: column4.name.new,
12475
+ schema: schema3
12431
12476
  });
12432
12477
  }
12433
- if (((_d = column4.default) == null ? void 0 : _d.type) === "deleted") {
12478
+ if (((_d = column4.type) == null ? void 0 : _d.type) === "changed") {
12434
12479
  statements.push({
12435
- type: "alter_table_alter_column_drop_default",
12480
+ type: "alter_table_alter_column_set_type",
12436
12481
  tableName,
12437
12482
  columnName,
12483
+ newDataType: column4.type.new,
12438
12484
  schema: schema3,
12439
12485
  columnDefault,
12440
12486
  columnOnUpdate,
12441
12487
  columnNotNull,
12442
12488
  columnAutoIncrement,
12443
- newDataType: columnType
12489
+ columnPk
12444
12490
  });
12445
12491
  }
12446
- if (((_e = column4.notNull) == null ? void 0 : _e.type) === "added") {
12492
+ if (((_e = column4.primaryKey) == null ? void 0 : _e.type) === "deleted" || ((_f = column4.primaryKey) == null ? void 0 : _f.type) === "changed" && !column4.primaryKey.new) {
12447
12493
  statements.push({
12448
- type: "alter_table_alter_column_set_notnull",
12494
+ type: "alter_table_alter_column_drop_pk",
12495
+ tableName,
12496
+ columnName
12497
+ });
12498
+ }
12499
+ if (((_g = column4.default) == null ? void 0 : _g.type) === "added") {
12500
+ statements.push({
12501
+ type: "alter_table_alter_column_set_default",
12449
12502
  tableName,
12450
12503
  columnName,
12504
+ newDefaultValue: column4.default.value,
12451
12505
  schema: schema3,
12452
- newDataType: columnType,
12453
- columnDefault,
12454
12506
  columnOnUpdate,
12455
12507
  columnNotNull,
12456
- columnAutoIncrement
12508
+ columnAutoIncrement,
12509
+ newDataType: columnType,
12510
+ columnPk
12457
12511
  });
12458
12512
  }
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";
12513
+ if (((_h = column4.default) == null ? void 0 : _h.type) === "changed") {
12461
12514
  statements.push({
12462
- type,
12515
+ type: "alter_table_alter_column_set_default",
12463
12516
  tableName,
12464
12517
  columnName,
12518
+ newDefaultValue: column4.default.new,
12465
12519
  schema: schema3,
12466
- newDataType: columnType,
12467
- columnDefault,
12468
12520
  columnOnUpdate,
12469
12521
  columnNotNull,
12470
- columnAutoIncrement
12522
+ columnAutoIncrement,
12523
+ newDataType: columnType,
12524
+ columnPk
12471
12525
  });
12472
12526
  }
12473
- if (((_g = column4.notNull) == null ? void 0 : _g.type) === "deleted") {
12527
+ if (((_i = column4.default) == null ? void 0 : _i.type) === "deleted") {
12474
12528
  statements.push({
12475
- type: "alter_table_alter_column_drop_notnull",
12529
+ type: "alter_table_alter_column_drop_default",
12476
12530
  tableName,
12477
12531
  columnName,
12478
12532
  schema: schema3,
12479
- newDataType: columnType,
12480
12533
  columnDefault,
12481
12534
  columnOnUpdate,
12482
12535
  columnNotNull,
12483
- columnAutoIncrement
12536
+ columnAutoIncrement,
12537
+ newDataType: columnType,
12538
+ columnPk
12484
12539
  });
12485
12540
  }
12486
- if (((_h = column4.autoincrement) == null ? void 0 : _h.type) === "added") {
12541
+ if (((_j = column4.notNull) == null ? void 0 : _j.type) === "added") {
12487
12542
  statements.push({
12488
- type: "alter_table_alter_column_set_autoincrement",
12543
+ type: "alter_table_alter_column_set_notnull",
12489
12544
  tableName,
12490
12545
  columnName,
12491
12546
  schema: schema3,
@@ -12493,11 +12548,12 @@ var _prepareAlterColumns = (tableName, schema3, columns, json2) => {
12493
12548
  columnDefault,
12494
12549
  columnOnUpdate,
12495
12550
  columnNotNull,
12496
- columnAutoIncrement
12551
+ columnAutoIncrement,
12552
+ columnPk
12497
12553
  });
12498
12554
  }
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";
12555
+ if (((_k = column4.notNull) == null ? void 0 : _k.type) === "changed") {
12556
+ const type = column4.notNull.new ? "alter_table_alter_column_set_notnull" : "alter_table_alter_column_drop_notnull";
12501
12557
  statements.push({
12502
12558
  type,
12503
12559
  tableName,
@@ -12507,12 +12563,13 @@ var _prepareAlterColumns = (tableName, schema3, columns, json2) => {
12507
12563
  columnDefault,
12508
12564
  columnOnUpdate,
12509
12565
  columnNotNull,
12510
- columnAutoIncrement
12566
+ columnAutoIncrement,
12567
+ columnPk
12511
12568
  });
12512
12569
  }
12513
- if (((_j = column4.autoincrement) == null ? void 0 : _j.type) === "deleted") {
12570
+ if (((_l = column4.notNull) == null ? void 0 : _l.type) === "deleted") {
12514
12571
  statements.push({
12515
- type: "alter_table_alter_column_drop_autoincrement",
12572
+ type: "alter_table_alter_column_drop_notnull",
12516
12573
  tableName,
12517
12574
  columnName,
12518
12575
  schema: schema3,
@@ -12520,10 +12577,23 @@ var _prepareAlterColumns = (tableName, schema3, columns, json2) => {
12520
12577
  columnDefault,
12521
12578
  columnOnUpdate,
12522
12579
  columnNotNull,
12523
- columnAutoIncrement
12580
+ columnAutoIncrement,
12581
+ columnPk
12524
12582
  });
12525
12583
  }
12526
- if (((_k = column4.onUpdate) == null ? void 0 : _k.type) === "added") {
12584
+ if (((_m = column4.primaryKey) == null ? void 0 : _m.type) === "added" || ((_n = column4.primaryKey) == null ? void 0 : _n.type) === "changed" && column4.primaryKey.new) {
12585
+ const wasAutoincrement = statements.filter(
12586
+ (it) => it.type === "alter_table_alter_column_set_autoincrement"
12587
+ );
12588
+ if (wasAutoincrement.length === 0) {
12589
+ statements.push({
12590
+ type: "alter_table_alter_column_set_pk",
12591
+ tableName,
12592
+ columnName
12593
+ });
12594
+ }
12595
+ }
12596
+ if (((_o = column4.onUpdate) == null ? void 0 : _o.type) === "added") {
12527
12597
  statements.push({
12528
12598
  type: "alter_table_alter_column_set_on_update",
12529
12599
  tableName,
@@ -12533,10 +12603,11 @@ var _prepareAlterColumns = (tableName, schema3, columns, json2) => {
12533
12603
  columnDefault,
12534
12604
  columnOnUpdate,
12535
12605
  columnNotNull,
12536
- columnAutoIncrement
12606
+ columnAutoIncrement,
12607
+ columnPk
12537
12608
  });
12538
12609
  }
12539
- if (((_l = column4.onUpdate) == null ? void 0 : _l.type) === "deleted") {
12610
+ if (((_p = column4.onUpdate) == null ? void 0 : _p.type) === "deleted") {
12540
12611
  statements.push({
12541
12612
  type: "alter_table_alter_column_drop_on_update",
12542
12613
  tableName,
@@ -12546,7 +12617,8 @@ var _prepareAlterColumns = (tableName, schema3, columns, json2) => {
12546
12617
  columnDefault,
12547
12618
  columnOnUpdate,
12548
12619
  columnNotNull,
12549
- columnAutoIncrement
12620
+ columnAutoIncrement,
12621
+ columnPk
12550
12622
  });
12551
12623
  }
12552
12624
  }
@@ -12778,6 +12850,7 @@ var alteredColumnSchema = objectType({
12778
12850
  name: makeSelfOrChanged(stringType()),
12779
12851
  type: makeChanged(stringType()).optional(),
12780
12852
  default: makePatched(anyType()).optional(),
12853
+ primaryKey: makePatched(booleanType()).optional(),
12781
12854
  notNull: makePatched(booleanType()).optional(),
12782
12855
  onUpdate: makePatched(booleanType()).optional(),
12783
12856
  autoincrement: makePatched(booleanType()).optional()
@@ -13110,6 +13183,7 @@ var applySnapshotsDiff = async (json1, json2, dialect3, schemasResolver, tablesR
13110
13183
  jsonStatements.push(...jsonDropTables);
13111
13184
  jsonStatements.push(...jsonRenameTables);
13112
13185
  jsonStatements.push(...jsonRenameColumnsStatements);
13186
+ jsonStatements.push(...jsonDeletedCompositePKs);
13113
13187
  jsonStatements.push(...jsonTableAlternations.alterColumns);
13114
13188
  jsonStatements.push(...jsonTableAlternations.createColumns);
13115
13189
  jsonStatements.push(...jsonAlterReferencesForAlteredTables);
@@ -13119,7 +13193,6 @@ var applySnapshotsDiff = async (json1, json2, dialect3, schemasResolver, tablesR
13119
13193
  jsonStatements.push(...jsonDropIndexesForAllAlteredTables);
13120
13194
  jsonStatements.push(...jsonCreateIndexesForCreatedTables);
13121
13195
  jsonStatements.push(...jsonCreateIndexesForAllAlteredTables);
13122
- jsonStatements.push(...jsonDeletedCompositePKs);
13123
13196
  jsonStatements.push(...jsonAddedCompositePKs);
13124
13197
  jsonStatements.push(...jsonAlteredCompositePKs);
13125
13198
  jsonStatements.push(...jsonSetTableSchemas);