drizzle-kit 0.30.2 → 0.30.3-2c67783

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/api.js +644 -342
  2. package/api.mjs +644 -342
  3. package/bin.cjs +2495 -336
  4. package/package.json +1 -1
package/api.js CHANGED
@@ -12121,7 +12121,7 @@ function fromJson(statements, dialect6, action, json22) {
12121
12121
  }).filter((it) => it !== "");
12122
12122
  return result;
12123
12123
  }
12124
- var parseType, Convertor, PgCreateRoleConvertor, PgDropRoleConvertor, PgRenameRoleConvertor, PgAlterRoleConvertor, PgCreatePolicyConvertor, PgDropPolicyConvertor, PgRenamePolicyConvertor, PgAlterPolicyConvertor, PgCreateIndPolicyConvertor, PgDropIndPolicyConvertor, PgRenameIndPolicyConvertor, PgAlterIndPolicyConvertor, PgEnableRlsConvertor, PgDisableRlsConvertor, PgCreateTableConvertor, MySqlCreateTableConvertor, SingleStoreCreateTableConvertor, SQLiteCreateTableConvertor, PgCreateViewConvertor, MySqlCreateViewConvertor, SqliteCreateViewConvertor, PgDropViewConvertor, MySqlDropViewConvertor, SqliteDropViewConvertor, MySqlAlterViewConvertor, PgRenameViewConvertor, MySqlRenameViewConvertor, PgAlterViewSchemaConvertor, PgAlterViewAddWithOptionConvertor, PgAlterViewDropWithOptionConvertor, PgAlterViewAlterTablespaceConvertor, PgAlterViewAlterUsingConvertor, PgAlterTableAlterColumnSetGenerated, PgAlterTableAlterColumnDropGenerated, PgAlterTableAlterColumnAlterGenerated, PgAlterTableAddUniqueConstraintConvertor, PgAlterTableDropUniqueConstraintConvertor, PgAlterTableAddCheckConstraintConvertor, PgAlterTableDeleteCheckConstraintConvertor, MySQLAlterTableAddUniqueConstraintConvertor, MySQLAlterTableDropUniqueConstraintConvertor, MySqlAlterTableAddCheckConstraintConvertor, SingleStoreAlterTableAddUniqueConstraintConvertor, SingleStoreAlterTableDropUniqueConstraintConvertor, MySqlAlterTableDeleteCheckConstraintConvertor, CreatePgSequenceConvertor, DropPgSequenceConvertor, RenamePgSequenceConvertor, MovePgSequenceConvertor, AlterPgSequenceConvertor, CreateTypeEnumConvertor, DropTypeEnumConvertor, AlterTypeAddValueConvertor, AlterTypeSetSchemaConvertor, AlterRenameTypeConvertor, AlterTypeDropValueConvertor, PgDropTableConvertor, MySQLDropTableConvertor, SingleStoreDropTableConvertor, SQLiteDropTableConvertor, PgRenameTableConvertor, SqliteRenameTableConvertor, MySqlRenameTableConvertor, SingleStoreRenameTableConvertor, PgAlterTableRenameColumnConvertor, MySqlAlterTableRenameColumnConvertor, SingleStoreAlterTableRenameColumnConvertor, SQLiteAlterTableRenameColumnConvertor, PgAlterTableDropColumnConvertor, MySqlAlterTableDropColumnConvertor, SingleStoreAlterTableDropColumnConvertor, SQLiteAlterTableDropColumnConvertor, PgAlterTableAddColumnConvertor, MySqlAlterTableAddColumnConvertor, SingleStoreAlterTableAddColumnConvertor, SQLiteAlterTableAddColumnConvertor, PgAlterTableAlterColumnSetTypeConvertor, PgAlterTableAlterColumnSetDefaultConvertor, PgAlterTableAlterColumnDropDefaultConvertor, PgAlterTableAlterColumnDropGeneratedConvertor, PgAlterTableAlterColumnSetExpressionConvertor, PgAlterTableAlterColumnAlterrGeneratedConvertor, SqliteAlterTableAlterColumnDropGeneratedConvertor, SqliteAlterTableAlterColumnSetExpressionConvertor, SqliteAlterTableAlterColumnAlterGeneratedConvertor, MySqlAlterTableAlterColumnAlterrGeneratedConvertor, MySqlAlterTableAddPk, MySqlAlterTableDropPk, LibSQLModifyColumn, MySqlModifyColumn, SingleStoreAlterTableAlterColumnAlterrGeneratedConvertor, SingleStoreAlterTableAddPk, SingleStoreAlterTableDropPk, SingleStoreModifyColumn, PgAlterTableCreateCompositePrimaryKeyConvertor, PgAlterTableDeleteCompositePrimaryKeyConvertor, PgAlterTableAlterCompositePrimaryKeyConvertor, MySqlAlterTableCreateCompositePrimaryKeyConvertor, MySqlAlterTableDeleteCompositePrimaryKeyConvertor, MySqlAlterTableAlterCompositePrimaryKeyConvertor, PgAlterTableAlterColumnSetPrimaryKeyConvertor, PgAlterTableAlterColumnDropPrimaryKeyConvertor, PgAlterTableAlterColumnSetNotNullConvertor, PgAlterTableAlterColumnDropNotNullConvertor, PgCreateForeignKeyConvertor, LibSQLCreateForeignKeyConvertor, MySqlCreateForeignKeyConvertor, PgAlterForeignKeyConvertor, PgDeleteForeignKeyConvertor, MySqlDeleteForeignKeyConvertor, CreatePgIndexConvertor, CreateMySqlIndexConvertor, CreateSingleStoreIndexConvertor, CreateSqliteIndexConvertor, PgDropIndexConvertor, PgCreateSchemaConvertor, PgRenameSchemaConvertor, PgDropSchemaConvertor, PgAlterTableSetSchemaConvertor, PgAlterTableSetNewSchemaConvertor, PgAlterTableRemoveFromSchemaConvertor, SqliteDropIndexConvertor, MySqlDropIndexConvertor, SingleStoreDropIndexConvertor, SQLiteRecreateTableConvertor, LibSQLRecreateTableConvertor, convertors;
12124
+ var parseType, Convertor, PgCreateRoleConvertor, PgDropRoleConvertor, PgRenameRoleConvertor, PgAlterRoleConvertor, PgCreatePolicyConvertor, PgDropPolicyConvertor, PgRenamePolicyConvertor, PgAlterPolicyConvertor, PgCreateIndPolicyConvertor, PgDropIndPolicyConvertor, PgRenameIndPolicyConvertor, PgAlterIndPolicyConvertor, PgEnableRlsConvertor, PgDisableRlsConvertor, PgCreateTableConvertor, MySqlCreateTableConvertor, SingleStoreCreateTableConvertor, SQLiteCreateTableConvertor, PgCreateViewConvertor, MySqlCreateViewConvertor, SqliteCreateViewConvertor, PgDropViewConvertor, MySqlDropViewConvertor, SqliteDropViewConvertor, MySqlAlterViewConvertor, PgRenameViewConvertor, MySqlRenameViewConvertor, PgAlterViewSchemaConvertor, PgAlterViewAddWithOptionConvertor, PgAlterViewDropWithOptionConvertor, PgAlterViewAlterTablespaceConvertor, PgAlterViewAlterUsingConvertor, PgAlterTableAlterColumnSetGenerated, PgAlterTableAlterColumnDropGenerated, PgAlterTableAlterColumnAlterGenerated, PgAlterTableAddUniqueConstraintConvertor, PgAlterTableDropUniqueConstraintConvertor, PgAlterTableAddCheckConstraintConvertor, PgAlterTableDeleteCheckConstraintConvertor, MySQLAlterTableAddUniqueConstraintConvertor, MySQLAlterTableDropUniqueConstraintConvertor, MySqlAlterTableAddCheckConstraintConvertor, SingleStoreAlterTableAddUniqueConstraintConvertor, SingleStoreAlterTableDropUniqueConstraintConvertor, MySqlAlterTableDeleteCheckConstraintConvertor, CreatePgSequenceConvertor, DropPgSequenceConvertor, RenamePgSequenceConvertor, MovePgSequenceConvertor, AlterPgSequenceConvertor, CreateTypeEnumConvertor, DropTypeEnumConvertor, AlterTypeAddValueConvertor, AlterTypeSetSchemaConvertor, AlterRenameTypeConvertor, AlterTypeDropValueConvertor, PgDropTableConvertor, MySQLDropTableConvertor, SingleStoreDropTableConvertor, SQLiteDropTableConvertor, PgRenameTableConvertor, SqliteRenameTableConvertor, MySqlRenameTableConvertor, SingleStoreRenameTableConvertor, PgAlterTableRenameColumnConvertor, MySqlAlterTableRenameColumnConvertor, SingleStoreAlterTableRenameColumnConvertor, SQLiteAlterTableRenameColumnConvertor, PgAlterTableDropColumnConvertor, MySqlAlterTableDropColumnConvertor, SingleStoreAlterTableDropColumnConvertor, SQLiteAlterTableDropColumnConvertor, PgAlterTableAddColumnConvertor, MySqlAlterTableAddColumnConvertor, SingleStoreAlterTableAddColumnConvertor, SQLiteAlterTableAddColumnConvertor, PgAlterTableAlterColumnSetTypeConvertor, PgAlterTableAlterColumnSetDefaultConvertor, PgAlterTableAlterColumnDropDefaultConvertor, PgAlterTableAlterColumnDropGeneratedConvertor, PgAlterTableAlterColumnSetExpressionConvertor, PgAlterTableAlterColumnAlterrGeneratedConvertor, SqliteAlterTableAlterColumnDropGeneratedConvertor, SqliteAlterTableAlterColumnSetExpressionConvertor, SqliteAlterTableAlterColumnAlterGeneratedConvertor, MySqlAlterTableAlterColumnAlterrGeneratedConvertor, MySqlAlterTableAddPk, MySqlAlterTableDropPk, LibSQLModifyColumn, MySqlModifyColumn, SingleStoreAlterTableAlterColumnAlterrGeneratedConvertor, SingleStoreAlterTableAddPk, SingleStoreAlterTableDropPk, SingleStoreModifyColumn, PgAlterTableCreateCompositePrimaryKeyConvertor, PgAlterTableDeleteCompositePrimaryKeyConvertor, PgAlterTableAlterCompositePrimaryKeyConvertor, MySqlAlterTableCreateCompositePrimaryKeyConvertor, MySqlAlterTableDeleteCompositePrimaryKeyConvertor, MySqlAlterTableAlterCompositePrimaryKeyConvertor, PgAlterTableAlterColumnSetPrimaryKeyConvertor, PgAlterTableAlterColumnDropPrimaryKeyConvertor, PgAlterTableAlterColumnSetNotNullConvertor, PgAlterTableAlterColumnDropNotNullConvertor, PgCreateForeignKeyConvertor, LibSQLCreateForeignKeyConvertor, MySqlCreateForeignKeyConvertor, PgAlterForeignKeyConvertor, PgDeleteForeignKeyConvertor, MySqlDeleteForeignKeyConvertor, CreatePgIndexConvertor, CreateMySqlIndexConvertor, CreateSingleStoreIndexConvertor, CreateSqliteIndexConvertor, PgDropIndexConvertor, PgCreateSchemaConvertor, PgRenameSchemaConvertor, PgDropSchemaConvertor, PgAlterTableSetSchemaConvertor, PgAlterTableSetNewSchemaConvertor, PgAlterTableRemoveFromSchemaConvertor, SqliteDropIndexConvertor, MySqlDropIndexConvertor, SingleStoreDropIndexConvertor, SQLiteRecreateTableConvertor, LibSQLRecreateTableConvertor, SingleStoreRecreateTableConvertor, convertors;
12125
12125
  var init_sqlgenerator = __esm({
12126
12126
  "src/sqlgenerator.ts"() {
12127
12127
  "use strict";
@@ -12467,7 +12467,7 @@ var init_sqlgenerator = __esm({
12467
12467
  if (typeof compositePKs !== "undefined" && compositePKs.length > 0) {
12468
12468
  statement += ",\n";
12469
12469
  const compositePK5 = SingleStoreSquasher.unsquashPK(compositePKs[0]);
12470
- statement += ` CONSTRAINT \`${st.compositePkName}\` PRIMARY KEY(\`${compositePK5.columns.join(`\`,\``)}\`)`;
12470
+ statement += ` CONSTRAINT \`${compositePK5.name}\` PRIMARY KEY(\`${compositePK5.columns.join(`\`,\``)}\`)`;
12471
12471
  }
12472
12472
  if (typeof uniqueConstraints !== "undefined" && uniqueConstraints.length > 0) {
12473
12473
  for (const uniqueConstraint5 of uniqueConstraints) {
@@ -13122,7 +13122,7 @@ WITH ${withCheckOption} CHECK OPTION` : "";
13122
13122
  }
13123
13123
  convert(statement) {
13124
13124
  const { tableNameFrom, tableNameTo } = statement;
13125
- return `RENAME TABLE \`${tableNameFrom}\` TO \`${tableNameTo}\`;`;
13125
+ return `ALTER TABLE \`${tableNameFrom}\` RENAME TO \`${tableNameTo}\`;`;
13126
13126
  }
13127
13127
  };
13128
13128
  PgAlterTableRenameColumnConvertor = class extends Convertor {
@@ -13150,7 +13150,7 @@ WITH ${withCheckOption} CHECK OPTION` : "";
13150
13150
  }
13151
13151
  convert(statement) {
13152
13152
  const { tableName, oldColumnName, newColumnName } = statement;
13153
- return `ALTER TABLE \`${tableName}\` RENAME COLUMN \`${oldColumnName}\` TO \`${newColumnName}\`;`;
13153
+ return `ALTER TABLE \`${tableName}\` CHANGE \`${oldColumnName}\` \`${newColumnName}\`;`;
13154
13154
  }
13155
13155
  };
13156
13156
  SQLiteAlterTableRenameColumnConvertor = class extends Convertor {
@@ -14460,10 +14460,52 @@ ${BREAKPOINT}ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT "${statement.newC
14460
14460
  return sqlStatements;
14461
14461
  }
14462
14462
  };
14463
+ SingleStoreRecreateTableConvertor = class extends Convertor {
14464
+ can(statement, dialect6) {
14465
+ return statement.type === "singlestore_recreate_table" && dialect6 === "singlestore";
14466
+ }
14467
+ convert(statement) {
14468
+ const { tableName, columns, compositePKs, uniqueConstraints } = statement;
14469
+ const columnNames = columns.map((it) => `\`${it.name}\``).join(", ");
14470
+ const newTableName = `__new_${tableName}`;
14471
+ const sqlStatements = [];
14472
+ sqlStatements.push(
14473
+ new SingleStoreCreateTableConvertor().convert({
14474
+ type: "create_table",
14475
+ tableName: newTableName,
14476
+ columns,
14477
+ compositePKs,
14478
+ uniqueConstraints,
14479
+ schema: ""
14480
+ })
14481
+ );
14482
+ sqlStatements.push(
14483
+ `INSERT INTO \`${newTableName}\`(${columnNames}) SELECT ${columnNames} FROM \`${tableName}\`;`
14484
+ );
14485
+ sqlStatements.push(
14486
+ new SingleStoreDropTableConvertor().convert({
14487
+ type: "drop_table",
14488
+ tableName,
14489
+ schema: ""
14490
+ })
14491
+ );
14492
+ sqlStatements.push(
14493
+ new SingleStoreRenameTableConvertor().convert({
14494
+ fromSchema: "",
14495
+ tableNameFrom: newTableName,
14496
+ tableNameTo: tableName,
14497
+ toSchema: "",
14498
+ type: "rename_table"
14499
+ })
14500
+ );
14501
+ return sqlStatements;
14502
+ }
14503
+ };
14463
14504
  convertors = [];
14464
14505
  convertors.push(new PgCreateTableConvertor());
14465
14506
  convertors.push(new MySqlCreateTableConvertor());
14466
14507
  convertors.push(new SingleStoreCreateTableConvertor());
14508
+ convertors.push(new SingleStoreRecreateTableConvertor());
14467
14509
  convertors.push(new SQLiteCreateTableConvertor());
14468
14510
  convertors.push(new SQLiteRecreateTableConvertor());
14469
14511
  convertors.push(new LibSQLRecreateTableConvertor());
@@ -16459,7 +16501,7 @@ var init_jsonStatements = __esm({
16459
16501
  });
16460
16502
 
16461
16503
  // src/statementCombiner.ts
16462
- var prepareLibSQLRecreateTable, prepareSQLiteRecreateTable, libSQLCombineStatements, sqliteCombineStatements;
16504
+ var prepareLibSQLRecreateTable, prepareSQLiteRecreateTable, libSQLCombineStatements, sqliteCombineStatements, prepareSingleStoreRecreateTable, singleStoreCombineStatements;
16463
16505
  var init_statementCombiner = __esm({
16464
16506
  "src/statementCombiner.ts"() {
16465
16507
  "use strict";
@@ -16738,6 +16780,101 @@ var init_statementCombiner = __esm({
16738
16780
  const rest = combinedStatements.filter((it) => it.type !== "rename_table" && it.type !== "alter_table_rename_column");
16739
16781
  return [...renamedTables, ...renamedColumns, ...rest];
16740
16782
  };
16783
+ prepareSingleStoreRecreateTable = (table5) => {
16784
+ const { name: name2, columns, uniqueConstraints, indexes, compositePrimaryKeys } = table5;
16785
+ const composites = Object.values(compositePrimaryKeys);
16786
+ const statements = [
16787
+ {
16788
+ type: "singlestore_recreate_table",
16789
+ tableName: name2,
16790
+ columns: Object.values(columns),
16791
+ compositePKs: composites,
16792
+ uniqueConstraints: Object.values(uniqueConstraints)
16793
+ }
16794
+ ];
16795
+ if (Object.keys(indexes).length) {
16796
+ statements.push(...prepareCreateIndexesJson(name2, "", indexes));
16797
+ }
16798
+ return statements;
16799
+ };
16800
+ singleStoreCombineStatements = (statements, json22) => {
16801
+ const newStatements = {};
16802
+ for (const statement of statements) {
16803
+ if (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_autoincrement" || statement.type === "alter_table_alter_column_set_autoincrement" || statement.type === "alter_table_alter_column_drop_pk" || statement.type === "alter_table_alter_column_set_pk" || statement.type === "create_composite_pk" || statement.type === "alter_composite_pk" || statement.type === "delete_composite_pk") {
16804
+ const tableName2 = statement.tableName;
16805
+ const statementsForTable2 = newStatements[tableName2];
16806
+ if (!statementsForTable2) {
16807
+ newStatements[tableName2] = prepareSingleStoreRecreateTable(json22.tables[tableName2]);
16808
+ continue;
16809
+ }
16810
+ if (!statementsForTable2.some(({ type }) => type === "recreate_table")) {
16811
+ const wasRename = statementsForTable2.some(
16812
+ ({ type }) => type === "rename_table" || type === "alter_table_rename_column"
16813
+ );
16814
+ const preparedStatements = prepareSingleStoreRecreateTable(json22.tables[tableName2]);
16815
+ if (wasRename) {
16816
+ newStatements[tableName2].push(...preparedStatements);
16817
+ } else {
16818
+ newStatements[tableName2] = preparedStatements;
16819
+ }
16820
+ continue;
16821
+ }
16822
+ continue;
16823
+ }
16824
+ if ((statement.type === "alter_table_alter_column_drop_default" || statement.type === "alter_table_alter_column_set_default") && statement.columnNotNull) {
16825
+ const tableName2 = statement.tableName;
16826
+ const statementsForTable2 = newStatements[tableName2];
16827
+ if (!statementsForTable2) {
16828
+ newStatements[tableName2] = prepareSingleStoreRecreateTable(json22.tables[tableName2]);
16829
+ continue;
16830
+ }
16831
+ if (!statementsForTable2.some(({ type }) => type === "recreate_table")) {
16832
+ const wasRename = statementsForTable2.some(({ type }) => type === "rename_table");
16833
+ const preparedStatements = prepareSingleStoreRecreateTable(json22.tables[tableName2]);
16834
+ if (wasRename) {
16835
+ newStatements[tableName2].push(...preparedStatements);
16836
+ } else {
16837
+ newStatements[tableName2] = preparedStatements;
16838
+ }
16839
+ continue;
16840
+ }
16841
+ continue;
16842
+ }
16843
+ if (statement.type === "alter_table_add_column" && statement.column.primaryKey) {
16844
+ const tableName2 = statement.tableName;
16845
+ const statementsForTable2 = newStatements[tableName2];
16846
+ if (!statementsForTable2) {
16847
+ newStatements[tableName2] = prepareSingleStoreRecreateTable(json22.tables[tableName2]);
16848
+ continue;
16849
+ }
16850
+ if (!statementsForTable2.some(({ type }) => type === "recreate_table")) {
16851
+ const wasRename = statementsForTable2.some(({ type }) => type === "rename_table");
16852
+ const preparedStatements = prepareSingleStoreRecreateTable(json22.tables[tableName2]);
16853
+ if (wasRename) {
16854
+ newStatements[tableName2].push(...preparedStatements);
16855
+ } else {
16856
+ newStatements[tableName2] = preparedStatements;
16857
+ }
16858
+ continue;
16859
+ }
16860
+ continue;
16861
+ }
16862
+ const tableName = statement.type === "rename_table" ? statement.tableNameTo : statement.tableName;
16863
+ const statementsForTable = newStatements[tableName];
16864
+ if (!statementsForTable) {
16865
+ newStatements[tableName] = [statement];
16866
+ continue;
16867
+ }
16868
+ if (!statementsForTable.some(({ type }) => type === "singlestore_recreate_table")) {
16869
+ newStatements[tableName].push(statement);
16870
+ }
16871
+ }
16872
+ const combinedStatements = Object.values(newStatements).flat();
16873
+ const renamedTables = combinedStatements.filter((it) => it.type === "rename_table");
16874
+ const renamedColumns = combinedStatements.filter((it) => it.type === "alter_table_rename_column");
16875
+ const rest = combinedStatements.filter((it) => it.type !== "rename_table" && it.type !== "alter_table_rename_column");
16876
+ return [...renamedTables, ...renamedColumns, ...rest];
16877
+ };
16741
16878
  }
16742
16879
  });
16743
16880
 
@@ -18683,7 +18820,7 @@ var init_snapshotsDiffer = __esm({
18683
18820
  return [tableKey2, tableValue];
18684
18821
  }
18685
18822
  );
18686
- const diffResult = applyJsonDiff(tablesPatchedSnap1, json22);
18823
+ const diffResult = applyJsonDiff(columnsPatchedSnap1, json22);
18687
18824
  const typedResult = diffResultSchemeSingleStore.parse(diffResult);
18688
18825
  const jsonStatements = [];
18689
18826
  const jsonCreateIndexesForCreatedTables = createdTables.map((it) => {
@@ -18847,7 +18984,8 @@ var init_snapshotsDiffer = __esm({
18847
18984
  jsonStatements.push(...jsonDropColumnsStatemets);
18848
18985
  jsonStatements.push(...jsonAddedCompositePKs);
18849
18986
  jsonStatements.push(...jsonAlteredUniqueConstraints);
18850
- const sqlStatements = fromJson(jsonStatements, "singlestore");
18987
+ const combinedJsonStatements = singleStoreCombineStatements(jsonStatements, json22);
18988
+ const sqlStatements = fromJson(combinedJsonStatements, "singlestore");
18851
18989
  const uniqueSqlStatements = [];
18852
18990
  sqlStatements.forEach((ss) => {
18853
18991
  if (!uniqueSqlStatements.includes(ss)) {
@@ -18859,7 +18997,7 @@ var init_snapshotsDiffer = __esm({
18859
18997
  });
18860
18998
  const _meta = prepareMigrationMeta([], rTables, rColumns);
18861
18999
  return {
18862
- statements: jsonStatements,
19000
+ statements: combinedJsonStatements,
18863
19001
  sqlStatements: uniqueSqlStatements,
18864
19002
  _meta
18865
19003
  };
@@ -21977,7 +22115,7 @@ var version;
21977
22115
  var init_version = __esm({
21978
22116
  "../drizzle-orm/dist/version.js"() {
21979
22117
  "use strict";
21980
- version = "0.38.4";
22118
+ version = "0.39.0";
21981
22119
  }
21982
22120
  });
21983
22121
 
@@ -22165,6 +22303,9 @@ function fillPlaceholders(params, values) {
22165
22303
  function isView(view4) {
22166
22304
  return typeof view4 === "object" && view4 !== null && IsDrizzleView in view4;
22167
22305
  }
22306
+ function getViewName(view4) {
22307
+ return view4[ViewBaseConfig].name;
22308
+ }
22168
22309
  var _a19, FakePrimitiveParam, _a20, StringChunk, _a21, _SQL, SQL, _a22, Name, noopDecoder, noopEncoder, noopMapper, _a23, Param, _a24, Placeholder, IsDrizzleView, _a25, _b10, _c2, View3;
22169
22310
  var init_sql = __esm({
22170
22311
  "../drizzle-orm/dist/sql/sql.js"() {
@@ -25291,6 +25432,7 @@ __export(dist_exports, {
25291
25432
  getTableLikeName: () => getTableLikeName,
25292
25433
  getTableName: () => getTableName,
25293
25434
  getTableUniqueName: () => getTableUniqueName,
25435
+ getViewName: () => getViewName,
25294
25436
  getViewSelectedFields: () => getViewSelectedFields,
25295
25437
  gt: () => gt,
25296
25438
  gte: () => gte,
@@ -25445,17 +25587,100 @@ var init_columns = __esm({
25445
25587
  }
25446
25588
  });
25447
25589
 
25590
+ // ../drizzle-orm/dist/selection-proxy.js
25591
+ var _a124, _SelectionProxyHandler, SelectionProxyHandler;
25592
+ var init_selection_proxy = __esm({
25593
+ "../drizzle-orm/dist/selection-proxy.js"() {
25594
+ "use strict";
25595
+ init_alias();
25596
+ init_column();
25597
+ init_entity();
25598
+ init_sql();
25599
+ init_subquery();
25600
+ init_view_common();
25601
+ _a124 = entityKind;
25602
+ _SelectionProxyHandler = class _SelectionProxyHandler {
25603
+ constructor(config) {
25604
+ __publicField(this, "config");
25605
+ this.config = { ...config };
25606
+ }
25607
+ get(subquery, prop) {
25608
+ if (prop === "_") {
25609
+ return {
25610
+ ...subquery["_"],
25611
+ selectedFields: new Proxy(
25612
+ subquery._.selectedFields,
25613
+ this
25614
+ )
25615
+ };
25616
+ }
25617
+ if (prop === ViewBaseConfig) {
25618
+ return {
25619
+ ...subquery[ViewBaseConfig],
25620
+ selectedFields: new Proxy(
25621
+ subquery[ViewBaseConfig].selectedFields,
25622
+ this
25623
+ )
25624
+ };
25625
+ }
25626
+ if (typeof prop === "symbol") {
25627
+ return subquery[prop];
25628
+ }
25629
+ const columns = is(subquery, Subquery) ? subquery._.selectedFields : is(subquery, View3) ? subquery[ViewBaseConfig].selectedFields : subquery;
25630
+ const value = columns[prop];
25631
+ if (is(value, SQL.Aliased)) {
25632
+ if (this.config.sqlAliasedBehavior === "sql" && !value.isSelectionField) {
25633
+ return value.sql;
25634
+ }
25635
+ const newValue = value.clone();
25636
+ newValue.isSelectionField = true;
25637
+ return newValue;
25638
+ }
25639
+ if (is(value, SQL)) {
25640
+ if (this.config.sqlBehavior === "sql") {
25641
+ return value;
25642
+ }
25643
+ throw new Error(
25644
+ `You tried to reference "${prop}" field from a subquery, which is a raw SQL field, but it doesn't have an alias declared. Please add an alias to the field using ".as('alias')" method.`
25645
+ );
25646
+ }
25647
+ if (is(value, Column2)) {
25648
+ if (this.config.alias) {
25649
+ return new Proxy(
25650
+ value,
25651
+ new ColumnAliasProxyHandler(
25652
+ new Proxy(
25653
+ value.table,
25654
+ new TableAliasProxyHandler(this.config.alias, this.config.replaceOriginalName ?? false)
25655
+ )
25656
+ )
25657
+ );
25658
+ }
25659
+ return value;
25660
+ }
25661
+ if (typeof value !== "object" || value === null) {
25662
+ return value;
25663
+ }
25664
+ return new Proxy(value, new _SelectionProxyHandler(this.config));
25665
+ }
25666
+ };
25667
+ __publicField(_SelectionProxyHandler, _a124, "SelectionProxyHandler");
25668
+ SelectionProxyHandler = _SelectionProxyHandler;
25669
+ }
25670
+ });
25671
+
25448
25672
  // ../drizzle-orm/dist/pg-core/query-builders/delete.js
25449
- var _a124, _b97, PgDeleteBase;
25673
+ var _a125, _b97, PgDeleteBase;
25450
25674
  var init_delete = __esm({
25451
25675
  "../drizzle-orm/dist/pg-core/query-builders/delete.js"() {
25452
25676
  "use strict";
25453
25677
  init_entity();
25454
25678
  init_query_promise();
25679
+ init_selection_proxy();
25455
25680
  init_table();
25456
25681
  init_tracing();
25457
25682
  init_utils2();
25458
- PgDeleteBase = class extends (_b97 = QueryPromise, _a124 = entityKind, _b97) {
25683
+ PgDeleteBase = class extends (_b97 = QueryPromise, _a125 = entityKind, _b97) {
25459
25684
  constructor(table5, session, dialect6, withList) {
25460
25685
  super();
25461
25686
  __publicField(this, "config");
@@ -25503,6 +25728,7 @@ var init_delete = __esm({
25503
25728
  return this;
25504
25729
  }
25505
25730
  returning(fields = this.config.table[Table2.Symbol.Columns]) {
25731
+ this.config.returningFields = fields;
25506
25732
  this.config.returning = orderSelectedFields(fields);
25507
25733
  return this;
25508
25734
  }
@@ -25528,11 +25754,22 @@ var init_delete = __esm({
25528
25754
  this.authToken = token;
25529
25755
  return this;
25530
25756
  }
25757
+ /** @internal */
25758
+ getSelectedFields() {
25759
+ return this.config.returningFields ? new Proxy(
25760
+ this.config.returningFields,
25761
+ new SelectionProxyHandler({
25762
+ alias: getTableName(this.config.table),
25763
+ sqlAliasedBehavior: "alias",
25764
+ sqlBehavior: "error"
25765
+ })
25766
+ ) : void 0;
25767
+ }
25531
25768
  $dynamic() {
25532
25769
  return this;
25533
25770
  }
25534
25771
  };
25535
- __publicField(PgDeleteBase, _a124, "PgDelete");
25772
+ __publicField(PgDeleteBase, _a125, "PgDelete");
25536
25773
  }
25537
25774
  });
25538
25775
 
@@ -25551,13 +25788,13 @@ function toCamelCase(input) {
25551
25788
  function noopCase(input) {
25552
25789
  return input;
25553
25790
  }
25554
- var _a125, CasingCache;
25791
+ var _a126, CasingCache;
25555
25792
  var init_casing = __esm({
25556
25793
  "../drizzle-orm/dist/casing.js"() {
25557
25794
  "use strict";
25558
25795
  init_entity();
25559
25796
  init_table();
25560
- _a125 = entityKind;
25797
+ _a126 = entityKind;
25561
25798
  CasingCache = class {
25562
25799
  constructor(casing2) {
25563
25800
  /** @internal */
@@ -25594,25 +25831,25 @@ var init_casing = __esm({
25594
25831
  this.cachedTables = {};
25595
25832
  }
25596
25833
  };
25597
- __publicField(CasingCache, _a125, "CasingCache");
25834
+ __publicField(CasingCache, _a126, "CasingCache");
25598
25835
  }
25599
25836
  });
25600
25837
 
25601
25838
  // ../drizzle-orm/dist/pg-core/view-base.js
25602
- var _a126, _b98, PgViewBase;
25839
+ var _a127, _b98, PgViewBase;
25603
25840
  var init_view_base = __esm({
25604
25841
  "../drizzle-orm/dist/pg-core/view-base.js"() {
25605
25842
  "use strict";
25606
25843
  init_entity();
25607
25844
  init_sql();
25608
- PgViewBase = class extends (_b98 = View3, _a126 = entityKind, _b98) {
25845
+ PgViewBase = class extends (_b98 = View3, _a127 = entityKind, _b98) {
25609
25846
  };
25610
- __publicField(PgViewBase, _a126, "PgViewBase");
25847
+ __publicField(PgViewBase, _a127, "PgViewBase");
25611
25848
  }
25612
25849
  });
25613
25850
 
25614
25851
  // ../drizzle-orm/dist/pg-core/dialect.js
25615
- var _a127, PgDialect;
25852
+ var _a128, PgDialect;
25616
25853
  var init_dialect = __esm({
25617
25854
  "../drizzle-orm/dist/pg-core/dialect.js"() {
25618
25855
  "use strict";
@@ -25631,7 +25868,7 @@ var init_dialect = __esm({
25631
25868
  init_utils2();
25632
25869
  init_view_common();
25633
25870
  init_view_base();
25634
- _a127 = entityKind;
25871
+ _a128 = entityKind;
25635
25872
  PgDialect = class {
25636
25873
  constructor(config) {
25637
25874
  /** @internal */
@@ -26723,89 +26960,7 @@ var init_dialect = __esm({
26723
26960
  };
26724
26961
  }
26725
26962
  };
26726
- __publicField(PgDialect, _a127, "PgDialect");
26727
- }
26728
- });
26729
-
26730
- // ../drizzle-orm/dist/selection-proxy.js
26731
- var _a128, _SelectionProxyHandler, SelectionProxyHandler;
26732
- var init_selection_proxy = __esm({
26733
- "../drizzle-orm/dist/selection-proxy.js"() {
26734
- "use strict";
26735
- init_alias();
26736
- init_column();
26737
- init_entity();
26738
- init_sql();
26739
- init_subquery();
26740
- init_view_common();
26741
- _a128 = entityKind;
26742
- _SelectionProxyHandler = class _SelectionProxyHandler {
26743
- constructor(config) {
26744
- __publicField(this, "config");
26745
- this.config = { ...config };
26746
- }
26747
- get(subquery, prop) {
26748
- if (prop === "_") {
26749
- return {
26750
- ...subquery["_"],
26751
- selectedFields: new Proxy(
26752
- subquery._.selectedFields,
26753
- this
26754
- )
26755
- };
26756
- }
26757
- if (prop === ViewBaseConfig) {
26758
- return {
26759
- ...subquery[ViewBaseConfig],
26760
- selectedFields: new Proxy(
26761
- subquery[ViewBaseConfig].selectedFields,
26762
- this
26763
- )
26764
- };
26765
- }
26766
- if (typeof prop === "symbol") {
26767
- return subquery[prop];
26768
- }
26769
- const columns = is(subquery, Subquery) ? subquery._.selectedFields : is(subquery, View3) ? subquery[ViewBaseConfig].selectedFields : subquery;
26770
- const value = columns[prop];
26771
- if (is(value, SQL.Aliased)) {
26772
- if (this.config.sqlAliasedBehavior === "sql" && !value.isSelectionField) {
26773
- return value.sql;
26774
- }
26775
- const newValue = value.clone();
26776
- newValue.isSelectionField = true;
26777
- return newValue;
26778
- }
26779
- if (is(value, SQL)) {
26780
- if (this.config.sqlBehavior === "sql") {
26781
- return value;
26782
- }
26783
- throw new Error(
26784
- `You tried to reference "${prop}" field from a subquery, which is a raw SQL field, but it doesn't have an alias declared. Please add an alias to the field using ".as('alias')" method.`
26785
- );
26786
- }
26787
- if (is(value, Column2)) {
26788
- if (this.config.alias) {
26789
- return new Proxy(
26790
- value,
26791
- new ColumnAliasProxyHandler(
26792
- new Proxy(
26793
- value.table,
26794
- new TableAliasProxyHandler(this.config.alias, this.config.replaceOriginalName ?? false)
26795
- )
26796
- )
26797
- );
26798
- }
26799
- return value;
26800
- }
26801
- if (typeof value !== "object" || value === null) {
26802
- return value;
26803
- }
26804
- return new Proxy(value, new _SelectionProxyHandler(this.config));
26805
- }
26806
- };
26807
- __publicField(_SelectionProxyHandler, _a128, "SelectionProxyHandler");
26808
- SelectionProxyHandler = _SelectionProxyHandler;
26963
+ __publicField(PgDialect, _a128, "PgDialect");
26809
26964
  }
26810
26965
  });
26811
26966
 
@@ -26890,22 +27045,23 @@ var init_select2 = __esm({
26890
27045
  */
26891
27046
  from(source) {
26892
27047
  const isPartialSelect = !!this.fields;
27048
+ const src = source;
26893
27049
  let fields;
26894
27050
  if (this.fields) {
26895
27051
  fields = this.fields;
26896
- } else if (is(source, Subquery)) {
27052
+ } else if (is(src, Subquery)) {
26897
27053
  fields = Object.fromEntries(
26898
- Object.keys(source._.selectedFields).map((key) => [key, source[key]])
27054
+ Object.keys(src._.selectedFields).map((key) => [key, src[key]])
26899
27055
  );
26900
- } else if (is(source, PgViewBase)) {
26901
- fields = source[ViewBaseConfig].selectedFields;
26902
- } else if (is(source, SQL)) {
27056
+ } else if (is(src, PgViewBase)) {
27057
+ fields = src[ViewBaseConfig].selectedFields;
27058
+ } else if (is(src, SQL)) {
26903
27059
  fields = {};
26904
27060
  } else {
26905
- fields = getTableColumns(source);
27061
+ fields = getTableColumns(src);
26906
27062
  }
26907
27063
  return new PgSelectBase({
26908
- table: source,
27064
+ table: src,
26909
27065
  fields,
26910
27066
  isPartialSelect,
26911
27067
  session: this.session,
@@ -27590,22 +27746,26 @@ var init_query_builder2 = __esm({
27590
27746
  constructor(dialect6) {
27591
27747
  __publicField(this, "dialect");
27592
27748
  __publicField(this, "dialectConfig");
27593
- this.dialect = is(dialect6, PgDialect) ? dialect6 : void 0;
27594
- this.dialectConfig = is(dialect6, PgDialect) ? void 0 : dialect6;
27595
- }
27596
- $with(alias) {
27597
- const queryBuilder = this;
27598
- return {
27599
- as(qb) {
27749
+ __publicField(this, "$with", (alias, selection) => {
27750
+ const queryBuilder = this;
27751
+ const as = (qb) => {
27600
27752
  if (typeof qb === "function") {
27601
27753
  qb = qb(queryBuilder);
27602
27754
  }
27603
27755
  return new Proxy(
27604
- new WithSubquery(qb.getSQL(), qb.getSelectedFields(), alias, true),
27756
+ new WithSubquery(
27757
+ qb.getSQL(),
27758
+ selection ?? ("getSelectedFields" in qb ? qb.getSelectedFields() ?? {} : {}),
27759
+ alias,
27760
+ true
27761
+ ),
27605
27762
  new SelectionProxyHandler({ alias, sqlAliasedBehavior: "alias", sqlBehavior: "error" })
27606
27763
  );
27607
- }
27608
- };
27764
+ };
27765
+ return { as };
27766
+ });
27767
+ this.dialect = is(dialect6, PgDialect) ? dialect6 : void 0;
27768
+ this.dialectConfig = is(dialect6, PgDialect) ? void 0 : dialect6;
27609
27769
  }
27610
27770
  with(...queries) {
27611
27771
  const self2 = this;
@@ -27677,6 +27837,7 @@ var init_insert = __esm({
27677
27837
  "use strict";
27678
27838
  init_entity();
27679
27839
  init_query_promise();
27840
+ init_selection_proxy();
27680
27841
  init_sql();
27681
27842
  init_table();
27682
27843
  init_tracing();
@@ -27751,6 +27912,7 @@ var init_insert = __esm({
27751
27912
  this.config = { table: table5, values, withList, select, overridingSystemValue_ };
27752
27913
  }
27753
27914
  returning(fields = this.config.table[Table2.Symbol.Columns]) {
27915
+ this.config.returningFields = fields;
27754
27916
  this.config.returning = orderSelectedFields(fields);
27755
27917
  return this;
27756
27918
  }
@@ -27853,6 +28015,17 @@ var init_insert = __esm({
27853
28015
  this.authToken = token;
27854
28016
  return this;
27855
28017
  }
28018
+ /** @internal */
28019
+ getSelectedFields() {
28020
+ return this.config.returningFields ? new Proxy(
28021
+ this.config.returningFields,
28022
+ new SelectionProxyHandler({
28023
+ alias: getTableName(this.config.table),
28024
+ sqlAliasedBehavior: "alias",
28025
+ sqlBehavior: "error"
28026
+ })
28027
+ ) : void 0;
28028
+ }
27856
28029
  $dynamic() {
27857
28030
  return this;
27858
28031
  }
@@ -27990,11 +28163,12 @@ var init_update = __esm({
27990
28163
  this.joinsNotNullableMap = typeof this.tableName === "string" ? { [this.tableName]: true } : {};
27991
28164
  }
27992
28165
  from(source) {
27993
- const tableName = getTableLikeName(source);
28166
+ const src = source;
28167
+ const tableName = getTableLikeName(src);
27994
28168
  if (typeof tableName === "string") {
27995
28169
  this.joinsNotNullableMap[tableName] = true;
27996
28170
  }
27997
- this.config.from = source;
28171
+ this.config.from = src;
27998
28172
  return this;
27999
28173
  }
28000
28174
  getTableLikeFields(table5) {
@@ -28109,6 +28283,7 @@ var init_update = __esm({
28109
28283
  }
28110
28284
  }
28111
28285
  }
28286
+ this.config.returningFields = fields;
28112
28287
  this.config.returning = orderSelectedFields(fields);
28113
28288
  return this;
28114
28289
  }
@@ -28134,6 +28309,17 @@ var init_update = __esm({
28134
28309
  this.authToken = token;
28135
28310
  return this;
28136
28311
  }
28312
+ /** @internal */
28313
+ getSelectedFields() {
28314
+ return this.config.returningFields ? new Proxy(
28315
+ this.config.returningFields,
28316
+ new SelectionProxyHandler({
28317
+ alias: getTableName(this.config.table),
28318
+ sqlAliasedBehavior: "alias",
28319
+ sqlBehavior: "error"
28320
+ })
28321
+ ) : void 0;
28322
+ }
28137
28323
  $dynamic() {
28138
28324
  return this;
28139
28325
  }
@@ -28395,6 +28581,56 @@ var init_db = __esm({
28395
28581
  PgDatabase = class {
28396
28582
  constructor(dialect6, session, schema5) {
28397
28583
  __publicField(this, "query");
28584
+ /**
28585
+ * Creates a subquery that defines a temporary named result set as a CTE.
28586
+ *
28587
+ * It is useful for breaking down complex queries into simpler parts and for reusing the result set in subsequent parts of the query.
28588
+ *
28589
+ * See docs: {@link https://orm.drizzle.team/docs/select#with-clause}
28590
+ *
28591
+ * @param alias The alias for the subquery.
28592
+ *
28593
+ * Failure to provide an alias will result in a DrizzleTypeError, preventing the subquery from being referenced in other queries.
28594
+ *
28595
+ * @example
28596
+ *
28597
+ * ```ts
28598
+ * // Create a subquery with alias 'sq' and use it in the select query
28599
+ * const sq = db.$with('sq').as(db.select().from(users).where(eq(users.id, 42)));
28600
+ *
28601
+ * const result = await db.with(sq).select().from(sq);
28602
+ * ```
28603
+ *
28604
+ * To select arbitrary SQL values as fields in a CTE and reference them in other CTEs or in the main query, you need to add aliases to them:
28605
+ *
28606
+ * ```ts
28607
+ * // Select an arbitrary SQL value as a field in a CTE and reference it in the main query
28608
+ * const sq = db.$with('sq').as(db.select({
28609
+ * name: sql<string>`upper(${users.name})`.as('name'),
28610
+ * })
28611
+ * .from(users));
28612
+ *
28613
+ * const result = await db.with(sq).select({ name: sq.name }).from(sq);
28614
+ * ```
28615
+ */
28616
+ __publicField(this, "$with", (alias, selection) => {
28617
+ const self2 = this;
28618
+ const as = (qb) => {
28619
+ if (typeof qb === "function") {
28620
+ qb = qb(new QueryBuilder(self2.dialect));
28621
+ }
28622
+ return new Proxy(
28623
+ new WithSubquery(
28624
+ qb.getSQL(),
28625
+ selection ?? ("getSelectedFields" in qb ? qb.getSelectedFields() ?? {} : {}),
28626
+ alias,
28627
+ true
28628
+ ),
28629
+ new SelectionProxyHandler({ alias, sqlAliasedBehavior: "alias", sqlBehavior: "error" })
28630
+ );
28631
+ };
28632
+ return { as };
28633
+ });
28398
28634
  __publicField(this, "authToken");
28399
28635
  this.dialect = dialect6;
28400
28636
  this.session = session;
@@ -28424,52 +28660,6 @@ var init_db = __esm({
28424
28660
  }
28425
28661
  }
28426
28662
  }
28427
- /**
28428
- * Creates a subquery that defines a temporary named result set as a CTE.
28429
- *
28430
- * It is useful for breaking down complex queries into simpler parts and for reusing the result set in subsequent parts of the query.
28431
- *
28432
- * See docs: {@link https://orm.drizzle.team/docs/select#with-clause}
28433
- *
28434
- * @param alias The alias for the subquery.
28435
- *
28436
- * Failure to provide an alias will result in a DrizzleTypeError, preventing the subquery from being referenced in other queries.
28437
- *
28438
- * @example
28439
- *
28440
- * ```ts
28441
- * // Create a subquery with alias 'sq' and use it in the select query
28442
- * const sq = db.$with('sq').as(db.select().from(users).where(eq(users.id, 42)));
28443
- *
28444
- * const result = await db.with(sq).select().from(sq);
28445
- * ```
28446
- *
28447
- * To select arbitrary SQL values as fields in a CTE and reference them in other CTEs or in the main query, you need to add aliases to them:
28448
- *
28449
- * ```ts
28450
- * // Select an arbitrary SQL value as a field in a CTE and reference it in the main query
28451
- * const sq = db.$with('sq').as(db.select({
28452
- * name: sql<string>`upper(${users.name})`.as('name'),
28453
- * })
28454
- * .from(users));
28455
- *
28456
- * const result = await db.with(sq).select({ name: sq.name }).from(sq);
28457
- * ```
28458
- */
28459
- $with(alias) {
28460
- const self2 = this;
28461
- return {
28462
- as(qb) {
28463
- if (typeof qb === "function") {
28464
- qb = qb(new QueryBuilder(self2.dialect));
28465
- }
28466
- return new Proxy(
28467
- new WithSubquery(qb.getSQL(), qb.getSelectedFields(), alias, true),
28468
- new SelectionProxyHandler({ alias, sqlAliasedBehavior: "alias", sqlBehavior: "error" })
28469
- );
28470
- }
28471
- };
28472
- }
28473
28663
  $count(source, filters) {
28474
28664
  return new PgCountBuilder({ source, filters, session: this.session });
28475
28665
  }
@@ -32273,7 +32463,7 @@ var init_dialect2 = __esm({
32273
32463
  const withSql = this.buildWithCTE(withList);
32274
32464
  const valuesSql = sql.join(valuesSqlList);
32275
32465
  const returningSql = returning ? sql` returning ${this.buildSelection(returning, { isSingleTable: true })}` : void 0;
32276
- const onConflictSql = onConflict ? sql` on conflict ${onConflict}` : void 0;
32466
+ const onConflictSql = onConflict?.length ? sql.join(onConflict) : void 0;
32277
32467
  return sql`${withSql}insert into ${table5} ${insertOrder} ${valuesSql}${onConflictSql}${returningSql}`;
32278
32468
  }
32279
32469
  sqlToQuery(sql2, invokeSource) {
@@ -33220,22 +33410,26 @@ var init_query_builder3 = __esm({
33220
33410
  constructor(dialect6) {
33221
33411
  __publicField(this, "dialect");
33222
33412
  __publicField(this, "dialectConfig");
33223
- this.dialect = is(dialect6, SQLiteDialect) ? dialect6 : void 0;
33224
- this.dialectConfig = is(dialect6, SQLiteDialect) ? void 0 : dialect6;
33225
- }
33226
- $with(alias) {
33227
- const queryBuilder = this;
33228
- return {
33229
- as(qb) {
33413
+ __publicField(this, "$with", (alias, selection) => {
33414
+ const queryBuilder = this;
33415
+ const as = (qb) => {
33230
33416
  if (typeof qb === "function") {
33231
33417
  qb = qb(queryBuilder);
33232
33418
  }
33233
33419
  return new Proxy(
33234
- new WithSubquery(qb.getSQL(), qb.getSelectedFields(), alias, true),
33420
+ new WithSubquery(
33421
+ qb.getSQL(),
33422
+ selection ?? ("getSelectedFields" in qb ? qb.getSelectedFields() ?? {} : {}),
33423
+ alias,
33424
+ true
33425
+ ),
33235
33426
  new SelectionProxyHandler({ alias, sqlAliasedBehavior: "alias", sqlBehavior: "error" })
33236
33427
  );
33237
- }
33238
- };
33428
+ };
33429
+ return { as };
33430
+ });
33431
+ this.dialect = is(dialect6, SQLiteDialect) ? dialect6 : void 0;
33432
+ this.dialectConfig = is(dialect6, SQLiteDialect) ? void 0 : dialect6;
33239
33433
  }
33240
33434
  with(...queries) {
33241
33435
  const self2 = this;
@@ -33376,12 +33570,14 @@ var init_insert2 = __esm({
33376
33570
  * ```
33377
33571
  */
33378
33572
  onConflictDoNothing(config = {}) {
33573
+ if (!this.config.onConflict)
33574
+ this.config.onConflict = [];
33379
33575
  if (config.target === void 0) {
33380
- this.config.onConflict = sql`do nothing`;
33576
+ this.config.onConflict.push(sql` on conflict do nothing`);
33381
33577
  } else {
33382
33578
  const targetSql = Array.isArray(config.target) ? sql`${config.target}` : sql`${[config.target]}`;
33383
33579
  const whereSql = config.where ? sql` where ${config.where}` : sql``;
33384
- this.config.onConflict = sql`${targetSql} do nothing${whereSql}`;
33580
+ this.config.onConflict.push(sql` on conflict ${targetSql} do nothing${whereSql}`);
33385
33581
  }
33386
33582
  return this;
33387
33583
  }
@@ -33420,12 +33616,16 @@ var init_insert2 = __esm({
33420
33616
  'You cannot use both "where" and "targetWhere"/"setWhere" at the same time - "where" is deprecated, use "targetWhere" or "setWhere" instead.'
33421
33617
  );
33422
33618
  }
33619
+ if (!this.config.onConflict)
33620
+ this.config.onConflict = [];
33423
33621
  const whereSql = config.where ? sql` where ${config.where}` : void 0;
33424
33622
  const targetWhereSql = config.targetWhere ? sql` where ${config.targetWhere}` : void 0;
33425
33623
  const setWhereSql = config.setWhere ? sql` where ${config.setWhere}` : void 0;
33426
33624
  const targetSql = Array.isArray(config.target) ? sql`${config.target}` : sql`${[config.target]}`;
33427
33625
  const setSql = this.dialect.buildUpdateSet(this.config.table, mapUpdateSet(this.config.table, config.set));
33428
- this.config.onConflict = sql`${targetSql}${targetWhereSql} do update set ${setSql}${whereSql}${setWhereSql}`;
33626
+ this.config.onConflict.push(
33627
+ sql` on conflict ${targetSql}${targetWhereSql} do update set ${setSql}${whereSql}${setWhereSql}`
33628
+ );
33429
33629
  return this;
33430
33630
  }
33431
33631
  /** @internal */
@@ -33916,6 +34116,56 @@ var init_db2 = __esm({
33916
34116
  BaseSQLiteDatabase = class {
33917
34117
  constructor(resultKind, dialect6, session, schema5) {
33918
34118
  __publicField(this, "query");
34119
+ /**
34120
+ * Creates a subquery that defines a temporary named result set as a CTE.
34121
+ *
34122
+ * It is useful for breaking down complex queries into simpler parts and for reusing the result set in subsequent parts of the query.
34123
+ *
34124
+ * See docs: {@link https://orm.drizzle.team/docs/select#with-clause}
34125
+ *
34126
+ * @param alias The alias for the subquery.
34127
+ *
34128
+ * Failure to provide an alias will result in a DrizzleTypeError, preventing the subquery from being referenced in other queries.
34129
+ *
34130
+ * @example
34131
+ *
34132
+ * ```ts
34133
+ * // Create a subquery with alias 'sq' and use it in the select query
34134
+ * const sq = db.$with('sq').as(db.select().from(users).where(eq(users.id, 42)));
34135
+ *
34136
+ * const result = await db.with(sq).select().from(sq);
34137
+ * ```
34138
+ *
34139
+ * To select arbitrary SQL values as fields in a CTE and reference them in other CTEs or in the main query, you need to add aliases to them:
34140
+ *
34141
+ * ```ts
34142
+ * // Select an arbitrary SQL value as a field in a CTE and reference it in the main query
34143
+ * const sq = db.$with('sq').as(db.select({
34144
+ * name: sql<string>`upper(${users.name})`.as('name'),
34145
+ * })
34146
+ * .from(users));
34147
+ *
34148
+ * const result = await db.with(sq).select({ name: sq.name }).from(sq);
34149
+ * ```
34150
+ */
34151
+ __publicField(this, "$with", (alias, selection) => {
34152
+ const self2 = this;
34153
+ const as = (qb) => {
34154
+ if (typeof qb === "function") {
34155
+ qb = qb(new QueryBuilder2(self2.dialect));
34156
+ }
34157
+ return new Proxy(
34158
+ new WithSubquery(
34159
+ qb.getSQL(),
34160
+ selection ?? ("getSelectedFields" in qb ? qb.getSelectedFields() ?? {} : {}),
34161
+ alias,
34162
+ true
34163
+ ),
34164
+ new SelectionProxyHandler({ alias, sqlAliasedBehavior: "alias", sqlBehavior: "error" })
34165
+ );
34166
+ };
34167
+ return { as };
34168
+ });
33919
34169
  this.resultKind = resultKind;
33920
34170
  this.dialect = dialect6;
33921
34171
  this.session = session;
@@ -33945,52 +34195,6 @@ var init_db2 = __esm({
33945
34195
  }
33946
34196
  }
33947
34197
  }
33948
- /**
33949
- * Creates a subquery that defines a temporary named result set as a CTE.
33950
- *
33951
- * It is useful for breaking down complex queries into simpler parts and for reusing the result set in subsequent parts of the query.
33952
- *
33953
- * See docs: {@link https://orm.drizzle.team/docs/select#with-clause}
33954
- *
33955
- * @param alias The alias for the subquery.
33956
- *
33957
- * Failure to provide an alias will result in a DrizzleTypeError, preventing the subquery from being referenced in other queries.
33958
- *
33959
- * @example
33960
- *
33961
- * ```ts
33962
- * // Create a subquery with alias 'sq' and use it in the select query
33963
- * const sq = db.$with('sq').as(db.select().from(users).where(eq(users.id, 42)));
33964
- *
33965
- * const result = await db.with(sq).select().from(sq);
33966
- * ```
33967
- *
33968
- * To select arbitrary SQL values as fields in a CTE and reference them in other CTEs or in the main query, you need to add aliases to them:
33969
- *
33970
- * ```ts
33971
- * // Select an arbitrary SQL value as a field in a CTE and reference it in the main query
33972
- * const sq = db.$with('sq').as(db.select({
33973
- * name: sql<string>`upper(${users.name})`.as('name'),
33974
- * })
33975
- * .from(users));
33976
- *
33977
- * const result = await db.with(sq).select({ name: sq.name }).from(sq);
33978
- * ```
33979
- */
33980
- $with(alias) {
33981
- const self2 = this;
33982
- return {
33983
- as(qb) {
33984
- if (typeof qb === "function") {
33985
- qb = qb(new QueryBuilder2(self2.dialect));
33986
- }
33987
- return new Proxy(
33988
- new WithSubquery(qb.getSQL(), qb.getSelectedFields(), alias, true),
33989
- new SelectionProxyHandler({ alias, sqlAliasedBehavior: "alias", sqlBehavior: "error" })
33990
- );
33991
- }
33992
- };
33993
- }
33994
34198
  $count(source, filters) {
33995
34199
  return new SQLiteCountBuilder({ source, filters, session: this.session });
33996
34200
  }
@@ -38813,22 +39017,26 @@ var init_query_builder4 = __esm({
38813
39017
  constructor(dialect6) {
38814
39018
  __publicField(this, "dialect");
38815
39019
  __publicField(this, "dialectConfig");
38816
- this.dialect = is(dialect6, MySqlDialect) ? dialect6 : void 0;
38817
- this.dialectConfig = is(dialect6, MySqlDialect) ? void 0 : dialect6;
38818
- }
38819
- $with(alias) {
38820
- const queryBuilder = this;
38821
- return {
38822
- as(qb) {
39020
+ __publicField(this, "$with", (alias, selection) => {
39021
+ const queryBuilder = this;
39022
+ const as = (qb) => {
38823
39023
  if (typeof qb === "function") {
38824
39024
  qb = qb(queryBuilder);
38825
39025
  }
38826
39026
  return new Proxy(
38827
- new WithSubquery(qb.getSQL(), qb.getSelectedFields(), alias, true),
39027
+ new WithSubquery(
39028
+ qb.getSQL(),
39029
+ selection ?? ("getSelectedFields" in qb ? qb.getSelectedFields() ?? {} : {}),
39030
+ alias,
39031
+ true
39032
+ ),
38828
39033
  new SelectionProxyHandler({ alias, sqlAliasedBehavior: "alias", sqlBehavior: "error" })
38829
39034
  );
38830
- }
38831
- };
39035
+ };
39036
+ return { as };
39037
+ });
39038
+ this.dialect = is(dialect6, MySqlDialect) ? dialect6 : void 0;
39039
+ this.dialectConfig = is(dialect6, MySqlDialect) ? void 0 : dialect6;
38832
39040
  }
38833
39041
  with(...queries) {
38834
39042
  const self2 = this;
@@ -39283,6 +39491,56 @@ var init_db3 = __esm({
39283
39491
  MySqlDatabase = class {
39284
39492
  constructor(dialect6, session, schema5, mode) {
39285
39493
  __publicField(this, "query");
39494
+ /**
39495
+ * Creates a subquery that defines a temporary named result set as a CTE.
39496
+ *
39497
+ * It is useful for breaking down complex queries into simpler parts and for reusing the result set in subsequent parts of the query.
39498
+ *
39499
+ * See docs: {@link https://orm.drizzle.team/docs/select#with-clause}
39500
+ *
39501
+ * @param alias The alias for the subquery.
39502
+ *
39503
+ * Failure to provide an alias will result in a DrizzleTypeError, preventing the subquery from being referenced in other queries.
39504
+ *
39505
+ * @example
39506
+ *
39507
+ * ```ts
39508
+ * // Create a subquery with alias 'sq' and use it in the select query
39509
+ * const sq = db.$with('sq').as(db.select().from(users).where(eq(users.id, 42)));
39510
+ *
39511
+ * const result = await db.with(sq).select().from(sq);
39512
+ * ```
39513
+ *
39514
+ * To select arbitrary SQL values as fields in a CTE and reference them in other CTEs or in the main query, you need to add aliases to them:
39515
+ *
39516
+ * ```ts
39517
+ * // Select an arbitrary SQL value as a field in a CTE and reference it in the main query
39518
+ * const sq = db.$with('sq').as(db.select({
39519
+ * name: sql<string>`upper(${users.name})`.as('name'),
39520
+ * })
39521
+ * .from(users));
39522
+ *
39523
+ * const result = await db.with(sq).select({ name: sq.name }).from(sq);
39524
+ * ```
39525
+ */
39526
+ __publicField(this, "$with", (alias, selection) => {
39527
+ const self2 = this;
39528
+ const as = (qb) => {
39529
+ if (typeof qb === "function") {
39530
+ qb = qb(new QueryBuilder3(self2.dialect));
39531
+ }
39532
+ return new Proxy(
39533
+ new WithSubquery(
39534
+ qb.getSQL(),
39535
+ selection ?? ("getSelectedFields" in qb ? qb.getSelectedFields() ?? {} : {}),
39536
+ alias,
39537
+ true
39538
+ ),
39539
+ new SelectionProxyHandler({ alias, sqlAliasedBehavior: "alias", sqlBehavior: "error" })
39540
+ );
39541
+ };
39542
+ return { as };
39543
+ });
39286
39544
  this.dialect = dialect6;
39287
39545
  this.session = session;
39288
39546
  this.mode = mode;
@@ -39311,52 +39569,6 @@ var init_db3 = __esm({
39311
39569
  }
39312
39570
  }
39313
39571
  }
39314
- /**
39315
- * Creates a subquery that defines a temporary named result set as a CTE.
39316
- *
39317
- * It is useful for breaking down complex queries into simpler parts and for reusing the result set in subsequent parts of the query.
39318
- *
39319
- * See docs: {@link https://orm.drizzle.team/docs/select#with-clause}
39320
- *
39321
- * @param alias The alias for the subquery.
39322
- *
39323
- * Failure to provide an alias will result in a DrizzleTypeError, preventing the subquery from being referenced in other queries.
39324
- *
39325
- * @example
39326
- *
39327
- * ```ts
39328
- * // Create a subquery with alias 'sq' and use it in the select query
39329
- * const sq = db.$with('sq').as(db.select().from(users).where(eq(users.id, 42)));
39330
- *
39331
- * const result = await db.with(sq).select().from(sq);
39332
- * ```
39333
- *
39334
- * To select arbitrary SQL values as fields in a CTE and reference them in other CTEs or in the main query, you need to add aliases to them:
39335
- *
39336
- * ```ts
39337
- * // Select an arbitrary SQL value as a field in a CTE and reference it in the main query
39338
- * const sq = db.$with('sq').as(db.select({
39339
- * name: sql<string>`upper(${users.name})`.as('name'),
39340
- * })
39341
- * .from(users));
39342
- *
39343
- * const result = await db.with(sq).select({ name: sq.name }).from(sq);
39344
- * ```
39345
- */
39346
- $with(alias) {
39347
- const self2 = this;
39348
- return {
39349
- as(qb) {
39350
- if (typeof qb === "function") {
39351
- qb = qb(new QueryBuilder3(self2.dialect));
39352
- }
39353
- return new Proxy(
39354
- new WithSubquery(qb.getSQL(), qb.getSelectedFields(), alias, true),
39355
- new SelectionProxyHandler({ alias, sqlAliasedBehavior: "alias", sqlBehavior: "error" })
39356
- );
39357
- }
39358
- };
39359
- }
39360
39572
  $count(source, filters) {
39361
39573
  return new MySqlCountBuilder({ source, filters, session: this.session });
39362
39574
  }
@@ -43912,22 +44124,26 @@ var init_query_builder5 = __esm({
43912
44124
  constructor(dialect6) {
43913
44125
  __publicField(this, "dialect");
43914
44126
  __publicField(this, "dialectConfig");
43915
- this.dialect = is(dialect6, SingleStoreDialect) ? dialect6 : void 0;
43916
- this.dialectConfig = is(dialect6, SingleStoreDialect) ? void 0 : dialect6;
43917
- }
43918
- $with(alias) {
43919
- const queryBuilder = this;
43920
- return {
43921
- as(qb) {
44127
+ __publicField(this, "$with", (alias, selection) => {
44128
+ const queryBuilder = this;
44129
+ const as = (qb) => {
43922
44130
  if (typeof qb === "function") {
43923
44131
  qb = qb(queryBuilder);
43924
44132
  }
43925
44133
  return new Proxy(
43926
- new WithSubquery(qb.getSQL(), qb.getSelectedFields(), alias, true),
44134
+ new WithSubquery(
44135
+ qb.getSQL(),
44136
+ selection ?? ("getSelectedFields" in qb ? qb.getSelectedFields() ?? {} : {}),
44137
+ alias,
44138
+ true
44139
+ ),
43927
44140
  new SelectionProxyHandler({ alias, sqlAliasedBehavior: "alias", sqlBehavior: "error" })
43928
44141
  );
43929
- }
43930
- };
44142
+ };
44143
+ return { as };
44144
+ });
44145
+ this.dialect = is(dialect6, SingleStoreDialect) ? dialect6 : void 0;
44146
+ this.dialectConfig = is(dialect6, SingleStoreDialect) ? void 0 : dialect6;
43931
44147
  }
43932
44148
  with(...queries) {
43933
44149
  const self2 = this;
@@ -44140,6 +44356,56 @@ var init_db4 = __esm({
44140
44356
  // We are waiting for SingleStore support for `json_array` function
44141
44357
  /**@inrernal */
44142
44358
  __publicField(this, "query");
44359
+ /**
44360
+ * Creates a subquery that defines a temporary named result set as a CTE.
44361
+ *
44362
+ * It is useful for breaking down complex queries into simpler parts and for reusing the result set in subsequent parts of the query.
44363
+ *
44364
+ * See docs: {@link https://orm.drizzle.team/docs/select#with-clause}
44365
+ *
44366
+ * @param alias The alias for the subquery.
44367
+ *
44368
+ * Failure to provide an alias will result in a DrizzleTypeError, preventing the subquery from being referenced in other queries.
44369
+ *
44370
+ * @example
44371
+ *
44372
+ * ```ts
44373
+ * // Create a subquery with alias 'sq' and use it in the select query
44374
+ * const sq = db.$with('sq').as(db.select().from(users).where(eq(users.id, 42)));
44375
+ *
44376
+ * const result = await db.with(sq).select().from(sq);
44377
+ * ```
44378
+ *
44379
+ * To select arbitrary SQL values as fields in a CTE and reference them in other CTEs or in the main query, you need to add aliases to them:
44380
+ *
44381
+ * ```ts
44382
+ * // Select an arbitrary SQL value as a field in a CTE and reference it in the main query
44383
+ * const sq = db.$with('sq').as(db.select({
44384
+ * name: sql<string>`upper(${users.name})`.as('name'),
44385
+ * })
44386
+ * .from(users));
44387
+ *
44388
+ * const result = await db.with(sq).select({ name: sq.name }).from(sq);
44389
+ * ```
44390
+ */
44391
+ __publicField(this, "$with", (alias, selection) => {
44392
+ const self2 = this;
44393
+ const as = (qb) => {
44394
+ if (typeof qb === "function") {
44395
+ qb = qb(new QueryBuilder4(self2.dialect));
44396
+ }
44397
+ return new Proxy(
44398
+ new WithSubquery(
44399
+ qb.getSQL(),
44400
+ selection ?? ("getSelectedFields" in qb ? qb.getSelectedFields() ?? {} : {}),
44401
+ alias,
44402
+ true
44403
+ ),
44404
+ new SelectionProxyHandler({ alias, sqlAliasedBehavior: "alias", sqlBehavior: "error" })
44405
+ );
44406
+ };
44407
+ return { as };
44408
+ });
44143
44409
  this.dialect = dialect6;
44144
44410
  this.session = session;
44145
44411
  this._ = schema5 ? {
@@ -44153,52 +44419,6 @@ var init_db4 = __esm({
44153
44419
  };
44154
44420
  this.query = {};
44155
44421
  }
44156
- /**
44157
- * Creates a subquery that defines a temporary named result set as a CTE.
44158
- *
44159
- * It is useful for breaking down complex queries into simpler parts and for reusing the result set in subsequent parts of the query.
44160
- *
44161
- * See docs: {@link https://orm.drizzle.team/docs/select#with-clause}
44162
- *
44163
- * @param alias The alias for the subquery.
44164
- *
44165
- * Failure to provide an alias will result in a DrizzleTypeError, preventing the subquery from being referenced in other queries.
44166
- *
44167
- * @example
44168
- *
44169
- * ```ts
44170
- * // Create a subquery with alias 'sq' and use it in the select query
44171
- * const sq = db.$with('sq').as(db.select().from(users).where(eq(users.id, 42)));
44172
- *
44173
- * const result = await db.with(sq).select().from(sq);
44174
- * ```
44175
- *
44176
- * To select arbitrary SQL values as fields in a CTE and reference them in other CTEs or in the main query, you need to add aliases to them:
44177
- *
44178
- * ```ts
44179
- * // Select an arbitrary SQL value as a field in a CTE and reference it in the main query
44180
- * const sq = db.$with('sq').as(db.select({
44181
- * name: sql<string>`upper(${users.name})`.as('name'),
44182
- * })
44183
- * .from(users));
44184
- *
44185
- * const result = await db.with(sq).select({ name: sq.name }).from(sq);
44186
- * ```
44187
- */
44188
- $with(alias) {
44189
- const self2 = this;
44190
- return {
44191
- as(qb) {
44192
- if (typeof qb === "function") {
44193
- qb = qb(new QueryBuilder4(self2.dialect));
44194
- }
44195
- return new Proxy(
44196
- new WithSubquery(qb.getSQL(), qb.getSelectedFields(), alias, true),
44197
- new SelectionProxyHandler({ alias, sqlAliasedBehavior: "alias", sqlBehavior: "error" })
44198
- );
44199
- }
44200
- };
44201
- }
44202
44422
  $count(source, filters) {
44203
44423
  return new SingleStoreCountBuilder({ source, filters, session: this.session });
44204
44424
  }
@@ -45469,15 +45689,31 @@ var init_singlestoreImports = __esm({
45469
45689
  var singlestorePushUtils_exports = {};
45470
45690
  __export(singlestorePushUtils_exports, {
45471
45691
  filterStatements: () => filterStatements2,
45692
+ findColumnTypeAlternations: () => findColumnTypeAlternations,
45472
45693
  logSuggestionsAndReturn: () => logSuggestionsAndReturn3
45473
45694
  });
45695
+ function findColumnTypeAlternations(columns1, columns2) {
45696
+ const changes = [];
45697
+ for (const key in columns1) {
45698
+ if (columns1.hasOwnProperty(key) && columns2.hasOwnProperty(key)) {
45699
+ const col1 = columns1[key];
45700
+ const col2 = columns2[key];
45701
+ if (col1.type !== col2.type) {
45702
+ changes.push(col2.name);
45703
+ }
45704
+ }
45705
+ }
45706
+ return changes;
45707
+ }
45474
45708
  var import_hanji10, filterStatements2, logSuggestionsAndReturn3;
45475
45709
  var init_singlestorePushUtils = __esm({
45476
45710
  "src/cli/commands/singlestorePushUtils.ts"() {
45477
45711
  "use strict";
45478
45712
  init_source();
45479
45713
  import_hanji10 = __toESM(require_hanji());
45714
+ init_sqlgenerator();
45480
45715
  init_singlestoreSchema();
45716
+ init_utils();
45481
45717
  init_selector_ui();
45482
45718
  init_outputs();
45483
45719
  filterStatements2 = (statements, currentSchema, prevSchema) => {
@@ -45521,7 +45757,7 @@ var init_singlestorePushUtils = __esm({
45521
45757
  return true;
45522
45758
  });
45523
45759
  };
45524
- logSuggestionsAndReturn3 = async (db, statements, json22) => {
45760
+ logSuggestionsAndReturn3 = async (db, statements, json22, json1) => {
45525
45761
  let shouldAskForApprove = false;
45526
45762
  const statementsToExecute = [];
45527
45763
  const infoToPrint = [];
@@ -45702,6 +45938,71 @@ var init_singlestorePushUtils = __esm({
45702
45938
  shouldAskForApprove = true;
45703
45939
  }
45704
45940
  }
45941
+ } else if (statement.type === "singlestore_recreate_table") {
45942
+ const tableName = statement.tableName;
45943
+ const prevColumns = json1.tables[tableName].columns;
45944
+ const currentColumns = json22.tables[tableName].columns;
45945
+ const { removedColumns, addedColumns } = findAddedAndRemoved(
45946
+ Object.keys(prevColumns),
45947
+ Object.keys(currentColumns)
45948
+ );
45949
+ if (removedColumns.length) {
45950
+ for (const removedColumn of removedColumns) {
45951
+ const res = await db.query(
45952
+ `select count(\`${tableName}\`.\`${removedColumn}\`) as count from \`${tableName}\``
45953
+ );
45954
+ const count2 = Number(res[0].count);
45955
+ if (count2 > 0) {
45956
+ infoToPrint.push(
45957
+ `\xB7 You're about to delete ${source_default.underline(
45958
+ removedColumn
45959
+ )} column in ${tableName} table with ${count2} items`
45960
+ );
45961
+ columnsToRemove.push(removedColumn);
45962
+ shouldAskForApprove = true;
45963
+ }
45964
+ }
45965
+ }
45966
+ if (addedColumns.length) {
45967
+ for (const addedColumn of addedColumns) {
45968
+ const [res] = await db.query(
45969
+ `select count(*) as count from \`${tableName}\``
45970
+ );
45971
+ const columnConf = json22.tables[tableName].columns[addedColumn];
45972
+ const count2 = Number(res.count);
45973
+ if (count2 > 0 && columnConf.notNull && !columnConf.default) {
45974
+ infoToPrint.push(
45975
+ `\xB7 You're about to add not-null ${source_default.underline(
45976
+ addedColumn
45977
+ )} column without default value to table, which contains ${count2} items`
45978
+ );
45979
+ shouldAskForApprove = true;
45980
+ tablesToTruncate.push(tableName);
45981
+ statementsToExecute.push(`TRUNCATE TABLE \`${tableName}\`;`);
45982
+ }
45983
+ }
45984
+ }
45985
+ const columnWithChangedType = findColumnTypeAlternations(prevColumns, currentColumns);
45986
+ for (const column5 of columnWithChangedType) {
45987
+ const [res] = await db.query(
45988
+ `select count(*) as count from \`${tableName}\` WHERE \`${tableName}\`.\`${column5}\` IS NOT NULL;`
45989
+ );
45990
+ const count2 = Number(res.count);
45991
+ if (count2 > 0) {
45992
+ infoToPrint.push(
45993
+ `\xB7 You're about recreate ${source_default.underline(tableName)} table with data type changing for ${source_default.underline(
45994
+ column5
45995
+ )} column, which contains ${count2} items`
45996
+ );
45997
+ shouldAskForApprove = true;
45998
+ tablesToTruncate.push(tableName);
45999
+ statementsToExecute.push(`TRUNCATE TABLE \`${tableName}\`;`);
46000
+ }
46001
+ }
46002
+ }
46003
+ const stmnt = fromJson([statement], "singlestore", "push");
46004
+ if (typeof stmnt !== "undefined") {
46005
+ statementsToExecute.push(...stmnt);
45705
46006
  }
45706
46007
  }
45707
46008
  return {
@@ -46547,7 +46848,8 @@ var pushSingleStoreSchema = async (imports, drizzleInstance, databaseName) => {
46547
46848
  const { shouldAskForApprove, statementsToExecute, infoToPrint } = await logSuggestionsAndReturn4(
46548
46849
  db,
46549
46850
  statements,
46550
- validatedCur
46851
+ validatedCur,
46852
+ validatedPrev
46551
46853
  );
46552
46854
  return {
46553
46855
  hasDataLoss: shouldAskForApprove,