drizzle-kit 0.20.1 → 0.20.2-8e648e0

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.
package/utils.js CHANGED
@@ -1043,7 +1043,7 @@ var require_hanji = __commonJS({
1043
1043
  }
1044
1044
  };
1045
1045
  exports.TaskTerminal = TaskTerminal;
1046
- function render5(view) {
1046
+ function render6(view) {
1047
1047
  const { stdin, stdout, closable } = (0, readline_1.prepareReadLine)();
1048
1048
  if (view instanceof Prompt3) {
1049
1049
  const terminal = new Terminal(view, stdin, stdout, closable);
@@ -1055,8 +1055,8 @@ var require_hanji = __commonJS({
1055
1055
  closable.close();
1056
1056
  return;
1057
1057
  }
1058
- exports.render = render5;
1059
- function renderWithTask3(view, task) {
1058
+ exports.render = render6;
1059
+ function renderWithTask4(view, task) {
1060
1060
  return __awaiter(this, void 0, void 0, function* () {
1061
1061
  const terminal = new TaskTerminal(view, process.stdout);
1062
1062
  terminal.requestLayout();
@@ -1065,7 +1065,7 @@ var require_hanji = __commonJS({
1065
1065
  return result;
1066
1066
  });
1067
1067
  }
1068
- exports.renderWithTask = renderWithTask3;
1068
+ exports.renderWithTask = renderWithTask4;
1069
1069
  var terminateHandler;
1070
1070
  function onTerminate(callback) {
1071
1071
  terminateHandler = callback;
@@ -11180,14 +11180,30 @@ var init_utils = __esm({
11180
11180
  // src/serializer/mysqlImports.ts
11181
11181
  var mysqlImports_exports = {};
11182
11182
  __export(mysqlImports_exports, {
11183
+ prepareFromExports: () => prepareFromExports,
11183
11184
  prepareFromMySqlImports: () => prepareFromMySqlImports
11184
11185
  });
11185
- var import_mysql_core, import_drizzle_orm, prepareFromMySqlImports;
11186
+ var import_mysql_core, import_drizzle_orm, prepareFromExports, prepareFromMySqlImports;
11186
11187
  var init_mysqlImports = __esm({
11187
11188
  "src/serializer/mysqlImports.ts"() {
11188
11189
  import_mysql_core = require("drizzle-orm/mysql-core");
11189
11190
  import_drizzle_orm = require("drizzle-orm");
11190
11191
  init_utils();
11192
+ prepareFromExports = (exports) => {
11193
+ const tables = [];
11194
+ const enums = [];
11195
+ const schemas = [];
11196
+ const i0values = Object.values(exports);
11197
+ i0values.forEach((t) => {
11198
+ if ((0, import_drizzle_orm.is)(t, import_mysql_core.MySqlTable)) {
11199
+ tables.push(t);
11200
+ }
11201
+ if ((0, import_drizzle_orm.is)(t, import_mysql_core.MySqlSchema)) {
11202
+ schemas.push(t);
11203
+ }
11204
+ });
11205
+ return { tables, enums, schemas };
11206
+ };
11191
11207
  prepareFromMySqlImports = async (imports) => {
11192
11208
  const tables = [];
11193
11209
  const enums = [];
@@ -11196,15 +11212,10 @@ var init_mysqlImports = __esm({
11196
11212
  for (let i = 0; i < imports.length; i++) {
11197
11213
  const it = imports[i];
11198
11214
  const i0 = require(`${it}`);
11199
- const i0values = Object.values(i0);
11200
- i0values.forEach((t) => {
11201
- if ((0, import_drizzle_orm.is)(t, import_mysql_core.MySqlTable)) {
11202
- tables.push(t);
11203
- }
11204
- if ((0, import_drizzle_orm.is)(t, import_mysql_core.MySqlSchema)) {
11205
- schemas.push(t);
11206
- }
11207
- });
11215
+ const prepared = prepareFromExports(i0);
11216
+ tables.push(...prepared.tables);
11217
+ enums.push(...prepared.enums);
11218
+ schemas.push(...prepared.schemas);
11208
11219
  }
11209
11220
  unregister();
11210
11221
  return { tables, enums, schemas };
@@ -11497,21 +11508,20 @@ We have encountered a collision between the index name on columns ${source_defau
11497
11508
  fromDatabase = async (db, inputSchema, tablesFilter = (table4) => true, progressCallback) => {
11498
11509
  const result = {};
11499
11510
  const internals = { tables: {} };
11500
- const columns = await db.execute(`select * from information_schema.columns
11511
+ const columns = await db.query(`select * from information_schema.columns
11501
11512
  where table_schema = '${inputSchema}' and table_name != '__drizzle_migrations'
11502
11513
  order by table_name, ordinal_position;`);
11503
- const response = columns[0];
11514
+ const response = columns;
11504
11515
  const schemas = [];
11505
11516
  let columnsCount = 0;
11506
11517
  let tablesCount = /* @__PURE__ */ new Set();
11507
11518
  let indexesCount = 0;
11508
11519
  let foreignKeysCount = 0;
11509
- const idxs = await db.execute(
11520
+ const idxs = await db.query(
11510
11521
  `select * from INFORMATION_SCHEMA.STATISTICS
11511
- WHERE INFORMATION_SCHEMA.STATISTICS.TABLE_SCHEMA = ? and INFORMATION_SCHEMA.STATISTICS.INDEX_NAME != 'PRIMARY';`,
11512
- [inputSchema]
11522
+ WHERE INFORMATION_SCHEMA.STATISTICS.TABLE_SCHEMA = '${inputSchema}' and INFORMATION_SCHEMA.STATISTICS.INDEX_NAME != 'PRIMARY';`
11513
11523
  );
11514
- const idxRows = idxs[0];
11524
+ const idxRows = idxs;
11515
11525
  for (const column5 of response) {
11516
11526
  if (!tablesFilter(column5["TABLE_NAME"]))
11517
11527
  continue;
@@ -11604,19 +11614,18 @@ We have encountered a collision between the index name on columns ${source_defau
11604
11614
  result[tableName].columns[columnName] = newColumn;
11605
11615
  }
11606
11616
  }
11607
- const tablePks = await db.execute(
11617
+ const tablePks = await db.query(
11608
11618
  `SELECT table_name, column_name, ordinal_position
11609
11619
  FROM information_schema.table_constraints t
11610
11620
  LEFT JOIN information_schema.key_column_usage k
11611
11621
  USING(constraint_name,table_schema,table_name)
11612
11622
  WHERE t.constraint_type='PRIMARY KEY'
11613
11623
  and table_name != '__drizzle_migrations'
11614
- AND t.table_schema = ?
11615
- ORDER BY ordinal_position`,
11616
- [inputSchema]
11624
+ AND t.table_schema = '${inputSchema}'
11625
+ ORDER BY ordinal_position`
11617
11626
  );
11618
11627
  const tableToPk = {};
11619
- const tableToPkRows = tablePks[0];
11628
+ const tableToPkRows = tablePks;
11620
11629
  for (const tableToPkRow of tableToPkRows) {
11621
11630
  const tableName = tableToPkRow["TABLE_NAME"];
11622
11631
  const columnName = tableToPkRow["COLUMN_NAME"];
@@ -11643,15 +11652,14 @@ We have encountered a collision between the index name on columns ${source_defau
11643
11652
  progressCallback("tables", tablesCount.size, "done");
11644
11653
  }
11645
11654
  try {
11646
- const fks = await db.execute(
11655
+ const fks = await db.query(
11647
11656
  `SELECT INFORMATION_SCHEMA.KEY_COLUMN_USAGE.TABLE_SCHEMA,INFORMATION_SCHEMA.KEY_COLUMN_USAGE.TABLE_NAME,INFORMATION_SCHEMA.KEY_COLUMN_USAGE.CONSTRAINT_NAME,INFORMATION_SCHEMA.KEY_COLUMN_USAGE.COLUMN_NAME,INFORMATION_SCHEMA.KEY_COLUMN_USAGE.REFERENCED_TABLE_SCHEMA,INFORMATION_SCHEMA.KEY_COLUMN_USAGE.REFERENCED_TABLE_NAME, INFORMATION_SCHEMA.KEY_COLUMN_USAGE.REFERENCED_COLUMN_NAME,information_schema.referential_constraints.UPDATE_RULE, information_schema.referential_constraints.DELETE_RULE
11648
11657
  FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE
11649
11658
  LEFT JOIN information_schema.referential_constraints on information_schema.referential_constraints.constraint_name = information_schema.KEY_COLUMN_USAGE.CONSTRAINT_NAME
11650
- WHERE INFORMATION_SCHEMA.KEY_COLUMN_USAGE.TABLE_SCHEMA = ? AND INFORMATION_SCHEMA.KEY_COLUMN_USAGE.CONSTRAINT_NAME != 'PRIMARY' and INFORMATION_SCHEMA.KEY_COLUMN_USAGE.REFERENCED_TABLE_NAME is not null;
11651
- `,
11652
- [inputSchema]
11659
+ WHERE INFORMATION_SCHEMA.KEY_COLUMN_USAGE.TABLE_SCHEMA = '${inputSchema}' AND INFORMATION_SCHEMA.KEY_COLUMN_USAGE.CONSTRAINT_NAME != 'PRIMARY' and INFORMATION_SCHEMA.KEY_COLUMN_USAGE.REFERENCED_TABLE_NAME is not null;
11660
+ `
11653
11661
  );
11654
- const fkRows = fks[0];
11662
+ const fkRows = fks;
11655
11663
  for (const fkRow of fkRows) {
11656
11664
  foreignKeysCount += 1;
11657
11665
  if (progressCallback) {
@@ -11759,16 +11767,16 @@ We have encountered a collision between the index name on columns ${source_defau
11759
11767
  // src/serializer/pgImports.ts
11760
11768
  var pgImports_exports = {};
11761
11769
  __export(pgImports_exports, {
11762
- prepareFromExports: () => prepareFromExports,
11770
+ prepareFromExports: () => prepareFromExports2,
11763
11771
  prepareFromPgImports: () => prepareFromPgImports
11764
11772
  });
11765
- var import_pg_core, import_drizzle_orm4, prepareFromExports, prepareFromPgImports;
11773
+ var import_pg_core, import_drizzle_orm4, prepareFromExports2, prepareFromPgImports;
11766
11774
  var init_pgImports = __esm({
11767
11775
  "src/serializer/pgImports.ts"() {
11768
11776
  import_pg_core = require("drizzle-orm/pg-core");
11769
11777
  import_drizzle_orm4 = require("drizzle-orm");
11770
11778
  init_utils();
11771
- prepareFromExports = (exports) => {
11779
+ prepareFromExports2 = (exports) => {
11772
11780
  const tables = [];
11773
11781
  const enums = [];
11774
11782
  const schemas = [];
@@ -11795,10 +11803,10 @@ var init_pgImports = __esm({
11795
11803
  for (let i = 0; i < imports.length; i++) {
11796
11804
  const it = imports[i];
11797
11805
  const i0 = require(`${it}`);
11798
- const prepared = prepareFromExports(i0);
11799
- tables = prepared.tables;
11800
- enums = prepared.enums;
11801
- schemas = prepared.schemas;
11806
+ const prepared = prepareFromExports2(i0);
11807
+ tables.push(...prepared.tables);
11808
+ enums.push(...prepared.enums);
11809
+ schemas.push(...prepared.schemas);
11802
11810
  }
11803
11811
  unregister();
11804
11812
  return { tables, enums, schemas };
@@ -12532,14 +12540,26 @@ ${withStyle.errorWarning(`We've found duplicated unique constraint names in ${so
12532
12540
  // src/serializer/sqliteImports.ts
12533
12541
  var sqliteImports_exports = {};
12534
12542
  __export(sqliteImports_exports, {
12543
+ prepareFromExports: () => prepareFromExports3,
12535
12544
  prepareFromSqliteImports: () => prepareFromSqliteImports
12536
12545
  });
12537
- var import_sqlite_core, import_drizzle_orm6, prepareFromSqliteImports;
12546
+ var import_sqlite_core, import_drizzle_orm6, prepareFromExports3, prepareFromSqliteImports;
12538
12547
  var init_sqliteImports = __esm({
12539
12548
  "src/serializer/sqliteImports.ts"() {
12540
12549
  import_sqlite_core = require("drizzle-orm/sqlite-core");
12541
12550
  import_drizzle_orm6 = require("drizzle-orm");
12542
12551
  init_utils();
12552
+ prepareFromExports3 = (exports) => {
12553
+ const tables = [];
12554
+ const enums = [];
12555
+ const i0values = Object.values(exports);
12556
+ i0values.forEach((t) => {
12557
+ if ((0, import_drizzle_orm6.is)(t, import_sqlite_core.SQLiteTable)) {
12558
+ tables.push(t);
12559
+ }
12560
+ });
12561
+ return { tables, enums };
12562
+ };
12543
12563
  prepareFromSqliteImports = async (imports) => {
12544
12564
  const tables = [];
12545
12565
  const enums = [];
@@ -12547,12 +12567,9 @@ var init_sqliteImports = __esm({
12547
12567
  for (let i = 0; i < imports.length; i++) {
12548
12568
  const it = imports[i];
12549
12569
  const i0 = require(`${it}`);
12550
- const i0values = Object.values(i0);
12551
- i0values.forEach((t) => {
12552
- if ((0, import_drizzle_orm6.is)(t, import_sqlite_core.SQLiteTable)) {
12553
- tables.push(t);
12554
- }
12555
- });
12570
+ const prepared = prepareFromExports3(i0);
12571
+ tables.push(...prepared.tables);
12572
+ enums.push(...prepared.enums);
12556
12573
  }
12557
12574
  unregister();
12558
12575
  return { tables, enums };
@@ -22466,7 +22483,7 @@ var require_connection = __commonJS({
22466
22483
  var flushBuffer = serialize.flush();
22467
22484
  var syncBuffer = serialize.sync();
22468
22485
  var endBuffer = serialize.end();
22469
- var Connection = class extends EventEmitter {
22486
+ var Connection2 = class extends EventEmitter {
22470
22487
  constructor(config) {
22471
22488
  super();
22472
22489
  config = config || {};
@@ -22636,7 +22653,7 @@ var require_connection = __commonJS({
22636
22653
  this._send(serialize.copyFail(msg));
22637
22654
  }
22638
22655
  };
22639
- module2.exports = Connection;
22656
+ module2.exports = Connection2;
22640
22657
  }
22641
22658
  });
22642
22659
 
@@ -22945,7 +22962,7 @@ var require_client = __commonJS({
22945
22962
  var ConnectionParameters = require_connection_parameters();
22946
22963
  var Query = require_query();
22947
22964
  var defaults3 = require_defaults();
22948
- var Connection = require_connection();
22965
+ var Connection2 = require_connection();
22949
22966
  var crypto = require_utils3();
22950
22967
  var Client2 = class extends EventEmitter {
22951
22968
  constructor(config) {
@@ -22971,7 +22988,7 @@ var require_client = __commonJS({
22971
22988
  this._connected = false;
22972
22989
  this._connectionError = false;
22973
22990
  this._queryable = true;
22974
- this.connection = c.connection || new Connection({
22991
+ this.connection = c.connection || new Connection2({
22975
22992
  stream: c.stream,
22976
22993
  ssl: this.connectionParameters.ssl,
22977
22994
  keepAlive: c.keepAlive || false,
@@ -24226,7 +24243,7 @@ var require_lib2 = __commonJS({
24226
24243
  "use strict";
24227
24244
  var Client2 = require_client();
24228
24245
  var defaults3 = require_defaults();
24229
- var Connection = require_connection();
24246
+ var Connection2 = require_connection();
24230
24247
  var Pool = require_pg_pool();
24231
24248
  var { DatabaseError } = require_dist();
24232
24249
  var { escapeIdentifier, escapeLiteral } = require_utils2();
@@ -24243,7 +24260,7 @@ var require_lib2 = __commonJS({
24243
24260
  this.Query = this.Client.Query;
24244
24261
  this.Pool = poolFactory(this.Client);
24245
24262
  this._pools = [];
24246
- this.Connection = Connection;
24263
+ this.Connection = Connection2;
24247
24264
  this.types = require_pg_types();
24248
24265
  this.DatabaseError = DatabaseError;
24249
24266
  this.escapeIdentifier = escapeIdentifier;
@@ -24280,11 +24297,14 @@ var drivers_exports = {};
24280
24297
  __export(drivers_exports, {
24281
24298
  BetterSqlite: () => BetterSqlite,
24282
24299
  DrizzleDbClient: () => DrizzleDbClient,
24300
+ DrizzleORMMySQLClient: () => DrizzleORMMySQLClient,
24283
24301
  DrizzleORMPgClient: () => DrizzleORMPgClient,
24302
+ DrizzleORMSQLiteClient: () => DrizzleORMSQLiteClient,
24303
+ MySQL2Client: () => MySQL2Client,
24284
24304
  PgPostgres: () => PgPostgres,
24285
24305
  TursoSqlite: () => TursoSqlite
24286
24306
  });
24287
- var import_drizzle_orm8, DrizzleDbClient, DrizzleORMPgClient, BetterSqlite, TursoSqlite, PgPostgres;
24307
+ var import_drizzle_orm8, DrizzleDbClient, DrizzleORMPgClient, DrizzleORMMySQLClient, DrizzleORMSQLiteClient, BetterSqlite, MySQL2Client, TursoSqlite, PgPostgres;
24288
24308
  var init_drivers = __esm({
24289
24309
  "src/drivers/index.ts"() {
24290
24310
  import_drizzle_orm8 = require("drizzle-orm");
@@ -24303,6 +24323,24 @@ var init_drivers = __esm({
24303
24323
  return res.rows;
24304
24324
  }
24305
24325
  };
24326
+ DrizzleORMMySQLClient = class extends DrizzleDbClient {
24327
+ async query(query, values) {
24328
+ const res = await this.db.execute(import_drizzle_orm8.sql.raw(query));
24329
+ return res[0];
24330
+ }
24331
+ async run(query) {
24332
+ await this.db.execute(import_drizzle_orm8.sql.raw(query));
24333
+ }
24334
+ };
24335
+ DrizzleORMSQLiteClient = class extends DrizzleDbClient {
24336
+ async query(query, values) {
24337
+ const res = this.db.all(import_drizzle_orm8.sql.raw(query));
24338
+ return res;
24339
+ }
24340
+ async run(query) {
24341
+ this.db.run(import_drizzle_orm8.sql.raw(query));
24342
+ }
24343
+ };
24306
24344
  BetterSqlite = class extends DrizzleDbClient {
24307
24345
  async run(query) {
24308
24346
  this.db.prepare(query).run();
@@ -24311,6 +24349,15 @@ var init_drivers = __esm({
24311
24349
  return this.db.prepare(query).all();
24312
24350
  }
24313
24351
  };
24352
+ MySQL2Client = class extends DrizzleDbClient {
24353
+ async run(query) {
24354
+ await this.db.execute(query);
24355
+ }
24356
+ async query(query) {
24357
+ const res = await this.db.execute(query);
24358
+ return res[0];
24359
+ }
24360
+ };
24314
24361
  TursoSqlite = class extends DrizzleDbClient {
24315
24362
  async run(query) {
24316
24363
  await this.db.execute(query);
@@ -37515,8 +37562,8 @@ var require_prepare = __commonJS({
37515
37562
  this.options = options;
37516
37563
  }
37517
37564
  start(packet, connection) {
37518
- const Connection = connection.constructor;
37519
- this.key = Connection.statementKey(this.options);
37565
+ const Connection2 = connection.constructor;
37566
+ this.key = Connection2.statementKey(this.options);
37520
37567
  const statement = connection._statements.get(this.key);
37521
37568
  if (statement) {
37522
37569
  if (this.onResult) {
@@ -39455,7 +39502,7 @@ var require_connection2 = __commonJS({
39455
39502
  var CharsetToEncoding = require_charset_encodings();
39456
39503
  var _connectionId = 0;
39457
39504
  var convertNamedPlaceholders = null;
39458
- var Connection = class _Connection extends EventEmitter {
39505
+ var Connection2 = class _Connection extends EventEmitter {
39459
39506
  constructor(opts) {
39460
39507
  super();
39461
39508
  this.config = opts.config;
@@ -40179,7 +40226,7 @@ var require_connection2 = __commonJS({
40179
40226
  };
40180
40227
  if (Tls.TLSSocket) {
40181
40228
  } else {
40182
- Connection.prototype.startTLS = function _startTLS(onSecure) {
40229
+ Connection2.prototype.startTLS = function _startTLS(onSecure) {
40183
40230
  if (this.config.debug) {
40184
40231
  console.log("Upgrading connection to TLS");
40185
40232
  }
@@ -40217,7 +40264,7 @@ var require_connection2 = __commonJS({
40217
40264
  });
40218
40265
  };
40219
40266
  }
40220
- module2.exports = Connection;
40267
+ module2.exports = Connection2;
40221
40268
  }
40222
40269
  });
40223
40270
 
@@ -40225,8 +40272,8 @@ var require_connection2 = __commonJS({
40225
40272
  var require_pool_connection = __commonJS({
40226
40273
  "node_modules/.pnpm/mysql2@2.3.3/node_modules/mysql2/lib/pool_connection.js"(exports, module2) {
40227
40274
  "use strict";
40228
- var Connection = require_mysql2().Connection;
40229
- var PoolConnection = class extends Connection {
40275
+ var Connection2 = require_mysql2().Connection;
40276
+ var PoolConnection = class extends Connection2 {
40230
40277
  constructor(pool, options) {
40231
40278
  super(options);
40232
40279
  this._pool = pool;
@@ -40268,9 +40315,9 @@ var require_pool_connection = __commonJS({
40268
40315
  pool._removeConnection(this);
40269
40316
  }
40270
40317
  };
40271
- PoolConnection.statementKey = Connection.statementKey;
40318
+ PoolConnection.statementKey = Connection2.statementKey;
40272
40319
  module2.exports = PoolConnection;
40273
- PoolConnection.prototype._realEnd = Connection.prototype.end;
40320
+ PoolConnection.prototype._realEnd = Connection2.prototype.end;
40274
40321
  }
40275
40322
  });
40276
40323
 
@@ -40283,7 +40330,7 @@ var require_pool = __commonJS({
40283
40330
  var EventEmitter = require("events").EventEmitter;
40284
40331
  var PoolConnection = require_pool_connection();
40285
40332
  var Queue = require_denque();
40286
- var Connection = require_connection2();
40333
+ var Connection2 = require_connection2();
40287
40334
  function spliceConnection(queue, connection) {
40288
40335
  const len = queue.length;
40289
40336
  for (let i = 0; i < len; i++) {
@@ -40390,7 +40437,7 @@ var require_pool = __commonJS({
40390
40437
  }
40391
40438
  }
40392
40439
  query(sql2, values, cb) {
40393
- const cmdQuery = Connection.createQuery(
40440
+ const cmdQuery = Connection2.createQuery(
40394
40441
  sql2,
40395
40442
  values,
40396
40443
  cb,
@@ -40493,7 +40540,7 @@ var require_pool_cluster = __commonJS({
40493
40540
  var process4 = require("process");
40494
40541
  var Pool = require_pool();
40495
40542
  var PoolConfig = require_pool_config();
40496
- var Connection = require_connection2();
40543
+ var Connection2 = require_connection2();
40497
40544
  var EventEmitter = require("events").EventEmitter;
40498
40545
  var makeSelector = {
40499
40546
  RR() {
@@ -40536,7 +40583,7 @@ var require_pool_cluster = __commonJS({
40536
40583
  * @returns query
40537
40584
  */
40538
40585
  query(sql2, values, cb) {
40539
- const query = Connection.createQuery(sql2, values, cb, {});
40586
+ const query = Connection2.createQuery(sql2, values, cb, {});
40540
40587
  this.getConnection((err2, conn) => {
40541
40588
  if (err2) {
40542
40589
  if (typeof query.onResult === "function") {
@@ -40742,7 +40789,7 @@ var require_server = __commonJS({
40742
40789
  "use strict";
40743
40790
  var net = require("net");
40744
40791
  var EventEmitter = require("events").EventEmitter;
40745
- var Connection = require_connection2();
40792
+ var Connection2 = require_connection2();
40746
40793
  var ConnectionConfig = require_connection_config();
40747
40794
  var Server = class extends EventEmitter {
40748
40795
  constructor() {
@@ -40755,7 +40802,7 @@ var require_server = __commonJS({
40755
40802
  stream: socket,
40756
40803
  isServer: true
40757
40804
  });
40758
- const connection = new Connection({ config: connectionConfig });
40805
+ const connection = new Connection2({ config: connectionConfig });
40759
40806
  this.emit("connection", connection);
40760
40807
  }
40761
40808
  listen(port) {
@@ -40776,14 +40823,14 @@ var require_mysql2 = __commonJS({
40776
40823
  "node_modules/.pnpm/mysql2@2.3.3/node_modules/mysql2/index.js"(exports) {
40777
40824
  "use strict";
40778
40825
  var SqlString = require_sqlstring();
40779
- var Connection = require_connection2();
40826
+ var Connection2 = require_connection2();
40780
40827
  var ConnectionConfig = require_connection_config();
40781
40828
  var parserCache = require_parser_cache();
40782
40829
  exports.createConnection = function(opts) {
40783
- return new Connection({ config: new ConnectionConfig(opts) });
40830
+ return new Connection2({ config: new ConnectionConfig(opts) });
40784
40831
  };
40785
40832
  exports.connect = exports.createConnection;
40786
- exports.Connection = Connection;
40833
+ exports.Connection = Connection2;
40787
40834
  var Pool = require_pool();
40788
40835
  var PoolCluster = require_pool_cluster();
40789
40836
  exports.createPool = function(config) {
@@ -40794,7 +40841,7 @@ var require_mysql2 = __commonJS({
40794
40841
  const PoolCluster2 = require_pool_cluster();
40795
40842
  return new PoolCluster2(config);
40796
40843
  };
40797
- exports.createQuery = Connection.createQuery;
40844
+ exports.createQuery = Connection2.createQuery;
40798
40845
  exports.Pool = Pool;
40799
40846
  exports.PoolCluster = PoolCluster;
40800
40847
  exports.createServer = function(handler) {
@@ -41058,7 +41105,7 @@ var require_promise = __commonJS({
41058
41105
  return this.connection.threadId;
41059
41106
  }
41060
41107
  };
41061
- function createConnection(opts) {
41108
+ function createConnection2(opts) {
41062
41109
  const coreConnection = core.createConnection(opts);
41063
41110
  const createConnectionErr = new Error();
41064
41111
  const thePromise = opts.Promise || Promise;
@@ -41311,7 +41358,7 @@ var require_promise = __commonJS({
41311
41358
  }
41312
41359
  return new PromisePoolCluster(corePoolCluster, thePromise);
41313
41360
  }
41314
- exports.createConnection = createConnection;
41361
+ exports.createConnection = createConnection2;
41315
41362
  exports.createPool = createPool;
41316
41363
  exports.createPoolCluster = createPoolCluster;
41317
41364
  exports.escape = core.escape;
@@ -56889,6 +56936,567 @@ var init_studioUtils = __esm({
56889
56936
  }
56890
56937
  });
56891
56938
 
56939
+ // src/cli/commands/sqlitePushUtils.ts
56940
+ var _moveDataStatements, getOldTableName, getNewTableName, logSuggestionsAndReturn;
56941
+ var init_sqlitePushUtils = __esm({
56942
+ "src/cli/commands/sqlitePushUtils.ts"() {
56943
+ init_source();
56944
+ init_sqliteSchema();
56945
+ init_sqlgenerator();
56946
+ _moveDataStatements = (tableName, json, dataLoss = false) => {
56947
+ const statements = [];
56948
+ statements.push(
56949
+ new SqliteRenameTableConvertor().convert({
56950
+ type: "rename_table",
56951
+ tableNameFrom: tableName,
56952
+ tableNameTo: `__old_push_${tableName}`,
56953
+ fromSchema: "",
56954
+ toSchema: ""
56955
+ })
56956
+ );
56957
+ const tableColumns = Object.values(json.tables[tableName].columns);
56958
+ const referenceData = Object.values(json.tables[tableName].foreignKeys);
56959
+ const compositePKs = Object.values(
56960
+ json.tables[tableName].compositePrimaryKeys
56961
+ ).map((it) => SQLiteSquasher.unsquashPK(it));
56962
+ statements.push(
56963
+ new SQLiteCreateTableConvertor().convert({
56964
+ type: "sqlite_create_table",
56965
+ tableName,
56966
+ columns: tableColumns,
56967
+ referenceData,
56968
+ compositePKs
56969
+ })
56970
+ );
56971
+ if (!dataLoss) {
56972
+ statements.push(
56973
+ `INSERT INTO "${tableName}" SELECT * FROM "__old_push_${tableName}";`
56974
+ );
56975
+ }
56976
+ statements.push(
56977
+ new SQLiteDropTableConvertor().convert({
56978
+ type: "drop_table",
56979
+ tableName: `__old_push_${tableName}`,
56980
+ schema: ""
56981
+ })
56982
+ );
56983
+ for (const idx of Object.values(json.tables[tableName].indexes)) {
56984
+ statements.push(
56985
+ new CreateSqliteIndexConvertor().convert({
56986
+ type: "create_index",
56987
+ tableName,
56988
+ schema: "",
56989
+ data: idx
56990
+ })
56991
+ );
56992
+ }
56993
+ return statements;
56994
+ };
56995
+ getOldTableName = (tableName, meta) => {
56996
+ for (const key of Object.keys(meta.tables)) {
56997
+ const value = meta.tables[key];
56998
+ if (`"${tableName}"` === value) {
56999
+ return key.substring(1, key.length - 1);
57000
+ }
57001
+ }
57002
+ return tableName;
57003
+ };
57004
+ getNewTableName = (tableName, meta) => {
57005
+ if (typeof meta.tables[`"${tableName}"`] !== "undefined") {
57006
+ return meta.tables[`"${tableName}"`].substring(
57007
+ 1,
57008
+ meta.tables[`"${tableName}"`].length - 1
57009
+ );
57010
+ }
57011
+ return tableName;
57012
+ };
57013
+ logSuggestionsAndReturn = async ({
57014
+ connection,
57015
+ statements,
57016
+ json1,
57017
+ json2,
57018
+ meta
57019
+ }) => {
57020
+ let shouldAskForApprove = false;
57021
+ const statementsToExecute = [];
57022
+ const infoToPrint = [];
57023
+ const tablesToRemove = [];
57024
+ const columnsToRemove = [];
57025
+ const schemasToRemove = [];
57026
+ const tablesToTruncate = [];
57027
+ const tablesContext = {};
57028
+ for (const statement of statements) {
57029
+ if (statement.type === "drop_table") {
57030
+ const res = await connection.query(
57031
+ `select count(*) as count from \`${statement.tableName}\``
57032
+ );
57033
+ const count = Number(res[0].count);
57034
+ if (count > 0) {
57035
+ infoToPrint.push(
57036
+ `\xB7 You're about to delete ${source_default.underline(
57037
+ statement.tableName
57038
+ )} table with ${count} items`
57039
+ );
57040
+ tablesToRemove.push(statement.tableName);
57041
+ shouldAskForApprove = true;
57042
+ }
57043
+ const stmnt = fromJson([statement], "sqlite")[0];
57044
+ statementsToExecute.push(stmnt);
57045
+ } else if (statement.type === "alter_table_drop_column") {
57046
+ const newTableName = getOldTableName(statement.tableName, meta);
57047
+ const columnIsPartOfPk = Object.values(
57048
+ json1.tables[newTableName].compositePrimaryKeys
57049
+ ).find(
57050
+ (c) => SQLiteSquasher.unsquashPK(c).includes(statement.columnName)
57051
+ );
57052
+ const columnIsPartOfIndex = Object.values(
57053
+ json1.tables[newTableName].indexes
57054
+ ).find(
57055
+ (c) => SQLiteSquasher.unsquashIdx(c).columns.includes(statement.columnName)
57056
+ );
57057
+ const columnIsPk = json1.tables[newTableName].columns[statement.columnName].primaryKey;
57058
+ const columnIsPartOfFk = Object.values(
57059
+ json1.tables[newTableName].foreignKeys
57060
+ ).find(
57061
+ (t) => SQLiteSquasher.unsquashFK(t).columnsFrom.includes(statement.columnName)
57062
+ );
57063
+ const res = await connection.query(
57064
+ `select count(*) as count from \`${newTableName}\``
57065
+ );
57066
+ const count = Number(res[0].count);
57067
+ if (count > 0) {
57068
+ infoToPrint.push(
57069
+ `\xB7 You're about to delete ${source_default.underline(
57070
+ statement.columnName
57071
+ )} column in ${newTableName} table with ${count} items`
57072
+ );
57073
+ columnsToRemove.push(`${newTableName}_${statement.columnName}`);
57074
+ shouldAskForApprove = true;
57075
+ }
57076
+ if (columnIsPk || columnIsPartOfPk || columnIsPartOfIndex || columnIsPartOfFk) {
57077
+ tablesContext[newTableName] = [
57078
+ ..._moveDataStatements(statement.tableName, json2, true)
57079
+ ];
57080
+ const tablesReferncingCurrent = [];
57081
+ for (const table4 of Object.values(json1.tables)) {
57082
+ const tablesRefs = Object.values(json1.tables[table4.name].foreignKeys).filter(
57083
+ (t) => SQLiteSquasher.unsquashFK(t).tableTo === newTableName
57084
+ ).map((t) => SQLiteSquasher.unsquashFK(t).tableFrom);
57085
+ tablesReferncingCurrent.push(...tablesRefs);
57086
+ }
57087
+ const uniqueTableRefs = [...new Set(tablesReferncingCurrent)];
57088
+ for (const table4 of uniqueTableRefs) {
57089
+ if (typeof tablesContext[table4] === "undefined") {
57090
+ tablesContext[table4] = [..._moveDataStatements(table4, json2)];
57091
+ }
57092
+ }
57093
+ } else {
57094
+ if (typeof tablesContext[newTableName] === "undefined") {
57095
+ const stmnt = fromJson([statement], "sqlite")[0];
57096
+ statementsToExecute.push(stmnt);
57097
+ }
57098
+ }
57099
+ } else if (statement.type === "sqlite_alter_table_add_column") {
57100
+ const newTableName = getOldTableName(statement.tableName, meta);
57101
+ if (statement.column.notNull && !statement.column.default) {
57102
+ const res = await connection.query(
57103
+ `select count(*) as count from \`${newTableName}\``
57104
+ );
57105
+ const count = Number(res[0].count);
57106
+ if (count > 0) {
57107
+ infoToPrint.push(
57108
+ `\xB7 You're about to add not-null ${source_default.underline(
57109
+ statement.column.name
57110
+ )} column without default value, which contains ${count} items`
57111
+ );
57112
+ tablesToTruncate.push(newTableName);
57113
+ statementsToExecute.push(`delete from ${newTableName};`);
57114
+ shouldAskForApprove = true;
57115
+ }
57116
+ }
57117
+ if (statement.column.primaryKey) {
57118
+ tablesContext[newTableName] = [
57119
+ ..._moveDataStatements(statement.tableName, json2, true)
57120
+ ];
57121
+ const tablesReferncingCurrent = [];
57122
+ for (const table4 of Object.values(json1.tables)) {
57123
+ const tablesRefs = Object.values(json1.tables[table4.name].foreignKeys).filter(
57124
+ (t) => SQLiteSquasher.unsquashFK(t).tableTo === newTableName
57125
+ ).map((t) => SQLiteSquasher.unsquashFK(t).tableFrom);
57126
+ tablesReferncingCurrent.push(...tablesRefs);
57127
+ }
57128
+ const uniqueTableRefs = [...new Set(tablesReferncingCurrent)];
57129
+ for (const table4 of uniqueTableRefs) {
57130
+ if (typeof tablesContext[table4] === "undefined") {
57131
+ tablesContext[table4] = [..._moveDataStatements(table4, json2)];
57132
+ }
57133
+ }
57134
+ } else {
57135
+ if (typeof tablesContext[newTableName] === "undefined") {
57136
+ const stmnt = fromJson([statement], "sqlite")[0];
57137
+ statementsToExecute.push(stmnt);
57138
+ }
57139
+ }
57140
+ } else if (statement.type === "alter_table_alter_column_set_type" || statement.type === "alter_table_alter_column_set_default" || statement.type === "alter_table_alter_column_drop_default" || 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") {
57141
+ const newTableName = getOldTableName(statement.tableName, meta);
57142
+ if (statement.type === "alter_table_alter_column_set_notnull" && typeof statement.columnDefault === "undefined") {
57143
+ const res = await connection.query(
57144
+ `select count(*) as count from \`${newTableName}\``
57145
+ );
57146
+ const count = Number(res[0].count);
57147
+ if (count > 0) {
57148
+ infoToPrint.push(
57149
+ `\xB7 You're about to add not-null constraint to ${source_default.underline(
57150
+ statement.columnName
57151
+ )} column without default value, which contains ${count} items`
57152
+ );
57153
+ tablesToTruncate.push(newTableName);
57154
+ shouldAskForApprove = true;
57155
+ }
57156
+ tablesContext[newTableName] = _moveDataStatements(
57157
+ statement.tableName,
57158
+ json2,
57159
+ true
57160
+ );
57161
+ } else {
57162
+ if (typeof tablesContext[newTableName] === "undefined") {
57163
+ tablesContext[newTableName] = _moveDataStatements(
57164
+ statement.tableName,
57165
+ json2
57166
+ );
57167
+ }
57168
+ }
57169
+ const tablesReferncingCurrent = [];
57170
+ for (const table4 of Object.values(json1.tables)) {
57171
+ const tablesRefs = Object.values(json1.tables[table4.name].foreignKeys).filter((t) => SQLiteSquasher.unsquashFK(t).tableTo === newTableName).map((t) => {
57172
+ return getNewTableName(
57173
+ SQLiteSquasher.unsquashFK(t).tableFrom,
57174
+ meta
57175
+ );
57176
+ });
57177
+ tablesReferncingCurrent.push(...tablesRefs);
57178
+ }
57179
+ const uniqueTableRefs = [...new Set(tablesReferncingCurrent)];
57180
+ for (const table4 of uniqueTableRefs) {
57181
+ if (typeof tablesContext[table4] === "undefined") {
57182
+ tablesContext[table4] = [..._moveDataStatements(table4, json2)];
57183
+ }
57184
+ }
57185
+ } else if (statement.type === "create_reference" || statement.type === "delete_reference" || statement.type === "alter_reference") {
57186
+ const fk4 = SQLiteSquasher.unsquashFK(statement.data);
57187
+ if (typeof tablesContext[statement.tableName] === "undefined") {
57188
+ tablesContext[statement.tableName] = _moveDataStatements(
57189
+ statement.tableName,
57190
+ json2
57191
+ );
57192
+ }
57193
+ } else if (statement.type === "create_composite_pk" || statement.type === "alter_composite_pk" || statement.type === "delete_composite_pk" || statement.type === "create_unique_constraint" || statement.type === "delete_unique_constraint") {
57194
+ const newTableName = getOldTableName(statement.tableName, meta);
57195
+ if (typeof tablesContext[newTableName] === "undefined") {
57196
+ tablesContext[newTableName] = _moveDataStatements(
57197
+ statement.tableName,
57198
+ json2
57199
+ );
57200
+ }
57201
+ } else {
57202
+ const stmnt = fromJson([statement], "sqlite")[0];
57203
+ if (typeof stmnt !== "undefined") {
57204
+ statementsToExecute.push(stmnt);
57205
+ }
57206
+ }
57207
+ }
57208
+ for (const context of Object.values(tablesContext)) {
57209
+ statementsToExecute.push(...context);
57210
+ }
57211
+ return {
57212
+ statementsToExecute,
57213
+ shouldAskForApprove,
57214
+ infoToPrint,
57215
+ columnsToRemove: [...new Set(columnsToRemove)],
57216
+ schemasToRemove: [...new Set(schemasToRemove)],
57217
+ tablesToTruncate: [...new Set(tablesToTruncate)],
57218
+ tablesToRemove: [...new Set(tablesToRemove)]
57219
+ };
57220
+ };
57221
+ }
57222
+ });
57223
+
57224
+ // src/mysql-introspect.ts
57225
+ var init_mysql_introspect = __esm({
57226
+ "src/mysql-introspect.ts"() {
57227
+ init_utils2();
57228
+ init_mysqlSerializer();
57229
+ }
57230
+ });
57231
+
57232
+ // src/cli/commands/mysqlIntrospect.ts
57233
+ var import_hanji8, import_promise, mysqlPushIntrospect;
57234
+ var init_mysqlIntrospect = __esm({
57235
+ "src/cli/commands/mysqlIntrospect.ts"() {
57236
+ import_hanji8 = __toESM(require_hanji());
57237
+ init_views();
57238
+ import_promise = __toESM(require_promise());
57239
+ init_mysqlSerializer();
57240
+ init_mysql_introspect();
57241
+ init_global();
57242
+ init_mjs();
57243
+ init_drivers();
57244
+ mysqlPushIntrospect = async (connection, filters) => {
57245
+ const { client, databaseName } = connection;
57246
+ const matchers = filters.map((it) => {
57247
+ return new Minimatch(it);
57248
+ });
57249
+ const filter2 = (tableName) => {
57250
+ if (matchers.length === 0)
57251
+ return true;
57252
+ for (let i = 0; i < matchers.length; i++) {
57253
+ const matcher = matchers[i];
57254
+ if (matcher.match(tableName))
57255
+ return true;
57256
+ }
57257
+ return false;
57258
+ };
57259
+ const res = await fromDatabase(client, databaseName, filter2);
57260
+ const schema4 = { id: originUUID, prevId: "", ...res };
57261
+ const { internal, ...schemaWithoutInternals } = schema4;
57262
+ return { schema: schemaWithoutInternals };
57263
+ };
57264
+ }
57265
+ });
57266
+
57267
+ // src/cli/commands/mysqlPushUtils.ts
57268
+ var mysqlPushUtils_exports = {};
57269
+ __export(mysqlPushUtils_exports, {
57270
+ filterStatements: () => filterStatements,
57271
+ logSuggestionsAndReturn: () => logSuggestionsAndReturn2
57272
+ });
57273
+ var import_hanji9, filterStatements, logSuggestionsAndReturn2;
57274
+ var init_mysqlPushUtils = __esm({
57275
+ "src/cli/commands/mysqlPushUtils.ts"() {
57276
+ init_source();
57277
+ import_hanji9 = __toESM(require_hanji());
57278
+ init_mysqlSchema();
57279
+ init_selector_ui();
57280
+ filterStatements = (statements, currentSchema, prevSchema) => {
57281
+ return statements.filter((statement) => {
57282
+ if (statement.type === "alter_table_alter_column_set_type") {
57283
+ if (statement.oldDataType.startsWith("tinyint") && statement.newDataType.startsWith("boolean")) {
57284
+ return false;
57285
+ }
57286
+ if (statement.oldDataType.startsWith("bigint unsigned") && statement.newDataType.startsWith("serial")) {
57287
+ return false;
57288
+ }
57289
+ if (statement.oldDataType.startsWith("serial") && statement.newDataType.startsWith("bigint unsigned")) {
57290
+ return false;
57291
+ }
57292
+ } else if (statement.type === "alter_table_alter_column_set_default") {
57293
+ if (statement.newDefaultValue === false && statement.oldDefaultValue === 0 && statement.newDataType === "boolean") {
57294
+ return false;
57295
+ }
57296
+ if (statement.newDefaultValue === true && statement.oldDefaultValue === 1 && statement.newDataType === "boolean") {
57297
+ return false;
57298
+ }
57299
+ } else if (statement.type === "delete_unique_constraint") {
57300
+ const unsquashed = MySqlSquasher.unsquashUnique(statement.data);
57301
+ if (unsquashed.columns.length === 1 && currentSchema.tables[statement.tableName].columns[unsquashed.columns[0]].type === "serial" && prevSchema.tables[statement.tableName].columns[unsquashed.columns[0]].type === "serial" && currentSchema.tables[statement.tableName].columns[unsquashed.columns[0]].name === unsquashed.columns[0]) {
57302
+ return false;
57303
+ }
57304
+ } else if (statement.type === "alter_table_alter_column_drop_notnull") {
57305
+ const serialStatement = statements.find(
57306
+ (it) => it.type === "alter_table_alter_column_set_type"
57307
+ );
57308
+ if ((serialStatement == null ? void 0 : serialStatement.oldDataType.startsWith("bigint unsigned")) && (serialStatement == null ? void 0 : serialStatement.newDataType.startsWith("serial")) && serialStatement.columnName === statement.columnName && serialStatement.tableName === statement.tableName) {
57309
+ return false;
57310
+ }
57311
+ if (statement.newDataType === "serial" && !statement.columnNotNull) {
57312
+ return false;
57313
+ }
57314
+ if (statement.columnAutoIncrement) {
57315
+ return false;
57316
+ }
57317
+ }
57318
+ return true;
57319
+ });
57320
+ };
57321
+ logSuggestionsAndReturn2 = async ({
57322
+ connection,
57323
+ statements
57324
+ }) => {
57325
+ let shouldAskForApprove = false;
57326
+ const statementsToExecute = [];
57327
+ const infoToPrint = [];
57328
+ const tablesToRemove = [];
57329
+ const columnsToRemove = [];
57330
+ const schemasToRemove = [];
57331
+ const tablesToTruncate = [];
57332
+ for (const statement of statements) {
57333
+ if (statement.type === "drop_table") {
57334
+ const res = await connection.query(
57335
+ `select count(*) as count from \`${statement.tableName}\``
57336
+ );
57337
+ const count = Number(res[0].count);
57338
+ if (count > 0) {
57339
+ infoToPrint.push(
57340
+ `\xB7 You're about to delete ${source_default.underline(
57341
+ statement.tableName
57342
+ )} table with ${count} items`
57343
+ );
57344
+ tablesToRemove.push(statement.tableName);
57345
+ shouldAskForApprove = true;
57346
+ }
57347
+ } else if (statement.type === "alter_table_drop_column") {
57348
+ const res = await connection.query(
57349
+ `select count(*) as count from \`${statement.tableName}\``
57350
+ );
57351
+ const count = Number(res[0].count);
57352
+ if (count > 0) {
57353
+ infoToPrint.push(
57354
+ `\xB7 You're about to delete ${source_default.underline(
57355
+ statement.columnName
57356
+ )} column in ${statement.tableName} table with ${count} items`
57357
+ );
57358
+ columnsToRemove.push(`${statement.tableName}_${statement.columnName}`);
57359
+ shouldAskForApprove = true;
57360
+ }
57361
+ } else if (statement.type === "drop_schema") {
57362
+ const res = await connection.query(
57363
+ `select count(*) as count from information_schema.tables where table_schema = \`${statement.name}\`;`
57364
+ );
57365
+ const count = Number(res[0].count);
57366
+ if (count > 0) {
57367
+ infoToPrint.push(
57368
+ `\xB7 You're about to delete ${source_default.underline(
57369
+ statement.name
57370
+ )} schema with ${count} tables`
57371
+ );
57372
+ schemasToRemove.push(statement.name);
57373
+ shouldAskForApprove = true;
57374
+ }
57375
+ } else if (statement.type === "alter_table_alter_column_set_type") {
57376
+ const res = await connection.query(
57377
+ `select count(*) as count from \`${statement.tableName}\``
57378
+ );
57379
+ const count = Number(res[0].count);
57380
+ if (count > 0) {
57381
+ infoToPrint.push(
57382
+ `\xB7 You're about to change ${source_default.underline(
57383
+ statement.columnName
57384
+ )} column type from ${source_default.underline(
57385
+ statement.oldDataType
57386
+ )} to ${source_default.underline(statement.newDataType)} with ${count} items`
57387
+ );
57388
+ statementsToExecute.push(`truncate table ${statement.tableName};`);
57389
+ tablesToTruncate.push(statement.tableName);
57390
+ shouldAskForApprove = true;
57391
+ }
57392
+ } else if (statement.type === "alter_table_alter_column_drop_default") {
57393
+ if (statement.columnNotNull) {
57394
+ const res = await connection.query(
57395
+ `select count(*) as count from \`${statement.tableName}\``
57396
+ );
57397
+ const count = Number(res[0].count);
57398
+ if (count > 0) {
57399
+ infoToPrint.push(
57400
+ `\xB7 You're about to remove default value from ${source_default.underline(
57401
+ statement.columnName
57402
+ )} not-null column with ${count} items`
57403
+ );
57404
+ tablesToTruncate.push(statement.tableName);
57405
+ statementsToExecute.push(`truncate table ${statement.tableName};`);
57406
+ shouldAskForApprove = true;
57407
+ }
57408
+ }
57409
+ shouldAskForApprove = true;
57410
+ } else if (statement.type === "alter_table_alter_column_set_notnull") {
57411
+ if (typeof statement.columnDefault === "undefined") {
57412
+ const res = await connection.query(
57413
+ `select count(*) as count from \`${statement.tableName}\``
57414
+ );
57415
+ const count = Number(res[0].count);
57416
+ if (count > 0) {
57417
+ infoToPrint.push(
57418
+ `\xB7 You're about to set not-null constraint to ${source_default.underline(
57419
+ statement.columnName
57420
+ )} column without default, which contains ${count} items`
57421
+ );
57422
+ tablesToTruncate.push(statement.tableName);
57423
+ statementsToExecute.push(`truncate table ${statement.tableName};`);
57424
+ shouldAskForApprove = true;
57425
+ }
57426
+ }
57427
+ } else if (statement.type === "alter_table_alter_column_drop_pk") {
57428
+ const res = await connection.query(
57429
+ `select count(*) as count from \`${statement.tableName}\``
57430
+ );
57431
+ const count = Number(res[0].count);
57432
+ if (count > 0) {
57433
+ infoToPrint.push(
57434
+ `\xB7 You're about to change ${source_default.underline(
57435
+ statement.tableName
57436
+ )} primary key. This statements may fail and you table may left without primary key`
57437
+ );
57438
+ tablesToTruncate.push(statement.tableName);
57439
+ shouldAskForApprove = true;
57440
+ }
57441
+ } else if (statement.type === "alter_table_add_column") {
57442
+ if (statement.column.notNull && typeof statement.column.default === "undefined") {
57443
+ const res = await connection.query(
57444
+ `select count(*) as count from \`${statement.tableName}\``
57445
+ );
57446
+ const count = Number(res[0].count);
57447
+ if (count > 0) {
57448
+ infoToPrint.push(
57449
+ `\xB7 You're about to add not-null ${source_default.underline(
57450
+ statement.column.name
57451
+ )} column without default value, which contains ${count} items`
57452
+ );
57453
+ tablesToTruncate.push(statement.tableName);
57454
+ statementsToExecute.push(`truncate table ${statement.tableName};`);
57455
+ shouldAskForApprove = true;
57456
+ }
57457
+ }
57458
+ } else if (statement.type === "create_unique_constraint") {
57459
+ const res = await connection.query(
57460
+ `select count(*) as count from \`${statement.tableName}\``
57461
+ );
57462
+ const count = Number(res[0].count);
57463
+ if (count > 0) {
57464
+ const unsquashedUnique = MySqlSquasher.unsquashUnique(statement.data);
57465
+ console.log(
57466
+ `\xB7 You're about to add ${source_default.underline(
57467
+ unsquashedUnique.name
57468
+ )} unique constraint to the table, which contains ${count} items. If this statement fails, you will receive an error from the database. Do you want to truncate ${source_default.underline(
57469
+ statement.tableName
57470
+ )} table?
57471
+ `
57472
+ );
57473
+ const { status, data } = await (0, import_hanji9.render)(
57474
+ new Select([
57475
+ "No, add the constraint without truncating the table",
57476
+ `Yes, truncate the table`
57477
+ ])
57478
+ );
57479
+ if ((data == null ? void 0 : data.index) === 1) {
57480
+ tablesToTruncate.push(statement.tableName);
57481
+ statementsToExecute.push(`truncate table ${statement.tableName};`);
57482
+ shouldAskForApprove = true;
57483
+ }
57484
+ }
57485
+ }
57486
+ }
57487
+ return {
57488
+ statementsToExecute,
57489
+ shouldAskForApprove,
57490
+ infoToPrint,
57491
+ columnsToRemove: [...new Set(columnsToRemove)],
57492
+ schemasToRemove: [...new Set(schemasToRemove)],
57493
+ tablesToTruncate: [...new Set(tablesToTruncate)],
57494
+ tablesToRemove: [...new Set(tablesToRemove)]
57495
+ };
57496
+ };
57497
+ }
57498
+ });
57499
+
56892
57500
  // src/utils.ts
56893
57501
  var utils_exports = {};
56894
57502
  __export(utils_exports, {
@@ -56897,12 +57505,18 @@ __export(utils_exports, {
56897
57505
  dryJournal: () => dryJournal,
56898
57506
  generateDrizzleJson: () => generateDrizzleJson,
56899
57507
  generateMigration: () => generateMigration,
57508
+ generateMySQLDrizzleJson: () => generateMySQLDrizzleJson,
57509
+ generateMySQLMigration: () => generateMySQLMigration,
57510
+ generateSQLiteDrizzleJson: () => generateSQLiteDrizzleJson,
57511
+ generateSQLiteMigration: () => generateSQLiteMigration,
56900
57512
  kloudMeta: () => kloudMeta,
56901
57513
  mapValues: () => mapValues,
56902
57514
  prepareFrom: () => prepareFrom,
56903
57515
  prepareMigrationFolder: () => prepareMigrationFolder,
56904
57516
  prepareMigrationMeta: () => prepareMigrationMeta,
56905
57517
  prepareOutFolder: () => prepareOutFolder2,
57518
+ pushMySQLSchema: () => pushMySQLSchema,
57519
+ pushSQLiteSchema: () => pushSQLiteSchema,
56906
57520
  pushSchema: () => pushSchema,
56907
57521
  schemaRenameKey: () => schemaRenameKey,
56908
57522
  snapshotsPriorV4: () => snapshotsPriorV4,
@@ -56911,7 +57525,7 @@ __export(utils_exports, {
56911
57525
  validateWithReport: () => validateWithReport
56912
57526
  });
56913
57527
  module.exports = __toCommonJS(utils_exports);
56914
- var import_fs4, import_path3, import_crypto2, assertV1OutFolder, dryJournal, snapshotsPriorV4, prepareOutFolder2, mapValues, validatorForDialect, validateWithReport, prepareMigrationFolder, prepareMigrationMeta, schemaRenameKey, tableRenameKey, columnRenameKey, kloudMeta, statementsForDiffs, generateDrizzleJson, generateMigration, pushSchema, prepareFrom;
57528
+ var import_fs4, import_path3, import_crypto2, import_drizzle_orm15, assertV1OutFolder, dryJournal, snapshotsPriorV4, prepareOutFolder2, mapValues, validatorForDialect, validateWithReport, prepareMigrationFolder, prepareMigrationMeta, schemaRenameKey, tableRenameKey, columnRenameKey, kloudMeta, statementsForDiffs, generateDrizzleJson, generateMigration, pushSchema, prepareFrom, generateSQLiteDrizzleJson, generateSQLiteMigration, pushSQLiteSchema, generateMySQLDrizzleJson, generateMySQLMigration, pushMySQLSchema;
56915
57529
  var init_utils5 = __esm({
56916
57530
  "src/utils.ts"() {
56917
57531
  import_fs4 = require("fs");
@@ -56935,6 +57549,10 @@ var init_utils5 = __esm({
56935
57549
  init_pgSerializer();
56936
57550
  init_studioUtils();
56937
57551
  init_pgConnect();
57552
+ init_sqlitePushUtils();
57553
+ init_mysqlSerializer();
57554
+ init_mysqlIntrospect();
57555
+ import_drizzle_orm15 = require("drizzle-orm");
56938
57556
  assertV1OutFolder = (out, dialect6) => {
56939
57557
  if (!(0, import_fs4.existsSync)(out))
56940
57558
  return;
@@ -57184,7 +57802,7 @@ var init_utils5 = __esm({
57184
57802
  return { ...result, left, right };
57185
57803
  };
57186
57804
  generateDrizzleJson = (imports, prevId) => {
57187
- const prepared = prepareFromExports(imports);
57805
+ const prepared = prepareFromExports2(imports);
57188
57806
  const id = (0, import_crypto2.randomUUID)();
57189
57807
  const snapshot = generatePgSnapshot(
57190
57808
  prepared.tables,
@@ -57288,6 +57906,134 @@ var init_utils5 = __esm({
57288
57906
  }
57289
57907
  throw Error("Only sqlite and pg is supported for now");
57290
57908
  };
57909
+ generateSQLiteDrizzleJson = async (imports, prevId) => {
57910
+ const { prepareFromExports: prepareFromExports4 } = await Promise.resolve().then(() => (init_sqliteImports(), sqliteImports_exports));
57911
+ const prepared = prepareFromExports4(imports);
57912
+ const id = (0, import_crypto2.randomUUID)();
57913
+ const snapshot = generateSqliteSnapshot(prepared.tables, prepared.enums);
57914
+ return {
57915
+ ...snapshot,
57916
+ id,
57917
+ prevId: prevId ?? originUUID
57918
+ };
57919
+ };
57920
+ generateSQLiteMigration = async (prev, cur) => {
57921
+ const { prepareSQL: prepareSQL2 } = await Promise.resolve().then(() => (init_migrate(), migrate_exports));
57922
+ const validatedPrev = sqliteSchema.parse(prev);
57923
+ const validatedCur = sqliteSchema.parse(cur);
57924
+ const squashedPrev = squashSqliteScheme(validatedPrev);
57925
+ const squashedCur = squashSqliteScheme(validatedCur);
57926
+ const { sqlStatements, _meta } = await prepareSQL2(
57927
+ squashedPrev,
57928
+ squashedCur,
57929
+ "sqlite",
57930
+ validatedPrev,
57931
+ validatedCur
57932
+ );
57933
+ return sqlStatements;
57934
+ };
57935
+ pushSQLiteSchema = async (imports, db) => {
57936
+ const { prepareSQL: prepareSQL2 } = await Promise.resolve().then(() => (init_migrate(), migrate_exports));
57937
+ const { DrizzleORMSQLiteClient: DrizzleORMSQLiteClient2 } = await Promise.resolve().then(() => (init_drivers(), drivers_exports));
57938
+ const client = new DrizzleORMSQLiteClient2(db);
57939
+ const cur = generateSQLiteDrizzleJson(imports);
57940
+ const { schema: prev } = await sqlitePushIntrospect(client, []);
57941
+ const validatedPrev = sqliteSchema.parse(prev);
57942
+ const validatedCur = sqliteSchema.parse(cur);
57943
+ const squashedPrev = squashSqliteScheme(validatedPrev);
57944
+ const squashedCur = squashSqliteScheme(validatedCur);
57945
+ const { statements, _meta } = await prepareSQL2(
57946
+ squashedPrev,
57947
+ squashedCur,
57948
+ "sqlite",
57949
+ validatedPrev,
57950
+ validatedCur
57951
+ );
57952
+ const { shouldAskForApprove, statementsToExecute, infoToPrint } = await logSuggestionsAndReturn({
57953
+ connection: client,
57954
+ statements,
57955
+ json1: squashedPrev,
57956
+ json2: squashedCur,
57957
+ meta: _meta
57958
+ });
57959
+ return {
57960
+ hasDataLoss: shouldAskForApprove,
57961
+ warnings: infoToPrint,
57962
+ statementsToExecute,
57963
+ apply: async () => {
57964
+ for (const dStmnt of statementsToExecute) {
57965
+ await client.query(dStmnt);
57966
+ }
57967
+ }
57968
+ };
57969
+ };
57970
+ (0, import_drizzle_orm15.eq)({}, 1);
57971
+ generateMySQLDrizzleJson = async (imports, prevId) => {
57972
+ const { prepareFromExports: prepareFromExports4 } = await Promise.resolve().then(() => (init_mysqlImports(), mysqlImports_exports));
57973
+ const prepared = prepareFromExports4(imports);
57974
+ const id = (0, import_crypto2.randomUUID)();
57975
+ const snapshot = generateMySqlSnapshot(
57976
+ prepared.tables,
57977
+ prepared.enums,
57978
+ prepared.schemas
57979
+ );
57980
+ return {
57981
+ ...snapshot,
57982
+ id,
57983
+ prevId: prevId ?? originUUID
57984
+ };
57985
+ };
57986
+ generateMySQLMigration = async (prev, cur) => {
57987
+ const { prepareSQL: prepareSQL2 } = await Promise.resolve().then(() => (init_migrate(), migrate_exports));
57988
+ const validatedPrev = mysqlSchema.parse(prev);
57989
+ const validatedCur = mysqlSchema.parse(cur);
57990
+ const squashedPrev = squashMysqlScheme(validatedPrev);
57991
+ const squashedCur = squashMysqlScheme(validatedCur);
57992
+ const { sqlStatements, _meta } = await prepareSQL2(
57993
+ squashedPrev,
57994
+ squashedCur,
57995
+ "mysql",
57996
+ validatedPrev,
57997
+ validatedCur
57998
+ );
57999
+ return sqlStatements;
58000
+ };
58001
+ pushMySQLSchema = async (imports, db, databaseName) => {
58002
+ const { prepareSQL: prepareSQL2 } = await Promise.resolve().then(() => (init_migrate(), migrate_exports));
58003
+ const { DrizzleORMMySQLClient: DrizzleORMMySQLClient2 } = await Promise.resolve().then(() => (init_drivers(), drivers_exports));
58004
+ const { logSuggestionsAndReturn: logSuggestionsAndReturn3 } = await Promise.resolve().then(() => (init_mysqlPushUtils(), mysqlPushUtils_exports));
58005
+ const client = new DrizzleORMMySQLClient2(db);
58006
+ const cur = generateMySQLDrizzleJson(imports);
58007
+ const { schema: prev } = await mysqlPushIntrospect(
58008
+ { client, databaseName },
58009
+ []
58010
+ );
58011
+ const validatedPrev = mysqlSchema.parse(prev);
58012
+ const validatedCur = mysqlSchema.parse(cur);
58013
+ const squashedPrev = squashMysqlScheme(validatedPrev);
58014
+ const squashedCur = squashMysqlScheme(validatedCur);
58015
+ const { statements, _meta } = await prepareSQL2(
58016
+ squashedPrev,
58017
+ squashedCur,
58018
+ "mysql",
58019
+ validatedPrev,
58020
+ validatedCur
58021
+ );
58022
+ const { shouldAskForApprove, statementsToExecute, infoToPrint } = await logSuggestionsAndReturn3({
58023
+ connection: client,
58024
+ statements
58025
+ });
58026
+ return {
58027
+ hasDataLoss: shouldAskForApprove,
58028
+ warnings: infoToPrint,
58029
+ statementsToExecute,
58030
+ apply: async () => {
58031
+ for (const dStmnt of statementsToExecute) {
58032
+ await client.query(dStmnt);
58033
+ }
58034
+ }
58035
+ };
58036
+ };
57291
58037
  }
57292
58038
  });
57293
58039
  init_utils5();
@@ -57298,12 +58044,18 @@ init_utils5();
57298
58044
  dryJournal,
57299
58045
  generateDrizzleJson,
57300
58046
  generateMigration,
58047
+ generateMySQLDrizzleJson,
58048
+ generateMySQLMigration,
58049
+ generateSQLiteDrizzleJson,
58050
+ generateSQLiteMigration,
57301
58051
  kloudMeta,
57302
58052
  mapValues,
57303
58053
  prepareFrom,
57304
58054
  prepareMigrationFolder,
57305
58055
  prepareMigrationMeta,
57306
58056
  prepareOutFolder,
58057
+ pushMySQLSchema,
58058
+ pushSQLiteSchema,
57307
58059
  pushSchema,
57308
58060
  schemaRenameKey,
57309
58061
  snapshotsPriorV4,