drizzle-kit 0.17.0 → 0.17.1-6474464

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 (5) hide show
  1. package/index.d.ts +14 -0
  2. package/index.js +20157 -18839
  3. package/package.json +10 -5
  4. package/readme.md +2 -2
  5. package/utils.js +165 -85
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "drizzle-kit",
3
- "version": "0.17.0",
3
+ "version": "0.17.1-6474464",
4
4
  "repository": "https://github.com/drizzle-team/drizzle-kit-mirror",
5
5
  "author": "Drizzle Team",
6
6
  "license": "MIT",
@@ -9,12 +9,13 @@
9
9
  },
10
10
  "scripts": {
11
11
  "migrate:old": "drizzle-kit generate:pg --out ./dev/migrations-pg --schema ./dev/migrations-pg/schema.ts",
12
+ "push": "node -r esbuild-register ./src/cli/index.ts push:mysql",
12
13
  "migrate:old:mysql": "drizzle-kit generate:mysql --out ./dev/migrations-mysql --schema ./dev/migrations-mysql/schema.ts",
13
14
  "start:pg": "node -r esbuild-register ./src/cli/index.ts generate:pg --out ./dev/migrations-pg --schema ./dev/migrations-pg/schema.ts",
14
15
  "start:sqlite": "node -r esbuild-register ./src/cli/index.ts generate:sqlite --out ./dev/migrations-sqlite --schema ./dev/migrations-sqlite/schema.ts",
15
- "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",
16
17
  "check:pg": "node -r esbuild-register ./src/cli/index.ts check --out ./dev/migrations --dialect pg",
17
- "introspect:mysql": "node -r esbuild-register ./src/cli/index.ts introspect:mysql --out ./dev/introspect-mysql --connectionString",
18
+ "introspect:mysql": "node -r esbuild-register ./src/cli/index.ts introspect:mysql",
18
19
  "introspect:pg": "node -r esbuild-register ./src/cli/index.ts introspect:pg --out ./dev/introspect-pg --connectionString=postgresql://postgres@localhost:5432/introspect",
19
20
  "up:pg": "node -r esbuild-register ./src/cli/index.ts up:pg --out ./dev/migrations-pg",
20
21
  "up:mysql": "node -r esbuild-register ./src/cli/index.ts up:mysql --out ./dev/migrations-mysql",
@@ -28,9 +29,10 @@
28
29
  "sim": "node -r esbuild-register ./dev/simulate.ts",
29
30
  "sim:sqlite": "node -r esbuild-register ./dev/sqlite/index.ts",
30
31
  "test": "ava test --timeout=60s",
31
- "build": "pnpm build:cli && pnpm build:utils",
32
+ "build": "pnpm build:cli && pnpm build:utils && pnpm build:cli-types",
32
33
  "build:cli": "esbuild ./src/cli/index.ts --bundle --platform=node --target=node10.4 --outfile=./dist/index.js --external:esbuild --external:drizzle-orm-pg --external:drizzle-orm-sqlite --external:drizzle-orm-mysql --external:drizzle-orm --external:pg-native",
33
34
  "build:utils": "esbuild ./src/utils.ts --bundle --platform=node --target=node10.4 --outfile=./dist/utils.js",
35
+ "build:cli-types": "tsc -p tsconfig.cli-types.json",
34
36
  "pack": "build && package",
35
37
  "tsc": "tsc -p tsconfig.build.json",
36
38
  "pub": "cp package.json readme.md dist/ && cd dist && npm publish"
@@ -55,19 +57,22 @@
55
57
  "glob": "^8.1.0",
56
58
  "hanji": "^0.0.5",
57
59
  "json-diff": "0.9.0",
60
+ "minimatch": "^7.4.3",
58
61
  "zod": "^3.20.2"
59
62
  },
60
63
  "devDependencies": {
61
64
  "@types/dockerode": "^3.3.14",
62
65
  "@types/glob": "^8.1.0",
66
+ "@types/minimatch": "^5.1.2",
63
67
  "@types/node": "^18.11.15",
64
68
  "@types/pg": "^8.6.5",
65
69
  "@typescript-eslint/eslint-plugin": "^5.46.1",
66
70
  "@typescript-eslint/parser": "^5.46.1",
67
71
  "ava": "^5.1.0",
68
72
  "dockerode": "^3.3.4",
73
+ "dotenv": "^16.0.3",
69
74
  "drizzle-kit": "^0.16.8",
70
- "drizzle-orm": "0.21.0-26e3751",
75
+ "drizzle-orm": "0.23.2",
71
76
  "esbuild": "^0.15.7",
72
77
  "esbuild-register": "^3.3.3",
73
78
  "eslint": "^8.29.0",
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,23 +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("`,`")}\`);`;
11245
+ statement += ` PRIMARY KEY(\`${compositePK4.columns.join("`,`")}\`)`;
11235
11246
  statement += `
11236
11247
  `;
11237
11248
  }
11249
+ statement += `);`;
11250
+ statement += `
11251
+ `;
11238
11252
  return statement;
11239
11253
  }
11240
11254
  };
@@ -11325,7 +11339,7 @@ var DropTableConvertor = class extends Convertor {
11325
11339
  }
11326
11340
  convert(statement) {
11327
11341
  const { tableName } = statement;
11328
- return `DROP TABLE ${tableName};`;
11342
+ return `DROP TABLE \`${tableName}\`;`;
11329
11343
  }
11330
11344
  };
11331
11345
  var PgRenameTableConvertor = class extends Convertor {
@@ -11433,12 +11447,13 @@ var MySqlAlterTableAddColumnConvertor = class extends Convertor {
11433
11447
  }
11434
11448
  convert(statement) {
11435
11449
  const { tableName, column: column4 } = statement;
11436
- const { name, type, notNull, primaryKey, autoincrement } = column4;
11437
- const defaultStatement = `${column4.default !== void 0 ? `DEFAULT ${column4.default}` : ""}`;
11438
- const notNullStatement = `${notNull ? "NOT NULL" : ""}`;
11439
- const primaryKeyStatement = `${primaryKey ? "PRIMARY KEY" : ""}`;
11440
- const autoincrementStatement = `${autoincrement ? "AUTO_INCREMENT" : ""}`;
11441
- 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};`;
11442
11457
  }
11443
11458
  };
11444
11459
  var SQLiteAlterTableAddColumnConvertor = class extends Convertor {
@@ -11513,27 +11528,25 @@ var PgAlterTableAlterColumnDropDefaultConvertor = class extends Convertor {
11513
11528
  return `ALTER TABLE ${tableName} ALTER COLUMN "${columnName}" DROP DEFAULT;`;
11514
11529
  }
11515
11530
  };
11516
- var MySqlAlterTableAlterColumnSetDefaultConvertor = class extends Convertor {
11531
+ var MySqlAlterTableAddPk = class extends Convertor {
11517
11532
  can(statement, dialect3) {
11518
- return statement.type === "alter_table_alter_column_set_default" && dialect3 === "mysql";
11533
+ return statement.type === "alter_table_alter_column_set_pk" && dialect3 === "mysql";
11519
11534
  }
11520
11535
  convert(statement) {
11521
- const { tableName, columnName } = statement;
11522
- return `ALTER TABLE ${tableName} ALTER COLUMN \`${columnName}\` SET DEFAULT ${statement.newDefaultValue};`;
11536
+ return `ALTER TABLE \`${statement.tableName}\` ADD PRIMARY KEY (\`${statement.columnName}\`);`;
11523
11537
  }
11524
11538
  };
11525
- var MySqlAlterTableAlterColumnDropDefaultConvertor = class extends Convertor {
11539
+ var MySqlAlterTableDropPk = class extends Convertor {
11526
11540
  can(statement, dialect3) {
11527
- return statement.type === "alter_table_alter_column_drop_default" && dialect3 === "mysql";
11541
+ return statement.type === "alter_table_alter_column_drop_pk" && dialect3 === "mysql";
11528
11542
  }
11529
11543
  convert(statement) {
11530
- const { tableName, columnName } = statement;
11531
- return `ALTER TABLE ${tableName} ALTER COLUMN \`${columnName}\` DROP DEFAULT;`;
11544
+ return `ALTER TABLE \`${statement.tableName}\` DROP PRIMARY KEY`;
11532
11545
  }
11533
11546
  };
11534
11547
  var MySqlModifyColumn = class extends Convertor {
11535
11548
  can(statement, dialect3) {
11536
- 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";
11537
11550
  }
11538
11551
  convert(statement) {
11539
11552
  const { tableName, columnName } = statement;
@@ -11542,6 +11555,7 @@ var MySqlModifyColumn = class extends Convertor {
11542
11555
  let columnNotNull = "";
11543
11556
  let columnOnUpdate = "";
11544
11557
  let columnAutoincrement = "";
11558
+ let primaryKey = statement.columnPk ? " PRIMARY KEY" : "";
11545
11559
  if (statement.type === "alter_table_alter_column_drop_notnull") {
11546
11560
  columnType = ` ${statement.newDataType}`;
11547
11561
  columnDefault = statement.columnDefault ? ` DEFAULT ${statement.columnDefault}` : "";
@@ -11571,19 +11585,31 @@ var MySqlModifyColumn = class extends Convertor {
11571
11585
  columnOnUpdate = columnOnUpdate = statement.columnOnUpdate ? ` ON UPDATE CURRENT_TIMESTAMP` : "";
11572
11586
  columnType = ` ${statement.newDataType}`;
11573
11587
  columnDefault = statement.columnDefault ? ` DEFAULT ${statement.columnDefault}` : "";
11574
- columnAutoincrement = "AUTO_INCREMENT";
11588
+ columnAutoincrement = " AUTO_INCREMENT";
11575
11589
  } else if (statement.type === "alter_table_alter_column_drop_autoincrement") {
11576
11590
  columnNotNull = statement.columnNotNull ? ` NOT NULL` : "";
11577
11591
  columnOnUpdate = columnOnUpdate = statement.columnOnUpdate ? ` ON UPDATE CURRENT_TIMESTAMP` : "";
11578
11592
  columnType = ` ${statement.newDataType}`;
11579
11593
  columnDefault = statement.columnDefault ? ` DEFAULT ${statement.columnDefault}` : "";
11580
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" : "";
11581
11607
  } else {
11582
11608
  columnType = ` ${statement.newDataType}`;
11583
11609
  columnNotNull = statement.columnNotNull ? ` NOT NULL` : "";
11584
11610
  columnOnUpdate = columnOnUpdate = statement.columnOnUpdate ? ` ON UPDATE CURRENT_TIMESTAMP` : "";
11585
11611
  columnDefault = statement.columnDefault ? ` DEFAULT ${statement.columnDefault}` : "";
11586
- columnAutoincrement = statement.columnAutoIncrement ? "AUTO_INCREMENT" : "";
11612
+ columnAutoincrement = statement.columnAutoIncrement ? " AUTO_INCREMENT" : "";
11587
11613
  }
11588
11614
  columnDefault = columnDefault instanceof Date ? columnDefault.toISOString() : columnDefault;
11589
11615
  return `ALTER TABLE ${tableName} MODIFY COLUMN \`${columnName}\`${columnType}${columnAutoincrement}${columnNotNull}${columnDefault}${columnOnUpdate};`;
@@ -11874,7 +11900,6 @@ var PgAlterForeignKeyConvertor = class extends Convertor {
11874
11900
  sql += " WHEN duplicate_object THEN null;\n";
11875
11901
  sql += "END $$;\n";
11876
11902
  return sql;
11877
- throw new Error("TODO");
11878
11903
  }
11879
11904
  };
11880
11905
  var SqliteAlterForeignKeyConvertor = class extends Convertor {
@@ -12142,8 +12167,6 @@ convertors.push(new PgAlterTableAlterColumnDropNotNullConvertor());
12142
12167
  convertors.push(new PgAlterTableAlterColumnSetDefaultConvertor());
12143
12168
  convertors.push(new PgAlterTableAlterColumnDropDefaultConvertor());
12144
12169
  convertors.push(new MySqlModifyColumn());
12145
- convertors.push(new MySqlAlterTableAlterColumnSetDefaultConvertor());
12146
- convertors.push(new MySqlAlterTableAlterColumnDropDefaultConvertor());
12147
12170
  convertors.push(new PgCreateForeignKeyConvertor());
12148
12171
  convertors.push(new MySqlCreateForeignKeyConvertor());
12149
12172
  convertors.push(new PgAlterForeignKeyConvertor());
@@ -12174,8 +12197,10 @@ convertors.push(new SqliteAlterTableAlterCompositePrimaryKeyConvertor());
12174
12197
  convertors.push(new PgAlterTableCreateCompositePrimaryKeyConvertor());
12175
12198
  convertors.push(new PgAlterTableDeleteCompositePrimaryKeyConvertor());
12176
12199
  convertors.push(new PgAlterTableAlterCompositePrimaryKeyConvertor());
12177
- convertors.push(new MySqlAlterTableCreateCompositePrimaryKeyConvertor());
12178
12200
  convertors.push(new MySqlAlterTableDeleteCompositePrimaryKeyConvertor());
12201
+ convertors.push(new MySqlAlterTableDropPk());
12202
+ convertors.push(new MySqlAlterTableCreateCompositePrimaryKeyConvertor());
12203
+ convertors.push(new MySqlAlterTableAddPk());
12179
12204
  convertors.push(new MySqlAlterTableAlterCompositePrimaryKeyConvertor());
12180
12205
  var fromJson = (statements, dialect3) => {
12181
12206
  const result = statements.map((statement) => {
@@ -12185,10 +12210,10 @@ var fromJson = (statements, dialect3) => {
12185
12210
  const convertor = filtered.length === 1 ? filtered[0] : void 0;
12186
12211
  if (!convertor) {
12187
12212
  console.log("no convertor:", statement.type, dialect3);
12188
- return "dry run";
12213
+ return "";
12189
12214
  }
12190
12215
  return convertor.convert(statement);
12191
- });
12216
+ }).filter((it) => it !== "");
12192
12217
  return result;
12193
12218
  };
12194
12219
  https:
@@ -12379,7 +12404,7 @@ var _prepareSQLiteAddColumns = (tableName, columns, referenceData) => {
12379
12404
  });
12380
12405
  };
12381
12406
  var _prepareAlterColumns = (tableName, schema3, columns, json2) => {
12382
- 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;
12383
12408
  let statements = [];
12384
12409
  for (const column4 of columns) {
12385
12410
  const columnName = typeof column4.name !== "string" ? column4.name.new : column4.name;
@@ -12388,97 +12413,134 @@ var _prepareAlterColumns = (tableName, schema3, columns, json2) => {
12388
12413
  const columnOnUpdate = json2.tables[tableName].columns[columnName].onUpdate;
12389
12414
  const columnNotNull = json2.tables[tableName].columns[columnName].notNull;
12390
12415
  const columnAutoIncrement = json2.tables[tableName].columns[columnName].autoincrement;
12391
- 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") {
12392
12418
  statements.push({
12393
- type: "alter_table_rename_column",
12419
+ type: "alter_table_alter_column_set_autoincrement",
12394
12420
  tableName,
12395
- oldColumnName: column4.name.old,
12396
- newColumnName: column4.name.new,
12397
- schema: schema3
12421
+ columnName,
12422
+ schema: schema3,
12423
+ newDataType: columnType,
12424
+ columnDefault,
12425
+ columnOnUpdate,
12426
+ columnNotNull,
12427
+ columnAutoIncrement,
12428
+ columnPk
12398
12429
  });
12399
12430
  }
12400
- if (((_a = column4.type) == null ? void 0 : _a.type) === "changed") {
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";
12401
12433
  statements.push({
12402
- type: "alter_table_alter_column_set_type",
12434
+ type,
12403
12435
  tableName,
12404
12436
  columnName,
12405
- newDataType: column4.type.new,
12406
12437
  schema: schema3,
12438
+ newDataType: columnType,
12407
12439
  columnDefault,
12408
12440
  columnOnUpdate,
12409
12441
  columnNotNull,
12410
- columnAutoIncrement
12442
+ columnAutoIncrement,
12443
+ columnPk
12411
12444
  });
12412
12445
  }
12413
- if (((_b = column4.default) == null ? void 0 : _b.type) === "added") {
12446
+ if (((_c = column4.autoincrement) == null ? void 0 : _c.type) === "deleted") {
12414
12447
  statements.push({
12415
- type: "alter_table_alter_column_set_default",
12448
+ type: "alter_table_alter_column_drop_autoincrement",
12416
12449
  tableName,
12417
12450
  columnName,
12418
- newDefaultValue: column4.default.value,
12419
- schema: schema3
12451
+ schema: schema3,
12452
+ newDataType: columnType,
12453
+ columnDefault,
12454
+ columnOnUpdate,
12455
+ columnNotNull,
12456
+ columnAutoIncrement,
12457
+ columnPk
12420
12458
  });
12421
12459
  }
12422
- if (((_c = column4.default) == null ? void 0 : _c.type) === "changed") {
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") {
12423
12470
  statements.push({
12424
- type: "alter_table_alter_column_set_default",
12471
+ type: "alter_table_rename_column",
12425
12472
  tableName,
12426
- columnName,
12427
- newDefaultValue: column4.default.new,
12473
+ oldColumnName: column4.name.old,
12474
+ newColumnName: column4.name.new,
12428
12475
  schema: schema3
12429
12476
  });
12430
12477
  }
12431
- if (((_d = column4.default) == null ? void 0 : _d.type) === "deleted") {
12478
+ if (((_d = column4.type) == null ? void 0 : _d.type) === "changed") {
12432
12479
  statements.push({
12433
- type: "alter_table_alter_column_drop_default",
12480
+ type: "alter_table_alter_column_set_type",
12434
12481
  tableName,
12435
12482
  columnName,
12436
- schema: schema3
12483
+ newDataType: column4.type.new,
12484
+ schema: schema3,
12485
+ columnDefault,
12486
+ columnOnUpdate,
12487
+ columnNotNull,
12488
+ columnAutoIncrement,
12489
+ columnPk
12437
12490
  });
12438
12491
  }
12439
- 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) {
12440
12493
  statements.push({
12441
- 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",
12442
12502
  tableName,
12443
12503
  columnName,
12504
+ newDefaultValue: column4.default.value,
12444
12505
  schema: schema3,
12445
- newDataType: columnType,
12446
- columnDefault,
12447
12506
  columnOnUpdate,
12448
12507
  columnNotNull,
12449
- columnAutoIncrement
12508
+ columnAutoIncrement,
12509
+ newDataType: columnType,
12510
+ columnPk
12450
12511
  });
12451
12512
  }
12452
- if (((_f = column4.notNull) == null ? void 0 : _f.type) === "changed") {
12453
- 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") {
12454
12514
  statements.push({
12455
- type,
12515
+ type: "alter_table_alter_column_set_default",
12456
12516
  tableName,
12457
12517
  columnName,
12518
+ newDefaultValue: column4.default.new,
12458
12519
  schema: schema3,
12459
- newDataType: columnType,
12460
- columnDefault,
12461
12520
  columnOnUpdate,
12462
12521
  columnNotNull,
12463
- columnAutoIncrement
12522
+ columnAutoIncrement,
12523
+ newDataType: columnType,
12524
+ columnPk
12464
12525
  });
12465
12526
  }
12466
- if (((_g = column4.notNull) == null ? void 0 : _g.type) === "deleted") {
12527
+ if (((_i = column4.default) == null ? void 0 : _i.type) === "deleted") {
12467
12528
  statements.push({
12468
- type: "alter_table_alter_column_drop_notnull",
12529
+ type: "alter_table_alter_column_drop_default",
12469
12530
  tableName,
12470
12531
  columnName,
12471
12532
  schema: schema3,
12472
- newDataType: columnType,
12473
12533
  columnDefault,
12474
12534
  columnOnUpdate,
12475
12535
  columnNotNull,
12476
- columnAutoIncrement
12536
+ columnAutoIncrement,
12537
+ newDataType: columnType,
12538
+ columnPk
12477
12539
  });
12478
12540
  }
12479
- if (((_h = column4.autoincrement) == null ? void 0 : _h.type) === "added") {
12541
+ if (((_j = column4.notNull) == null ? void 0 : _j.type) === "added") {
12480
12542
  statements.push({
12481
- type: "alter_table_alter_column_set_autoincrement",
12543
+ type: "alter_table_alter_column_set_notnull",
12482
12544
  tableName,
12483
12545
  columnName,
12484
12546
  schema: schema3,
@@ -12486,11 +12548,12 @@ var _prepareAlterColumns = (tableName, schema3, columns, json2) => {
12486
12548
  columnDefault,
12487
12549
  columnOnUpdate,
12488
12550
  columnNotNull,
12489
- columnAutoIncrement
12551
+ columnAutoIncrement,
12552
+ columnPk
12490
12553
  });
12491
12554
  }
12492
- if (((_i = column4.autoincrement) == null ? void 0 : _i.type) === "changed") {
12493
- 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";
12494
12557
  statements.push({
12495
12558
  type,
12496
12559
  tableName,
@@ -12500,12 +12563,13 @@ var _prepareAlterColumns = (tableName, schema3, columns, json2) => {
12500
12563
  columnDefault,
12501
12564
  columnOnUpdate,
12502
12565
  columnNotNull,
12503
- columnAutoIncrement
12566
+ columnAutoIncrement,
12567
+ columnPk
12504
12568
  });
12505
12569
  }
12506
- if (((_j = column4.autoincrement) == null ? void 0 : _j.type) === "deleted") {
12570
+ if (((_l = column4.notNull) == null ? void 0 : _l.type) === "deleted") {
12507
12571
  statements.push({
12508
- type: "alter_table_alter_column_drop_autoincrement",
12572
+ type: "alter_table_alter_column_drop_notnull",
12509
12573
  tableName,
12510
12574
  columnName,
12511
12575
  schema: schema3,
@@ -12513,10 +12577,23 @@ var _prepareAlterColumns = (tableName, schema3, columns, json2) => {
12513
12577
  columnDefault,
12514
12578
  columnOnUpdate,
12515
12579
  columnNotNull,
12516
- columnAutoIncrement
12580
+ columnAutoIncrement,
12581
+ columnPk
12517
12582
  });
12518
12583
  }
12519
- 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") {
12520
12597
  statements.push({
12521
12598
  type: "alter_table_alter_column_set_on_update",
12522
12599
  tableName,
@@ -12526,10 +12603,11 @@ var _prepareAlterColumns = (tableName, schema3, columns, json2) => {
12526
12603
  columnDefault,
12527
12604
  columnOnUpdate,
12528
12605
  columnNotNull,
12529
- columnAutoIncrement
12606
+ columnAutoIncrement,
12607
+ columnPk
12530
12608
  });
12531
12609
  }
12532
- if (((_l = column4.onUpdate) == null ? void 0 : _l.type) === "deleted") {
12610
+ if (((_p = column4.onUpdate) == null ? void 0 : _p.type) === "deleted") {
12533
12611
  statements.push({
12534
12612
  type: "alter_table_alter_column_drop_on_update",
12535
12613
  tableName,
@@ -12539,7 +12617,8 @@ var _prepareAlterColumns = (tableName, schema3, columns, json2) => {
12539
12617
  columnDefault,
12540
12618
  columnOnUpdate,
12541
12619
  columnNotNull,
12542
- columnAutoIncrement
12620
+ columnAutoIncrement,
12621
+ columnPk
12543
12622
  });
12544
12623
  }
12545
12624
  }
@@ -12771,6 +12850,7 @@ var alteredColumnSchema = objectType({
12771
12850
  name: makeSelfOrChanged(stringType()),
12772
12851
  type: makeChanged(stringType()).optional(),
12773
12852
  default: makePatched(anyType()).optional(),
12853
+ primaryKey: makePatched(booleanType()).optional(),
12774
12854
  notNull: makePatched(booleanType()).optional(),
12775
12855
  onUpdate: makePatched(booleanType()).optional(),
12776
12856
  autoincrement: makePatched(booleanType()).optional()
@@ -13103,6 +13183,7 @@ var applySnapshotsDiff = async (json1, json2, dialect3, schemasResolver, tablesR
13103
13183
  jsonStatements.push(...jsonDropTables);
13104
13184
  jsonStatements.push(...jsonRenameTables);
13105
13185
  jsonStatements.push(...jsonRenameColumnsStatements);
13186
+ jsonStatements.push(...jsonDeletedCompositePKs);
13106
13187
  jsonStatements.push(...jsonTableAlternations.alterColumns);
13107
13188
  jsonStatements.push(...jsonTableAlternations.createColumns);
13108
13189
  jsonStatements.push(...jsonAlterReferencesForAlteredTables);
@@ -13112,7 +13193,6 @@ var applySnapshotsDiff = async (json1, json2, dialect3, schemasResolver, tablesR
13112
13193
  jsonStatements.push(...jsonDropIndexesForAllAlteredTables);
13113
13194
  jsonStatements.push(...jsonCreateIndexesForCreatedTables);
13114
13195
  jsonStatements.push(...jsonCreateIndexesForAllAlteredTables);
13115
- jsonStatements.push(...jsonDeletedCompositePKs);
13116
13196
  jsonStatements.push(...jsonAddedCompositePKs);
13117
13197
  jsonStatements.push(...jsonAlteredCompositePKs);
13118
13198
  jsonStatements.push(...jsonSetTableSchemas);