drizzle-kit 0.22.7-a16c9a1 → 0.22.7-c827f86

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. package/bin.cjs +47 -33
  2. package/package.json +1 -1
  3. package/payload.js +33 -18
  4. package/payload.mjs +33 -18
package/bin.cjs CHANGED
@@ -22391,13 +22391,19 @@ function mapSqlToSqliteType(sqlType) {
22391
22391
  }
22392
22392
  function extractGeneratedColumns(input) {
22393
22393
  const columns = {};
22394
- const lines = input.split("\n");
22394
+ const lines = input.split(/,\s*(?![^()]*\))/);
22395
22395
  for (const line of lines) {
22396
22396
  if (line.includes("GENERATED ALWAYS AS")) {
22397
22397
  const parts = line.trim().split(/\s+/);
22398
- const columnName = parts[0].slice(1, parts[0].length - 1);
22398
+ const columnName = parts[0].replace(/[`'"]/g, "");
22399
22399
  const expression = line.substring(line.indexOf("("), line.indexOf(")") + 1).trim();
22400
- const type = parts[parts.length - 1].replace(/(^,)|(,$)/g, "").toLowerCase();
22400
+ const typeIndex = parts.findIndex(
22401
+ (part) => part.match(/(stored|virtual)/i)
22402
+ );
22403
+ let type = "virtual";
22404
+ if (typeIndex !== -1) {
22405
+ type = parts[typeIndex].replace(/[^a-z]/gi, "").toLowerCase();
22406
+ }
22401
22407
  columns[columnName] = {
22402
22408
  columnName,
22403
22409
  expression,
@@ -22445,7 +22451,7 @@ var init_sqliteSerializer = __esm({
22445
22451
  notNull,
22446
22452
  autoincrement: (0, import_drizzle_orm7.is)(column7, import_sqlite_core2.SQLiteBaseInteger) ? column7.autoIncrement : false,
22447
22453
  generated: generated ? {
22448
- as: (0, import_drizzle_orm7.is)(generated.as, import_drizzle_orm7.SQL) ? dialect6.sqlToQuery(generated.as, "indexes").sql : typeof generated.as === "function" ? dialect6.sqlToQuery(generated.as(), "indexes").sql : generated.as,
22454
+ as: (0, import_drizzle_orm7.is)(generated.as, import_drizzle_orm7.SQL) ? `(${dialect6.sqlToQuery(generated.as, "indexes").sql})` : typeof generated.as === "function" ? `(${dialect6.sqlToQuery(generated.as(), "indexes").sql})` : `(${generated.as})`,
22449
22455
  type: generated.mode ?? "virtual"
22450
22456
  } : void 0
22451
22457
  };
@@ -23202,7 +23208,7 @@ var init_sqlgenerator = __esm({
23202
23208
  const notNullStatement = column7.notNull ? " NOT NULL" : "";
23203
23209
  const defaultStatement = column7.default !== void 0 ? ` DEFAULT ${column7.default}` : "";
23204
23210
  const autoincrementStatement = column7.autoincrement ? " AUTOINCREMENT" : "";
23205
- const generatedStatement = column7.generated ? ` GENERATED ALWAYS AS (${column7.generated.as}) ${column7.generated.type.toUpperCase()}` : "";
23211
+ const generatedStatement = column7.generated ? ` GENERATED ALWAYS AS ${column7.generated.as} ${column7.generated.type.toUpperCase()}` : "";
23206
23212
  statement += " ";
23207
23213
  statement += `\`${column7.name}\` ${column7.type}${primaryKeyStatement}${autoincrementStatement}${defaultStatement}${notNullStatement}${generatedStatement}`;
23208
23214
  statement += i2 === columns.length - 1 ? "" : ",\n";
@@ -23277,8 +23283,6 @@ var init_sqlgenerator = __esm({
23277
23283
  const tableNameWithSchema = schema5 ? `"${schema5}"."${tableName}"` : `"${tableName}"`;
23278
23284
  const unsquashedIdentity = PgSquasher.unsquashIdentity(identity);
23279
23285
  const unsquashedOldIdentity = PgSquasher.unsquashIdentity(oldIdentity);
23280
- const identityWithSchema = schema5 ? `"${schema5}"."${unsquashedIdentity == null ? void 0 : unsquashedIdentity.name}"` : `"${unsquashedIdentity == null ? void 0 : unsquashedIdentity.name}"`;
23281
- const oldIdentityWithSchema = schema5 ? `"${schema5}"."${unsquashedOldIdentity == null ? void 0 : unsquashedOldIdentity.name}"` : `"${unsquashedOldIdentity == null ? void 0 : unsquashedOldIdentity.name}"`;
23282
23286
  const statementsToReturn = [];
23283
23287
  if (unsquashedOldIdentity.type !== unsquashedIdentity.type) {
23284
23288
  statementsToReturn.push(
@@ -23587,14 +23591,18 @@ var init_sqlgenerator = __esm({
23587
23591
  }
23588
23592
  convert(statement) {
23589
23593
  const { tableName, column: column7, schema: schema5 } = statement;
23590
- const { name, type, notNull, generated } = column7;
23594
+ const { name, type, notNull, generated, primaryKey, identity } = column7;
23595
+ const primaryKeyStatement = primaryKey ? " PRIMARY KEY" : "";
23591
23596
  const tableNameWithSchema = schema5 ? `"${schema5}"."${tableName}"` : `"${tableName}"`;
23592
23597
  const defaultStatement = `${column7.default !== void 0 ? ` DEFAULT ${column7.default}` : ""}`;
23593
23598
  const schemaPrefix = column7.typeSchema && column7.typeSchema !== "public" ? `"${column7.typeSchema}".` : "";
23594
23599
  const fixedType = isPgNativeType(column7.type) ? column7.type : `${schemaPrefix}"${column7.type}"`;
23595
23600
  const notNullStatement = `${notNull ? " NOT NULL" : ""}`;
23601
+ const unsquashedIdentity = identity ? PgSquasher.unsquashIdentity(identity) : void 0;
23602
+ const identityWithSchema = schema5 ? `"${schema5}"."${unsquashedIdentity == null ? void 0 : unsquashedIdentity.name}"` : `"${unsquashedIdentity == null ? void 0 : unsquashedIdentity.name}"`;
23603
+ const identityStatement = unsquashedIdentity ? ` GENERATED ${unsquashedIdentity.type === "always" ? "ALWAYS" : "BY DEFAULT"} AS IDENTITY (sequence name ${identityWithSchema}${unsquashedIdentity.increment ? ` INCREMENT BY ${unsquashedIdentity.increment}` : ""}${unsquashedIdentity.minValue ? ` MINVALUE ${unsquashedIdentity.minValue}` : ""}${unsquashedIdentity.maxValue ? ` MAXVALUE ${unsquashedIdentity.maxValue}` : ""}${unsquashedIdentity.startWith ? ` START WITH ${unsquashedIdentity.startWith}` : ""}${unsquashedIdentity.cache ? ` CACHE ${unsquashedIdentity.cache}` : ""}${unsquashedIdentity.cycle ? ` CYCLE` : ""})` : "";
23596
23604
  const generatedStatement = ` GENERATED ALWAYS AS (${generated == null ? void 0 : generated.as}) STORED`;
23597
- return `ALTER TABLE ${tableNameWithSchema} ADD COLUMN "${name}" ${fixedType}${defaultStatement}${notNullStatement}${generated ? generatedStatement : ""};`;
23605
+ return `ALTER TABLE ${tableNameWithSchema} ADD COLUMN "${name}" ${fixedType}${primaryKeyStatement}${defaultStatement}${notNullStatement}${generated ? generatedStatement : ""}${identityStatement};`;
23598
23606
  }
23599
23607
  };
23600
23608
  MySqlAlterTableAddColumnConvertor = class extends Convertor {
@@ -23633,7 +23641,7 @@ var init_sqlgenerator = __esm({
23633
23641
  const primaryKeyStatement = `${primaryKey ? " PRIMARY KEY" : ""}`;
23634
23642
  const referenceAsObject = referenceData ? SQLiteSquasher.unsquashFK(referenceData) : void 0;
23635
23643
  const referenceStatement = `${referenceAsObject ? ` REFERENCES ${referenceAsObject.tableTo}(${referenceAsObject.columnsTo})` : ""}`;
23636
- const generatedStatement = generated ? ` GENERATED ALWAYS AS (${generated.as}) ${generated.type.toUpperCase()}` : "";
23644
+ const generatedStatement = generated ? ` GENERATED ALWAYS AS ${generated.as} ${generated.type.toUpperCase()}` : "";
23637
23645
  return `ALTER TABLE \`${tableName}\` ADD \`${name}\` ${type}${primaryKeyStatement}${defaultStatement}${notNullStatement}${generatedStatement}${referenceStatement};`;
23638
23646
  }
23639
23647
  };
@@ -23922,8 +23930,8 @@ var init_sqlgenerator = __esm({
23922
23930
  columnPk,
23923
23931
  columnGenerated
23924
23932
  } = statement;
23925
- const tableNameWithSchema = schema5 ? `"${schema5}"."${tableName}"` : `"${tableName}"`;
23926
- const addColumnStatement = new PgAlterTableAddColumnConvertor().convert({
23933
+ const tableNameWithSchema = schema5 ? `\`${schema5}\`.\`${tableName}\`` : `\`${tableName}\``;
23934
+ const addColumnStatement = new MySqlAlterTableAddColumnConvertor().convert({
23927
23935
  schema: schema5,
23928
23936
  tableName,
23929
23937
  column: {
@@ -23939,7 +23947,7 @@ var init_sqlgenerator = __esm({
23939
23947
  type: "alter_table_add_column"
23940
23948
  });
23941
23949
  return [
23942
- `ALTER TABLE ${tableNameWithSchema} drop column "${columnName}";`,
23950
+ `ALTER TABLE ${tableNameWithSchema} drop column \`${columnName}\`;`,
23943
23951
  addColumnStatement
23944
23952
  ];
23945
23953
  }
@@ -29549,6 +29557,13 @@ var init_snapshotsDiffer = __esm({
29549
29557
  return false;
29550
29558
  }
29551
29559
  }
29560
+ if (st.type === "alter_table_alter_column_set_notnull") {
29561
+ if (jsonStatements.find(
29562
+ (it) => it.type === "alter_table_alter_column_set_identity" && it.tableName === st.tableName && it.schema === st.schema
29563
+ )) {
29564
+ return false;
29565
+ }
29566
+ }
29552
29567
  return true;
29553
29568
  });
29554
29569
  const sqlStatements = fromJson(filteredJsonStatements, "postgresql");
@@ -122357,14 +122372,14 @@ var init_sqlitePushUtils = __esm({
122357
122372
  }
122358
122373
  tablesContext[newTableName] = _moveDataStatements(
122359
122374
  statement.tableName,
122360
- json2,
122375
+ json1,
122361
122376
  true
122362
122377
  );
122363
122378
  } else {
122364
122379
  if (typeof tablesContext[newTableName] === "undefined") {
122365
122380
  tablesContext[newTableName] = _moveDataStatements(
122366
122381
  statement.tableName,
122367
- json2
122382
+ json1
122368
122383
  );
122369
122384
  }
122370
122385
  }
@@ -122383,7 +122398,7 @@ var init_sqlitePushUtils = __esm({
122383
122398
  const uniqueTableRefs = [...new Set(tablesReferncingCurrent)];
122384
122399
  for (const table4 of uniqueTableRefs) {
122385
122400
  if (typeof tablesContext[table4] === "undefined") {
122386
- tablesContext[table4] = [..._moveDataStatements(table4, json2)];
122401
+ tablesContext[table4] = [..._moveDataStatements(table4, json1)];
122387
122402
  }
122388
122403
  }
122389
122404
  }
@@ -122404,9 +122419,9 @@ var init_sqlitePushUtils = __esm({
122404
122419
  );
122405
122420
  }
122406
122421
  } else {
122407
- const stmnt = fromJson([statement], "sqlite")[0];
122422
+ const stmnt = fromJson([statement], "sqlite");
122408
122423
  if (typeof stmnt !== "undefined") {
122409
- statementsToExecute.push(stmnt);
122424
+ statementsToExecute.push(...stmnt);
122410
122425
  }
122411
122426
  }
122412
122427
  }
@@ -124236,25 +124251,24 @@ var init_push = __esm({
124236
124251
  process.exit(0);
124237
124252
  }
124238
124253
  }
124239
- if (!("driver" in credentials2)) {
124240
- await db2.query("begin");
124241
- try {
124242
- for (const dStmnt of statementsToExecute) {
124243
- await db2.query(dStmnt);
124244
- }
124245
- await db2.query("commit");
124246
- } catch (e2) {
124247
- await db2.query("rollback");
124248
- }
124249
- } else if (credentials2.driver === "turso") {
124250
- await db2.batch(statementsToExecute.map((it) => ({ query: it })));
124251
- }
124252
124254
  if (statementsToExecute.length === 0) {
124253
124255
  (0, import_hanji11.render)(`
124254
124256
  [${source_default.blue("i")}] No changes detected`);
124255
124257
  } else {
124256
- for (const dStmnt of statementsToExecute) {
124257
- await db2.run(dStmnt);
124258
+ if (!("driver" in credentials2)) {
124259
+ await db2.query("begin");
124260
+ try {
124261
+ for (const dStmnt of statementsToExecute) {
124262
+ await db2.query(dStmnt);
124263
+ }
124264
+ await db2.query("commit");
124265
+ } catch (e2) {
124266
+ console.error(e2);
124267
+ await db2.query("rollback");
124268
+ process.exit(1);
124269
+ }
124270
+ } else if (credentials2.driver === "turso") {
124271
+ await db2.batch(statementsToExecute.map((it) => ({ query: it })));
124258
124272
  }
124259
124273
  (0, import_hanji11.render)(`[${source_default.green("\u2713")}] Changes applied`);
124260
124274
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "drizzle-kit",
3
- "version": "0.22.7-a16c9a1",
3
+ "version": "0.22.7-c827f86",
4
4
  "repository": "https://github.com/drizzle-team/drizzle-kit-mirror",
5
5
  "author": "Drizzle Team",
6
6
  "license": "MIT",
package/payload.js CHANGED
@@ -23102,6 +23102,13 @@ var init_snapshotsDiffer = __esm({
23102
23102
  return false;
23103
23103
  }
23104
23104
  }
23105
+ if (st.type === "alter_table_alter_column_set_notnull") {
23106
+ if (jsonStatements.find(
23107
+ (it) => it.type === "alter_table_alter_column_set_identity" && it.tableName === st.tableName && it.schema === st.schema
23108
+ )) {
23109
+ return false;
23110
+ }
23111
+ }
23105
23112
  return true;
23106
23113
  });
23107
23114
  const sqlStatements = fromJson(filteredJsonStatements, "postgresql");
@@ -24156,7 +24163,7 @@ var init_sqlgenerator = __esm({
24156
24163
  const notNullStatement = column4.notNull ? " NOT NULL" : "";
24157
24164
  const defaultStatement = column4.default !== void 0 ? ` DEFAULT ${column4.default}` : "";
24158
24165
  const autoincrementStatement = column4.autoincrement ? " AUTOINCREMENT" : "";
24159
- const generatedStatement = column4.generated ? ` GENERATED ALWAYS AS (${column4.generated.as}) ${column4.generated.type.toUpperCase()}` : "";
24166
+ const generatedStatement = column4.generated ? ` GENERATED ALWAYS AS ${column4.generated.as} ${column4.generated.type.toUpperCase()}` : "";
24160
24167
  statement += " ";
24161
24168
  statement += `\`${column4.name}\` ${column4.type}${primaryKeyStatement}${autoincrementStatement}${defaultStatement}${notNullStatement}${generatedStatement}`;
24162
24169
  statement += i === columns.length - 1 ? "" : ",\n";
@@ -24231,8 +24238,6 @@ var init_sqlgenerator = __esm({
24231
24238
  const tableNameWithSchema = schema4 ? `"${schema4}"."${tableName}"` : `"${tableName}"`;
24232
24239
  const unsquashedIdentity = PgSquasher.unsquashIdentity(identity);
24233
24240
  const unsquashedOldIdentity = PgSquasher.unsquashIdentity(oldIdentity);
24234
- const identityWithSchema = schema4 ? `"${schema4}"."${unsquashedIdentity?.name}"` : `"${unsquashedIdentity?.name}"`;
24235
- const oldIdentityWithSchema = schema4 ? `"${schema4}"."${unsquashedOldIdentity?.name}"` : `"${unsquashedOldIdentity?.name}"`;
24236
24241
  const statementsToReturn = [];
24237
24242
  if (unsquashedOldIdentity.type !== unsquashedIdentity.type) {
24238
24243
  statementsToReturn.push(
@@ -24541,14 +24546,18 @@ var init_sqlgenerator = __esm({
24541
24546
  }
24542
24547
  convert(statement) {
24543
24548
  const { tableName, column: column4, schema: schema4 } = statement;
24544
- const { name: name2, type, notNull, generated } = column4;
24549
+ const { name: name2, type, notNull, generated, primaryKey, identity } = column4;
24550
+ const primaryKeyStatement = primaryKey ? " PRIMARY KEY" : "";
24545
24551
  const tableNameWithSchema = schema4 ? `"${schema4}"."${tableName}"` : `"${tableName}"`;
24546
24552
  const defaultStatement = `${column4.default !== void 0 ? ` DEFAULT ${column4.default}` : ""}`;
24547
24553
  const schemaPrefix = column4.typeSchema && column4.typeSchema !== "public" ? `"${column4.typeSchema}".` : "";
24548
24554
  const fixedType = isPgNativeType(column4.type) ? column4.type : `${schemaPrefix}"${column4.type}"`;
24549
24555
  const notNullStatement = `${notNull ? " NOT NULL" : ""}`;
24556
+ const unsquashedIdentity = identity ? PgSquasher.unsquashIdentity(identity) : void 0;
24557
+ const identityWithSchema = schema4 ? `"${schema4}"."${unsquashedIdentity?.name}"` : `"${unsquashedIdentity?.name}"`;
24558
+ const identityStatement = unsquashedIdentity ? ` GENERATED ${unsquashedIdentity.type === "always" ? "ALWAYS" : "BY DEFAULT"} AS IDENTITY (sequence name ${identityWithSchema}${unsquashedIdentity.increment ? ` INCREMENT BY ${unsquashedIdentity.increment}` : ""}${unsquashedIdentity.minValue ? ` MINVALUE ${unsquashedIdentity.minValue}` : ""}${unsquashedIdentity.maxValue ? ` MAXVALUE ${unsquashedIdentity.maxValue}` : ""}${unsquashedIdentity.startWith ? ` START WITH ${unsquashedIdentity.startWith}` : ""}${unsquashedIdentity.cache ? ` CACHE ${unsquashedIdentity.cache}` : ""}${unsquashedIdentity.cycle ? ` CYCLE` : ""})` : "";
24550
24559
  const generatedStatement = ` GENERATED ALWAYS AS (${generated?.as}) STORED`;
24551
- return `ALTER TABLE ${tableNameWithSchema} ADD COLUMN "${name2}" ${fixedType}${defaultStatement}${notNullStatement}${generated ? generatedStatement : ""};`;
24560
+ return `ALTER TABLE ${tableNameWithSchema} ADD COLUMN "${name2}" ${fixedType}${primaryKeyStatement}${defaultStatement}${notNullStatement}${generated ? generatedStatement : ""}${identityStatement};`;
24552
24561
  }
24553
24562
  };
24554
24563
  MySqlAlterTableAddColumnConvertor = class extends Convertor {
@@ -24587,7 +24596,7 @@ var init_sqlgenerator = __esm({
24587
24596
  const primaryKeyStatement = `${primaryKey ? " PRIMARY KEY" : ""}`;
24588
24597
  const referenceAsObject = referenceData ? SQLiteSquasher.unsquashFK(referenceData) : void 0;
24589
24598
  const referenceStatement = `${referenceAsObject ? ` REFERENCES ${referenceAsObject.tableTo}(${referenceAsObject.columnsTo})` : ""}`;
24590
- const generatedStatement = generated ? ` GENERATED ALWAYS AS (${generated.as}) ${generated.type.toUpperCase()}` : "";
24599
+ const generatedStatement = generated ? ` GENERATED ALWAYS AS ${generated.as} ${generated.type.toUpperCase()}` : "";
24591
24600
  return `ALTER TABLE \`${tableName}\` ADD \`${name2}\` ${type}${primaryKeyStatement}${defaultStatement}${notNullStatement}${generatedStatement}${referenceStatement};`;
24592
24601
  }
24593
24602
  };
@@ -24876,8 +24885,8 @@ var init_sqlgenerator = __esm({
24876
24885
  columnPk,
24877
24886
  columnGenerated
24878
24887
  } = statement;
24879
- const tableNameWithSchema = schema4 ? `"${schema4}"."${tableName}"` : `"${tableName}"`;
24880
- const addColumnStatement = new PgAlterTableAddColumnConvertor().convert({
24888
+ const tableNameWithSchema = schema4 ? `\`${schema4}\`.\`${tableName}\`` : `\`${tableName}\``;
24889
+ const addColumnStatement = new MySqlAlterTableAddColumnConvertor().convert({
24881
24890
  schema: schema4,
24882
24891
  tableName,
24883
24892
  column: {
@@ -24893,7 +24902,7 @@ var init_sqlgenerator = __esm({
24893
24902
  type: "alter_table_add_column"
24894
24903
  });
24895
24904
  return [
24896
- `ALTER TABLE ${tableNameWithSchema} drop column "${columnName}";`,
24905
+ `ALTER TABLE ${tableNameWithSchema} drop column \`${columnName}\`;`,
24897
24906
  addColumnStatement
24898
24907
  ];
24899
24908
  }
@@ -29070,13 +29079,19 @@ function mapSqlToSqliteType(sqlType) {
29070
29079
  }
29071
29080
  function extractGeneratedColumns(input) {
29072
29081
  const columns = {};
29073
- const lines = input.split("\n");
29082
+ const lines = input.split(/,\s*(?![^()]*\))/);
29074
29083
  for (const line of lines) {
29075
29084
  if (line.includes("GENERATED ALWAYS AS")) {
29076
29085
  const parts = line.trim().split(/\s+/);
29077
- const columnName = parts[0].slice(1, parts[0].length - 1);
29086
+ const columnName = parts[0].replace(/[`'"]/g, "");
29078
29087
  const expression = line.substring(line.indexOf("("), line.indexOf(")") + 1).trim();
29079
- const type = parts[parts.length - 1].replace(/(^,)|(,$)/g, "").toLowerCase();
29088
+ const typeIndex = parts.findIndex(
29089
+ (part) => part.match(/(stored|virtual)/i)
29090
+ );
29091
+ let type = "virtual";
29092
+ if (typeIndex !== -1) {
29093
+ type = parts[typeIndex].replace(/[^a-z]/gi, "").toLowerCase();
29094
+ }
29080
29095
  columns[columnName] = {
29081
29096
  columnName,
29082
29097
  expression,
@@ -29124,7 +29139,7 @@ var init_sqliteSerializer = __esm({
29124
29139
  notNull,
29125
29140
  autoincrement: is(column4, SQLiteBaseInteger) ? column4.autoIncrement : false,
29126
29141
  generated: generated ? {
29127
- as: is(generated.as, SQL) ? dialect5.sqlToQuery(generated.as, "indexes").sql : typeof generated.as === "function" ? dialect5.sqlToQuery(generated.as(), "indexes").sql : generated.as,
29142
+ as: is(generated.as, SQL) ? `(${dialect5.sqlToQuery(generated.as, "indexes").sql})` : typeof generated.as === "function" ? `(${dialect5.sqlToQuery(generated.as(), "indexes").sql})` : `(${generated.as})`,
29128
29143
  type: generated.mode ?? "virtual"
29129
29144
  } : void 0
29130
29145
  };
@@ -35048,14 +35063,14 @@ var logSuggestionsAndReturn = async (connection, statements, json1, json2, meta)
35048
35063
  }
35049
35064
  tablesContext[newTableName] = _moveDataStatements(
35050
35065
  statement.tableName,
35051
- json2,
35066
+ json1,
35052
35067
  true
35053
35068
  );
35054
35069
  } else {
35055
35070
  if (typeof tablesContext[newTableName] === "undefined") {
35056
35071
  tablesContext[newTableName] = _moveDataStatements(
35057
35072
  statement.tableName,
35058
- json2
35073
+ json1
35059
35074
  );
35060
35075
  }
35061
35076
  }
@@ -35074,7 +35089,7 @@ var logSuggestionsAndReturn = async (connection, statements, json1, json2, meta)
35074
35089
  const uniqueTableRefs = [...new Set(tablesReferncingCurrent)];
35075
35090
  for (const table4 of uniqueTableRefs) {
35076
35091
  if (typeof tablesContext[table4] === "undefined") {
35077
- tablesContext[table4] = [..._moveDataStatements(table4, json2)];
35092
+ tablesContext[table4] = [..._moveDataStatements(table4, json1)];
35078
35093
  }
35079
35094
  }
35080
35095
  }
@@ -35095,9 +35110,9 @@ var logSuggestionsAndReturn = async (connection, statements, json1, json2, meta)
35095
35110
  );
35096
35111
  }
35097
35112
  } else {
35098
- const stmnt = fromJson([statement], "sqlite")[0];
35113
+ const stmnt = fromJson([statement], "sqlite");
35099
35114
  if (typeof stmnt !== "undefined") {
35100
- statementsToExecute.push(stmnt);
35115
+ statementsToExecute.push(...stmnt);
35101
35116
  }
35102
35117
  }
35103
35118
  }
package/payload.mjs CHANGED
@@ -23107,6 +23107,13 @@ var init_snapshotsDiffer = __esm({
23107
23107
  return false;
23108
23108
  }
23109
23109
  }
23110
+ if (st.type === "alter_table_alter_column_set_notnull") {
23111
+ if (jsonStatements.find(
23112
+ (it) => it.type === "alter_table_alter_column_set_identity" && it.tableName === st.tableName && it.schema === st.schema
23113
+ )) {
23114
+ return false;
23115
+ }
23116
+ }
23110
23117
  return true;
23111
23118
  });
23112
23119
  const sqlStatements = fromJson(filteredJsonStatements, "postgresql");
@@ -24161,7 +24168,7 @@ var init_sqlgenerator = __esm({
24161
24168
  const notNullStatement = column4.notNull ? " NOT NULL" : "";
24162
24169
  const defaultStatement = column4.default !== void 0 ? ` DEFAULT ${column4.default}` : "";
24163
24170
  const autoincrementStatement = column4.autoincrement ? " AUTOINCREMENT" : "";
24164
- const generatedStatement = column4.generated ? ` GENERATED ALWAYS AS (${column4.generated.as}) ${column4.generated.type.toUpperCase()}` : "";
24171
+ const generatedStatement = column4.generated ? ` GENERATED ALWAYS AS ${column4.generated.as} ${column4.generated.type.toUpperCase()}` : "";
24165
24172
  statement += " ";
24166
24173
  statement += `\`${column4.name}\` ${column4.type}${primaryKeyStatement}${autoincrementStatement}${defaultStatement}${notNullStatement}${generatedStatement}`;
24167
24174
  statement += i === columns.length - 1 ? "" : ",\n";
@@ -24236,8 +24243,6 @@ var init_sqlgenerator = __esm({
24236
24243
  const tableNameWithSchema = schema4 ? `"${schema4}"."${tableName}"` : `"${tableName}"`;
24237
24244
  const unsquashedIdentity = PgSquasher.unsquashIdentity(identity);
24238
24245
  const unsquashedOldIdentity = PgSquasher.unsquashIdentity(oldIdentity);
24239
- const identityWithSchema = schema4 ? `"${schema4}"."${unsquashedIdentity?.name}"` : `"${unsquashedIdentity?.name}"`;
24240
- const oldIdentityWithSchema = schema4 ? `"${schema4}"."${unsquashedOldIdentity?.name}"` : `"${unsquashedOldIdentity?.name}"`;
24241
24246
  const statementsToReturn = [];
24242
24247
  if (unsquashedOldIdentity.type !== unsquashedIdentity.type) {
24243
24248
  statementsToReturn.push(
@@ -24546,14 +24551,18 @@ var init_sqlgenerator = __esm({
24546
24551
  }
24547
24552
  convert(statement) {
24548
24553
  const { tableName, column: column4, schema: schema4 } = statement;
24549
- const { name: name2, type, notNull, generated } = column4;
24554
+ const { name: name2, type, notNull, generated, primaryKey, identity } = column4;
24555
+ const primaryKeyStatement = primaryKey ? " PRIMARY KEY" : "";
24550
24556
  const tableNameWithSchema = schema4 ? `"${schema4}"."${tableName}"` : `"${tableName}"`;
24551
24557
  const defaultStatement = `${column4.default !== void 0 ? ` DEFAULT ${column4.default}` : ""}`;
24552
24558
  const schemaPrefix = column4.typeSchema && column4.typeSchema !== "public" ? `"${column4.typeSchema}".` : "";
24553
24559
  const fixedType = isPgNativeType(column4.type) ? column4.type : `${schemaPrefix}"${column4.type}"`;
24554
24560
  const notNullStatement = `${notNull ? " NOT NULL" : ""}`;
24561
+ const unsquashedIdentity = identity ? PgSquasher.unsquashIdentity(identity) : void 0;
24562
+ const identityWithSchema = schema4 ? `"${schema4}"."${unsquashedIdentity?.name}"` : `"${unsquashedIdentity?.name}"`;
24563
+ const identityStatement = unsquashedIdentity ? ` GENERATED ${unsquashedIdentity.type === "always" ? "ALWAYS" : "BY DEFAULT"} AS IDENTITY (sequence name ${identityWithSchema}${unsquashedIdentity.increment ? ` INCREMENT BY ${unsquashedIdentity.increment}` : ""}${unsquashedIdentity.minValue ? ` MINVALUE ${unsquashedIdentity.minValue}` : ""}${unsquashedIdentity.maxValue ? ` MAXVALUE ${unsquashedIdentity.maxValue}` : ""}${unsquashedIdentity.startWith ? ` START WITH ${unsquashedIdentity.startWith}` : ""}${unsquashedIdentity.cache ? ` CACHE ${unsquashedIdentity.cache}` : ""}${unsquashedIdentity.cycle ? ` CYCLE` : ""})` : "";
24555
24564
  const generatedStatement = ` GENERATED ALWAYS AS (${generated?.as}) STORED`;
24556
- return `ALTER TABLE ${tableNameWithSchema} ADD COLUMN "${name2}" ${fixedType}${defaultStatement}${notNullStatement}${generated ? generatedStatement : ""};`;
24565
+ return `ALTER TABLE ${tableNameWithSchema} ADD COLUMN "${name2}" ${fixedType}${primaryKeyStatement}${defaultStatement}${notNullStatement}${generated ? generatedStatement : ""}${identityStatement};`;
24557
24566
  }
24558
24567
  };
24559
24568
  MySqlAlterTableAddColumnConvertor = class extends Convertor {
@@ -24592,7 +24601,7 @@ var init_sqlgenerator = __esm({
24592
24601
  const primaryKeyStatement = `${primaryKey ? " PRIMARY KEY" : ""}`;
24593
24602
  const referenceAsObject = referenceData ? SQLiteSquasher.unsquashFK(referenceData) : void 0;
24594
24603
  const referenceStatement = `${referenceAsObject ? ` REFERENCES ${referenceAsObject.tableTo}(${referenceAsObject.columnsTo})` : ""}`;
24595
- const generatedStatement = generated ? ` GENERATED ALWAYS AS (${generated.as}) ${generated.type.toUpperCase()}` : "";
24604
+ const generatedStatement = generated ? ` GENERATED ALWAYS AS ${generated.as} ${generated.type.toUpperCase()}` : "";
24596
24605
  return `ALTER TABLE \`${tableName}\` ADD \`${name2}\` ${type}${primaryKeyStatement}${defaultStatement}${notNullStatement}${generatedStatement}${referenceStatement};`;
24597
24606
  }
24598
24607
  };
@@ -24881,8 +24890,8 @@ var init_sqlgenerator = __esm({
24881
24890
  columnPk,
24882
24891
  columnGenerated
24883
24892
  } = statement;
24884
- const tableNameWithSchema = schema4 ? `"${schema4}"."${tableName}"` : `"${tableName}"`;
24885
- const addColumnStatement = new PgAlterTableAddColumnConvertor().convert({
24893
+ const tableNameWithSchema = schema4 ? `\`${schema4}\`.\`${tableName}\`` : `\`${tableName}\``;
24894
+ const addColumnStatement = new MySqlAlterTableAddColumnConvertor().convert({
24886
24895
  schema: schema4,
24887
24896
  tableName,
24888
24897
  column: {
@@ -24898,7 +24907,7 @@ var init_sqlgenerator = __esm({
24898
24907
  type: "alter_table_add_column"
24899
24908
  });
24900
24909
  return [
24901
- `ALTER TABLE ${tableNameWithSchema} drop column "${columnName}";`,
24910
+ `ALTER TABLE ${tableNameWithSchema} drop column \`${columnName}\`;`,
24902
24911
  addColumnStatement
24903
24912
  ];
24904
24913
  }
@@ -29075,13 +29084,19 @@ function mapSqlToSqliteType(sqlType) {
29075
29084
  }
29076
29085
  function extractGeneratedColumns(input) {
29077
29086
  const columns = {};
29078
- const lines = input.split("\n");
29087
+ const lines = input.split(/,\s*(?![^()]*\))/);
29079
29088
  for (const line of lines) {
29080
29089
  if (line.includes("GENERATED ALWAYS AS")) {
29081
29090
  const parts = line.trim().split(/\s+/);
29082
- const columnName = parts[0].slice(1, parts[0].length - 1);
29091
+ const columnName = parts[0].replace(/[`'"]/g, "");
29083
29092
  const expression = line.substring(line.indexOf("("), line.indexOf(")") + 1).trim();
29084
- const type = parts[parts.length - 1].replace(/(^,)|(,$)/g, "").toLowerCase();
29093
+ const typeIndex = parts.findIndex(
29094
+ (part) => part.match(/(stored|virtual)/i)
29095
+ );
29096
+ let type = "virtual";
29097
+ if (typeIndex !== -1) {
29098
+ type = parts[typeIndex].replace(/[^a-z]/gi, "").toLowerCase();
29099
+ }
29085
29100
  columns[columnName] = {
29086
29101
  columnName,
29087
29102
  expression,
@@ -29129,7 +29144,7 @@ var init_sqliteSerializer = __esm({
29129
29144
  notNull,
29130
29145
  autoincrement: is(column4, SQLiteBaseInteger) ? column4.autoIncrement : false,
29131
29146
  generated: generated ? {
29132
- as: is(generated.as, SQL) ? dialect5.sqlToQuery(generated.as, "indexes").sql : typeof generated.as === "function" ? dialect5.sqlToQuery(generated.as(), "indexes").sql : generated.as,
29147
+ as: is(generated.as, SQL) ? `(${dialect5.sqlToQuery(generated.as, "indexes").sql})` : typeof generated.as === "function" ? `(${dialect5.sqlToQuery(generated.as(), "indexes").sql})` : `(${generated.as})`,
29133
29148
  type: generated.mode ?? "virtual"
29134
29149
  } : void 0
29135
29150
  };
@@ -35039,14 +35054,14 @@ var logSuggestionsAndReturn = async (connection, statements, json1, json2, meta)
35039
35054
  }
35040
35055
  tablesContext[newTableName] = _moveDataStatements(
35041
35056
  statement.tableName,
35042
- json2,
35057
+ json1,
35043
35058
  true
35044
35059
  );
35045
35060
  } else {
35046
35061
  if (typeof tablesContext[newTableName] === "undefined") {
35047
35062
  tablesContext[newTableName] = _moveDataStatements(
35048
35063
  statement.tableName,
35049
- json2
35064
+ json1
35050
35065
  );
35051
35066
  }
35052
35067
  }
@@ -35065,7 +35080,7 @@ var logSuggestionsAndReturn = async (connection, statements, json1, json2, meta)
35065
35080
  const uniqueTableRefs = [...new Set(tablesReferncingCurrent)];
35066
35081
  for (const table4 of uniqueTableRefs) {
35067
35082
  if (typeof tablesContext[table4] === "undefined") {
35068
- tablesContext[table4] = [..._moveDataStatements(table4, json2)];
35083
+ tablesContext[table4] = [..._moveDataStatements(table4, json1)];
35069
35084
  }
35070
35085
  }
35071
35086
  }
@@ -35086,9 +35101,9 @@ var logSuggestionsAndReturn = async (connection, statements, json1, json2, meta)
35086
35101
  );
35087
35102
  }
35088
35103
  } else {
35089
- const stmnt = fromJson([statement], "sqlite")[0];
35104
+ const stmnt = fromJson([statement], "sqlite");
35090
35105
  if (typeof stmnt !== "undefined") {
35091
- statementsToExecute.push(stmnt);
35106
+ statementsToExecute.push(...stmnt);
35092
35107
  }
35093
35108
  }
35094
35109
  }