drizzle-kit 0.17.0-d21eb2d → 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 +19911 -18637
  2. package/package.json +7 -3
  3. package/readme.md +89 -15
  4. package/utils.js +165 -85
package/utils.js CHANGED
@@ -1,4 +1,3 @@
1
- "use strict";
2
1
  var __create = Object.create;
3
2
  var __defProp = Object.defineProperty;
4
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
@@ -11096,6 +11095,19 @@ var alternationsInColumn = (column4) => {
11096
11095
  return { ...others, notNull: { type: "deleted", value: it.notNull__deleted } };
11097
11096
  }
11098
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;
11099
11111
  }).map((it) => {
11100
11112
  if ("onUpdate" in it) {
11101
11113
  return { ...it, onUpdate: { type: "changed", old: it.onUpdate.__old, new: it.onUpdate.__new } };
@@ -11219,23 +11231,24 @@ var MySqlCreateTableConvertor = class extends Convertor {
11219
11231
  `;
11220
11232
  for (let i = 0; i < columns.length; i++) {
11221
11233
  const column4 = columns[i];
11222
- const primaryKeyStatement = column4.primaryKey ? "PRIMARY KEY" : "";
11223
- const notNullStatement = column4.notNull ? "NOT NULL" : "";
11224
- const defaultStatement = column4.default !== void 0 ? `DEFAULT ${column4.default}` : "";
11225
- const onUpdateStatement = column4.onUpdate ? `ON UPDATE CURRENT_TIMESTAMP` : "";
11226
- const autoincrementStatement = column4.autoincrement ? "AUTO_INCREMENT" : "";
11227
- statement += " " + `\`${column4.name}\` ${column4.type} ${autoincrementStatement} ${primaryKeyStatement} ${notNullStatement} ${defaultStatement} ${onUpdateStatement}`.replace(/ +/g, " ").trim();
11228
- 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";
11229
11241
  }
11230
- statement += `);`;
11231
- statement += `
11232
- `;
11233
11242
  if (typeof compositePKs !== "undefined" && compositePKs.length > 0) {
11243
+ statement += ",\n";
11234
11244
  const compositePK4 = MySqlSquasher.unsquashPK(compositePKs[0]);
11235
- statement += `ALTER TABLE ${tName} ADD PRIMARY KEY(\`${compositePK4.columns.join("`,`")}\`);`;
11245
+ statement += ` PRIMARY KEY(\`${compositePK4.columns.join("`,`")}\`)`;
11236
11246
  statement += `
11237
11247
  `;
11238
11248
  }
11249
+ statement += `);`;
11250
+ statement += `
11251
+ `;
11239
11252
  return statement;
11240
11253
  }
11241
11254
  };
@@ -11326,7 +11339,7 @@ var DropTableConvertor = class extends Convertor {
11326
11339
  }
11327
11340
  convert(statement) {
11328
11341
  const { tableName } = statement;
11329
- return `DROP TABLE ${tableName};`;
11342
+ return `DROP TABLE \`${tableName}\`;`;
11330
11343
  }
11331
11344
  };
11332
11345
  var PgRenameTableConvertor = class extends Convertor {
@@ -11434,12 +11447,13 @@ var MySqlAlterTableAddColumnConvertor = class extends Convertor {
11434
11447
  }
11435
11448
  convert(statement) {
11436
11449
  const { tableName, column: column4 } = statement;
11437
- const { name, type, notNull, primaryKey, autoincrement } = column4;
11438
- const defaultStatement = `${column4.default !== void 0 ? `DEFAULT ${column4.default}` : ""}`;
11439
- const notNullStatement = `${notNull ? "NOT NULL" : ""}`;
11440
- const primaryKeyStatement = `${primaryKey ? "PRIMARY KEY" : ""}`;
11441
- const autoincrementStatement = `${autoincrement ? "AUTO_INCREMENT" : ""}`;
11442
- 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};`;
11443
11457
  }
11444
11458
  };
11445
11459
  var SQLiteAlterTableAddColumnConvertor = class extends Convertor {
@@ -11514,27 +11528,25 @@ var PgAlterTableAlterColumnDropDefaultConvertor = class extends Convertor {
11514
11528
  return `ALTER TABLE ${tableName} ALTER COLUMN "${columnName}" DROP DEFAULT;`;
11515
11529
  }
11516
11530
  };
11517
- var MySqlAlterTableAlterColumnSetDefaultConvertor = class extends Convertor {
11531
+ var MySqlAlterTableAddPk = class extends Convertor {
11518
11532
  can(statement, dialect3) {
11519
- return statement.type === "alter_table_alter_column_set_default" && dialect3 === "mysql";
11533
+ return statement.type === "alter_table_alter_column_set_pk" && dialect3 === "mysql";
11520
11534
  }
11521
11535
  convert(statement) {
11522
- const { tableName, columnName } = statement;
11523
- return `ALTER TABLE ${tableName} ALTER COLUMN \`${columnName}\` SET DEFAULT ${statement.newDefaultValue};`;
11536
+ return `ALTER TABLE \`${statement.tableName}\` ADD PRIMARY KEY (\`${statement.columnName}\`);`;
11524
11537
  }
11525
11538
  };
11526
- var MySqlAlterTableAlterColumnDropDefaultConvertor = class extends Convertor {
11539
+ var MySqlAlterTableDropPk = class extends Convertor {
11527
11540
  can(statement, dialect3) {
11528
- return statement.type === "alter_table_alter_column_drop_default" && dialect3 === "mysql";
11541
+ return statement.type === "alter_table_alter_column_drop_pk" && dialect3 === "mysql";
11529
11542
  }
11530
11543
  convert(statement) {
11531
- const { tableName, columnName } = statement;
11532
- return `ALTER TABLE ${tableName} ALTER COLUMN \`${columnName}\` DROP DEFAULT;`;
11544
+ return `ALTER TABLE \`${statement.tableName}\` DROP PRIMARY KEY`;
11533
11545
  }
11534
11546
  };
11535
11547
  var MySqlModifyColumn = class extends Convertor {
11536
11548
  can(statement, dialect3) {
11537
- 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") && dialect3 === "mysql";
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";
11538
11550
  }
11539
11551
  convert(statement) {
11540
11552
  const { tableName, columnName } = statement;
@@ -11543,6 +11555,7 @@ var MySqlModifyColumn = class extends Convertor {
11543
11555
  let columnNotNull = "";
11544
11556
  let columnOnUpdate = "";
11545
11557
  let columnAutoincrement = "";
11558
+ let primaryKey = statement.columnPk ? " PRIMARY KEY" : "";
11546
11559
  if (statement.type === "alter_table_alter_column_drop_notnull") {
11547
11560
  columnType = ` ${statement.newDataType}`;
11548
11561
  columnDefault = statement.columnDefault ? ` DEFAULT ${statement.columnDefault}` : "";
@@ -11572,19 +11585,31 @@ var MySqlModifyColumn = class extends Convertor {
11572
11585
  columnOnUpdate = columnOnUpdate = statement.columnOnUpdate ? ` ON UPDATE CURRENT_TIMESTAMP` : "";
11573
11586
  columnType = ` ${statement.newDataType}`;
11574
11587
  columnDefault = statement.columnDefault ? ` DEFAULT ${statement.columnDefault}` : "";
11575
- columnAutoincrement = "AUTO_INCREMENT";
11588
+ columnAutoincrement = " AUTO_INCREMENT";
11576
11589
  } else if (statement.type === "alter_table_alter_column_drop_autoincrement") {
11577
11590
  columnNotNull = statement.columnNotNull ? ` NOT NULL` : "";
11578
11591
  columnOnUpdate = columnOnUpdate = statement.columnOnUpdate ? ` ON UPDATE CURRENT_TIMESTAMP` : "";
11579
11592
  columnType = ` ${statement.newDataType}`;
11580
11593
  columnDefault = statement.columnDefault ? ` DEFAULT ${statement.columnDefault}` : "";
11581
11594
  columnAutoincrement = "";
11595
+ } else if (statement.type === "alter_table_alter_column_set_default") {
11596
+ columnNotNull = statement.columnNotNull ? ` NOT NULL` : "";
11597
+ columnOnUpdate = columnOnUpdate = statement.columnOnUpdate ? ` ON UPDATE CURRENT_TIMESTAMP` : "";
11598
+ columnType = ` ${statement.newDataType}`;
11599
+ columnDefault = ` DEFAULT ${statement.newDefaultValue}`;
11600
+ columnAutoincrement = statement.columnAutoIncrement ? " AUTO_INCREMENT" : "";
11601
+ } else if (statement.type === "alter_table_alter_column_drop_default") {
11602
+ columnNotNull = statement.columnNotNull ? ` NOT NULL` : "";
11603
+ columnOnUpdate = columnOnUpdate = statement.columnOnUpdate ? ` ON UPDATE CURRENT_TIMESTAMP` : "";
11604
+ columnType = ` ${statement.newDataType}`;
11605
+ columnDefault = "";
11606
+ columnAutoincrement = statement.columnAutoIncrement ? " AUTO_INCREMENT" : "";
11582
11607
  } else {
11583
11608
  columnType = ` ${statement.newDataType}`;
11584
11609
  columnNotNull = statement.columnNotNull ? ` NOT NULL` : "";
11585
11610
  columnOnUpdate = columnOnUpdate = statement.columnOnUpdate ? ` ON UPDATE CURRENT_TIMESTAMP` : "";
11586
11611
  columnDefault = statement.columnDefault ? ` DEFAULT ${statement.columnDefault}` : "";
11587
- columnAutoincrement = statement.columnAutoIncrement ? "AUTO_INCREMENT" : "";
11612
+ columnAutoincrement = statement.columnAutoIncrement ? " AUTO_INCREMENT" : "";
11588
11613
  }
11589
11614
  columnDefault = columnDefault instanceof Date ? columnDefault.toISOString() : columnDefault;
11590
11615
  return `ALTER TABLE ${tableName} MODIFY COLUMN \`${columnName}\`${columnType}${columnAutoincrement}${columnNotNull}${columnDefault}${columnOnUpdate};`;
@@ -12143,8 +12168,6 @@ convertors.push(new PgAlterTableAlterColumnDropNotNullConvertor());
12143
12168
  convertors.push(new PgAlterTableAlterColumnSetDefaultConvertor());
12144
12169
  convertors.push(new PgAlterTableAlterColumnDropDefaultConvertor());
12145
12170
  convertors.push(new MySqlModifyColumn());
12146
- convertors.push(new MySqlAlterTableAlterColumnSetDefaultConvertor());
12147
- convertors.push(new MySqlAlterTableAlterColumnDropDefaultConvertor());
12148
12171
  convertors.push(new PgCreateForeignKeyConvertor());
12149
12172
  convertors.push(new MySqlCreateForeignKeyConvertor());
12150
12173
  convertors.push(new PgAlterForeignKeyConvertor());
@@ -12175,8 +12198,10 @@ convertors.push(new SqliteAlterTableAlterCompositePrimaryKeyConvertor());
12175
12198
  convertors.push(new PgAlterTableCreateCompositePrimaryKeyConvertor());
12176
12199
  convertors.push(new PgAlterTableDeleteCompositePrimaryKeyConvertor());
12177
12200
  convertors.push(new PgAlterTableAlterCompositePrimaryKeyConvertor());
12178
- convertors.push(new MySqlAlterTableCreateCompositePrimaryKeyConvertor());
12179
12201
  convertors.push(new MySqlAlterTableDeleteCompositePrimaryKeyConvertor());
12202
+ convertors.push(new MySqlAlterTableDropPk());
12203
+ convertors.push(new MySqlAlterTableCreateCompositePrimaryKeyConvertor());
12204
+ convertors.push(new MySqlAlterTableAddPk());
12180
12205
  convertors.push(new MySqlAlterTableAlterCompositePrimaryKeyConvertor());
12181
12206
  var fromJson = (statements, dialect3) => {
12182
12207
  const result = statements.map((statement) => {
@@ -12186,10 +12211,10 @@ var fromJson = (statements, dialect3) => {
12186
12211
  const convertor = filtered.length === 1 ? filtered[0] : void 0;
12187
12212
  if (!convertor) {
12188
12213
  console.log("no convertor:", statement.type, dialect3);
12189
- return "dry run";
12214
+ return "";
12190
12215
  }
12191
12216
  return convertor.convert(statement);
12192
- });
12217
+ }).filter((it) => it !== "");
12193
12218
  return result;
12194
12219
  };
12195
12220
  https:
@@ -12380,7 +12405,7 @@ var _prepareSQLiteAddColumns = (tableName, columns, referenceData) => {
12380
12405
  });
12381
12406
  };
12382
12407
  var _prepareAlterColumns = (tableName, schema3, columns, json2) => {
12383
- 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;
12384
12409
  let statements = [];
12385
12410
  for (const column4 of columns) {
12386
12411
  const columnName = typeof column4.name !== "string" ? column4.name.new : column4.name;
@@ -12389,97 +12414,134 @@ var _prepareAlterColumns = (tableName, schema3, columns, json2) => {
12389
12414
  const columnOnUpdate = json2.tables[tableName].columns[columnName].onUpdate;
12390
12415
  const columnNotNull = json2.tables[tableName].columns[columnName].notNull;
12391
12416
  const columnAutoIncrement = json2.tables[tableName].columns[columnName].autoincrement;
12392
- 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") {
12393
12419
  statements.push({
12394
- type: "alter_table_rename_column",
12420
+ type: "alter_table_alter_column_set_autoincrement",
12395
12421
  tableName,
12396
- oldColumnName: column4.name.old,
12397
- newColumnName: column4.name.new,
12398
- schema: schema3
12422
+ columnName,
12423
+ schema: schema3,
12424
+ newDataType: columnType,
12425
+ columnDefault,
12426
+ columnOnUpdate,
12427
+ columnNotNull,
12428
+ columnAutoIncrement,
12429
+ columnPk
12399
12430
  });
12400
12431
  }
12401
- if (((_a = column4.type) == null ? void 0 : _a.type) === "changed") {
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";
12402
12434
  statements.push({
12403
- type: "alter_table_alter_column_set_type",
12435
+ type,
12404
12436
  tableName,
12405
12437
  columnName,
12406
- newDataType: column4.type.new,
12407
12438
  schema: schema3,
12439
+ newDataType: columnType,
12408
12440
  columnDefault,
12409
12441
  columnOnUpdate,
12410
12442
  columnNotNull,
12411
- columnAutoIncrement
12443
+ columnAutoIncrement,
12444
+ columnPk
12412
12445
  });
12413
12446
  }
12414
- if (((_b = column4.default) == null ? void 0 : _b.type) === "added") {
12447
+ if (((_c = column4.autoincrement) == null ? void 0 : _c.type) === "deleted") {
12415
12448
  statements.push({
12416
- type: "alter_table_alter_column_set_default",
12449
+ type: "alter_table_alter_column_drop_autoincrement",
12417
12450
  tableName,
12418
12451
  columnName,
12419
- newDefaultValue: column4.default.value,
12420
- schema: schema3
12452
+ schema: schema3,
12453
+ newDataType: columnType,
12454
+ columnDefault,
12455
+ columnOnUpdate,
12456
+ columnNotNull,
12457
+ columnAutoIncrement,
12458
+ columnPk
12421
12459
  });
12422
12460
  }
12423
- if (((_c = column4.default) == null ? void 0 : _c.type) === "changed") {
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") {
12424
12471
  statements.push({
12425
- type: "alter_table_alter_column_set_default",
12472
+ type: "alter_table_rename_column",
12426
12473
  tableName,
12427
- columnName,
12428
- newDefaultValue: column4.default.new,
12474
+ oldColumnName: column4.name.old,
12475
+ newColumnName: column4.name.new,
12429
12476
  schema: schema3
12430
12477
  });
12431
12478
  }
12432
- if (((_d = column4.default) == null ? void 0 : _d.type) === "deleted") {
12479
+ if (((_d = column4.type) == null ? void 0 : _d.type) === "changed") {
12433
12480
  statements.push({
12434
- type: "alter_table_alter_column_drop_default",
12481
+ type: "alter_table_alter_column_set_type",
12435
12482
  tableName,
12436
12483
  columnName,
12437
- schema: schema3
12484
+ newDataType: column4.type.new,
12485
+ schema: schema3,
12486
+ columnDefault,
12487
+ columnOnUpdate,
12488
+ columnNotNull,
12489
+ columnAutoIncrement,
12490
+ columnPk
12438
12491
  });
12439
12492
  }
12440
- 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) {
12441
12494
  statements.push({
12442
- 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",
12443
12503
  tableName,
12444
12504
  columnName,
12505
+ newDefaultValue: column4.default.value,
12445
12506
  schema: schema3,
12446
- newDataType: columnType,
12447
- columnDefault,
12448
12507
  columnOnUpdate,
12449
12508
  columnNotNull,
12450
- columnAutoIncrement
12509
+ columnAutoIncrement,
12510
+ newDataType: columnType,
12511
+ columnPk
12451
12512
  });
12452
12513
  }
12453
- if (((_f = column4.notNull) == null ? void 0 : _f.type) === "changed") {
12454
- 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") {
12455
12515
  statements.push({
12456
- type,
12516
+ type: "alter_table_alter_column_set_default",
12457
12517
  tableName,
12458
12518
  columnName,
12519
+ newDefaultValue: column4.default.new,
12459
12520
  schema: schema3,
12460
- newDataType: columnType,
12461
- columnDefault,
12462
12521
  columnOnUpdate,
12463
12522
  columnNotNull,
12464
- columnAutoIncrement
12523
+ columnAutoIncrement,
12524
+ newDataType: columnType,
12525
+ columnPk
12465
12526
  });
12466
12527
  }
12467
- if (((_g = column4.notNull) == null ? void 0 : _g.type) === "deleted") {
12528
+ if (((_i = column4.default) == null ? void 0 : _i.type) === "deleted") {
12468
12529
  statements.push({
12469
- type: "alter_table_alter_column_drop_notnull",
12530
+ type: "alter_table_alter_column_drop_default",
12470
12531
  tableName,
12471
12532
  columnName,
12472
12533
  schema: schema3,
12473
- newDataType: columnType,
12474
12534
  columnDefault,
12475
12535
  columnOnUpdate,
12476
12536
  columnNotNull,
12477
- columnAutoIncrement
12537
+ columnAutoIncrement,
12538
+ newDataType: columnType,
12539
+ columnPk
12478
12540
  });
12479
12541
  }
12480
- if (((_h = column4.autoincrement) == null ? void 0 : _h.type) === "added") {
12542
+ if (((_j = column4.notNull) == null ? void 0 : _j.type) === "added") {
12481
12543
  statements.push({
12482
- type: "alter_table_alter_column_set_autoincrement",
12544
+ type: "alter_table_alter_column_set_notnull",
12483
12545
  tableName,
12484
12546
  columnName,
12485
12547
  schema: schema3,
@@ -12487,11 +12549,12 @@ var _prepareAlterColumns = (tableName, schema3, columns, json2) => {
12487
12549
  columnDefault,
12488
12550
  columnOnUpdate,
12489
12551
  columnNotNull,
12490
- columnAutoIncrement
12552
+ columnAutoIncrement,
12553
+ columnPk
12491
12554
  });
12492
12555
  }
12493
- if (((_i = column4.autoincrement) == null ? void 0 : _i.type) === "changed") {
12494
- 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";
12495
12558
  statements.push({
12496
12559
  type,
12497
12560
  tableName,
@@ -12501,12 +12564,13 @@ var _prepareAlterColumns = (tableName, schema3, columns, json2) => {
12501
12564
  columnDefault,
12502
12565
  columnOnUpdate,
12503
12566
  columnNotNull,
12504
- columnAutoIncrement
12567
+ columnAutoIncrement,
12568
+ columnPk
12505
12569
  });
12506
12570
  }
12507
- if (((_j = column4.autoincrement) == null ? void 0 : _j.type) === "deleted") {
12571
+ if (((_l = column4.notNull) == null ? void 0 : _l.type) === "deleted") {
12508
12572
  statements.push({
12509
- type: "alter_table_alter_column_drop_autoincrement",
12573
+ type: "alter_table_alter_column_drop_notnull",
12510
12574
  tableName,
12511
12575
  columnName,
12512
12576
  schema: schema3,
@@ -12514,10 +12578,23 @@ var _prepareAlterColumns = (tableName, schema3, columns, json2) => {
12514
12578
  columnDefault,
12515
12579
  columnOnUpdate,
12516
12580
  columnNotNull,
12517
- columnAutoIncrement
12581
+ columnAutoIncrement,
12582
+ columnPk
12518
12583
  });
12519
12584
  }
12520
- 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") {
12521
12598
  statements.push({
12522
12599
  type: "alter_table_alter_column_set_on_update",
12523
12600
  tableName,
@@ -12527,10 +12604,11 @@ var _prepareAlterColumns = (tableName, schema3, columns, json2) => {
12527
12604
  columnDefault,
12528
12605
  columnOnUpdate,
12529
12606
  columnNotNull,
12530
- columnAutoIncrement
12607
+ columnAutoIncrement,
12608
+ columnPk
12531
12609
  });
12532
12610
  }
12533
- if (((_l = column4.onUpdate) == null ? void 0 : _l.type) === "deleted") {
12611
+ if (((_p = column4.onUpdate) == null ? void 0 : _p.type) === "deleted") {
12534
12612
  statements.push({
12535
12613
  type: "alter_table_alter_column_drop_on_update",
12536
12614
  tableName,
@@ -12540,7 +12618,8 @@ var _prepareAlterColumns = (tableName, schema3, columns, json2) => {
12540
12618
  columnDefault,
12541
12619
  columnOnUpdate,
12542
12620
  columnNotNull,
12543
- columnAutoIncrement
12621
+ columnAutoIncrement,
12622
+ columnPk
12544
12623
  });
12545
12624
  }
12546
12625
  }
@@ -12772,6 +12851,7 @@ var alteredColumnSchema = objectType({
12772
12851
  name: makeSelfOrChanged(stringType()),
12773
12852
  type: makeChanged(stringType()).optional(),
12774
12853
  default: makePatched(anyType()).optional(),
12854
+ primaryKey: makePatched(booleanType()).optional(),
12775
12855
  notNull: makePatched(booleanType()).optional(),
12776
12856
  onUpdate: makePatched(booleanType()).optional(),
12777
12857
  autoincrement: makePatched(booleanType()).optional()
@@ -13104,6 +13184,7 @@ var applySnapshotsDiff = async (json1, json2, dialect3, schemasResolver, tablesR
13104
13184
  jsonStatements.push(...jsonDropTables);
13105
13185
  jsonStatements.push(...jsonRenameTables);
13106
13186
  jsonStatements.push(...jsonRenameColumnsStatements);
13187
+ jsonStatements.push(...jsonDeletedCompositePKs);
13107
13188
  jsonStatements.push(...jsonTableAlternations.alterColumns);
13108
13189
  jsonStatements.push(...jsonTableAlternations.createColumns);
13109
13190
  jsonStatements.push(...jsonAlterReferencesForAlteredTables);
@@ -13113,7 +13194,6 @@ var applySnapshotsDiff = async (json1, json2, dialect3, schemasResolver, tablesR
13113
13194
  jsonStatements.push(...jsonDropIndexesForAllAlteredTables);
13114
13195
  jsonStatements.push(...jsonCreateIndexesForCreatedTables);
13115
13196
  jsonStatements.push(...jsonCreateIndexesForAllAlteredTables);
13116
- jsonStatements.push(...jsonDeletedCompositePKs);
13117
13197
  jsonStatements.push(...jsonAddedCompositePKs);
13118
13198
  jsonStatements.push(...jsonAlteredCompositePKs);
13119
13199
  jsonStatements.push(...jsonSetTableSchemas);