bun-query-builder 0.2.36 → 0.2.38

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/dist/bin/cli.js CHANGED
@@ -19489,13 +19489,27 @@ async function resetDatabase(dir, opts = {}) {
19489
19489
  const dialect = opts.dialect || config5.dialect || "postgres";
19490
19490
  const driver = getDialectDriver(dialect);
19491
19491
  const workspaceRoot = getWorkspaceRoot();
19492
+ const dropTableForReset = async (tableName) => {
19493
+ const dropSql = driver.dropTable(tableName);
19494
+ await withFreshConnection(async (bunSql2) => {
19495
+ if (dialect === "sqlite")
19496
+ await bunSql2.unsafe("PRAGMA foreign_keys = OFF").execute();
19497
+ if (dialect === "mysql" || dialect === "vitess")
19498
+ await bunSql2.unsafe("SET FOREIGN_KEY_CHECKS = 0").execute();
19499
+ try {
19500
+ await bunSql2.unsafe(dropSql).execute();
19501
+ } finally {
19502
+ if (dialect === "sqlite")
19503
+ await bunSql2.unsafe("PRAGMA foreign_keys = ON").execute();
19504
+ if (dialect === "mysql" || dialect === "vitess")
19505
+ await bunSql2.unsafe("SET FOREIGN_KEY_CHECKS = 1").execute();
19506
+ }
19507
+ });
19508
+ };
19492
19509
  try {
19493
- const dropMigrationsSql = driver.dropTable("migrations");
19494
19510
  try {
19495
- await withFreshConnection(async (bunSql2) => {
19496
- await bunSql2.unsafe(dropMigrationsSql).execute();
19497
- info("-- Dropped migrations table");
19498
- });
19511
+ await dropTableForReset("migrations");
19512
+ info("-- Dropped migrations table");
19499
19513
  } catch (err) {
19500
19514
  console.error(err);
19501
19515
  }
@@ -19526,11 +19540,8 @@ async function resetDatabase(dir, opts = {}) {
19526
19540
  info(`-- Dropping ${tableNames.length} tables: ${tableNames.join(", ")}`);
19527
19541
  for (const tableName of tableNames.reverse()) {
19528
19542
  try {
19529
- const dropSql = driver.dropTable(tableName);
19530
- await withFreshConnection(async (bunSql2) => {
19531
- await bunSql2.unsafe(dropSql).execute();
19532
- info(`-- Dropped table: ${tableName}`);
19533
- });
19543
+ await dropTableForReset(tableName);
19544
+ info(`-- Dropped table: ${tableName}`);
19534
19545
  } catch (err) {
19535
19546
  console.error(err);
19536
19547
  info(`-- Table ${tableName} may not exist, skipping drop`);
@@ -19556,21 +19567,25 @@ async function resetDatabase(dir, opts = {}) {
19556
19567
  } else {
19557
19568
  info("-- No enum types found to drop");
19558
19569
  }
19559
- if (tableNames.length > 0) {
19570
+ if (tableNames.length > 0 && !opts.preserveMigrationState) {
19560
19571
  try {
19561
19572
  await deleteMigrationFiles(dir, workspaceRoot, opts);
19562
19573
  } catch (err) {
19563
19574
  console.error(err);
19564
19575
  info("-- Could not clean up migration files");
19565
19576
  }
19566
- } else {
19577
+ } else if (tableNames.length === 0) {
19567
19578
  info("-- No models directory found; keeping committed migration files in place");
19579
+ } else {
19580
+ info("-- Preserving migration files and model snapshot for fresh replay");
19568
19581
  }
19569
- try {
19570
- await clearGeneratedDirectory(workspaceRoot);
19571
- } catch (err) {
19572
- console.error(err);
19573
- info("-- Could not clear generated directory");
19582
+ if (!opts.preserveMigrationState) {
19583
+ try {
19584
+ await clearGeneratedDirectory(workspaceRoot);
19585
+ } catch (err) {
19586
+ console.error(err);
19587
+ info("-- Could not clear generated directory");
19588
+ }
19574
19589
  }
19575
19590
  info("-- Database reset completed successfully");
19576
19591
  return true;
@@ -32318,7 +32333,7 @@ function getPrefix() {
32318
32333
  }
32319
32334
  var prefix = getPrefix();
32320
32335
  // package.json
32321
- var version2 = "0.2.36";
32336
+ var version2 = "0.2.38";
32322
32337
 
32323
32338
  // bin/cli.ts
32324
32339
  init_actions();
package/dist/src/index.js CHANGED
@@ -19488,13 +19488,27 @@ async function resetDatabase(dir, opts = {}) {
19488
19488
  const dialect = opts.dialect || config5.dialect || "postgres";
19489
19489
  const driver = getDialectDriver(dialect);
19490
19490
  const workspaceRoot = getWorkspaceRoot();
19491
+ const dropTableForReset = async (tableName) => {
19492
+ const dropSql = driver.dropTable(tableName);
19493
+ await withFreshConnection(async (bunSql2) => {
19494
+ if (dialect === "sqlite")
19495
+ await bunSql2.unsafe("PRAGMA foreign_keys = OFF").execute();
19496
+ if (dialect === "mysql" || dialect === "vitess")
19497
+ await bunSql2.unsafe("SET FOREIGN_KEY_CHECKS = 0").execute();
19498
+ try {
19499
+ await bunSql2.unsafe(dropSql).execute();
19500
+ } finally {
19501
+ if (dialect === "sqlite")
19502
+ await bunSql2.unsafe("PRAGMA foreign_keys = ON").execute();
19503
+ if (dialect === "mysql" || dialect === "vitess")
19504
+ await bunSql2.unsafe("SET FOREIGN_KEY_CHECKS = 1").execute();
19505
+ }
19506
+ });
19507
+ };
19491
19508
  try {
19492
- const dropMigrationsSql = driver.dropTable("migrations");
19493
19509
  try {
19494
- await withFreshConnection(async (bunSql2) => {
19495
- await bunSql2.unsafe(dropMigrationsSql).execute();
19496
- info("-- Dropped migrations table");
19497
- });
19510
+ await dropTableForReset("migrations");
19511
+ info("-- Dropped migrations table");
19498
19512
  } catch (err) {
19499
19513
  console.error(err);
19500
19514
  }
@@ -19525,11 +19539,8 @@ async function resetDatabase(dir, opts = {}) {
19525
19539
  info(`-- Dropping ${tableNames.length} tables: ${tableNames.join(", ")}`);
19526
19540
  for (const tableName of tableNames.reverse()) {
19527
19541
  try {
19528
- const dropSql = driver.dropTable(tableName);
19529
- await withFreshConnection(async (bunSql2) => {
19530
- await bunSql2.unsafe(dropSql).execute();
19531
- info(`-- Dropped table: ${tableName}`);
19532
- });
19542
+ await dropTableForReset(tableName);
19543
+ info(`-- Dropped table: ${tableName}`);
19533
19544
  } catch (err) {
19534
19545
  console.error(err);
19535
19546
  info(`-- Table ${tableName} may not exist, skipping drop`);
@@ -19555,21 +19566,25 @@ async function resetDatabase(dir, opts = {}) {
19555
19566
  } else {
19556
19567
  info("-- No enum types found to drop");
19557
19568
  }
19558
- if (tableNames.length > 0) {
19569
+ if (tableNames.length > 0 && !opts.preserveMigrationState) {
19559
19570
  try {
19560
19571
  await deleteMigrationFiles(dir, workspaceRoot, opts);
19561
19572
  } catch (err) {
19562
19573
  console.error(err);
19563
19574
  info("-- Could not clean up migration files");
19564
19575
  }
19565
- } else {
19576
+ } else if (tableNames.length === 0) {
19566
19577
  info("-- No models directory found; keeping committed migration files in place");
19578
+ } else {
19579
+ info("-- Preserving migration files and model snapshot for fresh replay");
19567
19580
  }
19568
- try {
19569
- await clearGeneratedDirectory(workspaceRoot);
19570
- } catch (err) {
19571
- console.error(err);
19572
- info("-- Could not clear generated directory");
19581
+ if (!opts.preserveMigrationState) {
19582
+ try {
19583
+ await clearGeneratedDirectory(workspaceRoot);
19584
+ } catch (err) {
19585
+ console.error(err);
19586
+ info("-- Could not clear generated directory");
19587
+ }
19573
19588
  }
19574
19589
  info("-- Database reset completed successfully");
19575
19590
  return true;
package/dist/types.d.ts CHANGED
@@ -271,6 +271,7 @@ export declare interface IntrospectOptions {
271
271
  }
272
272
  export declare interface MigrateOptions {
273
273
  dialect?: SupportedDialect
274
+ preserveMigrationState?: boolean
274
275
  vitessSharded?: boolean
275
276
  state?: string
276
277
  apply?: boolean
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "bun-query-builder",
3
3
  "type": "module",
4
- "version": "0.2.36",
4
+ "version": "0.2.38",
5
5
  "description": "A simple yet performant query builder for TypeScript. Built with Bun.",
6
6
  "author": "Chris Breuer <chris@stacksjs.org>",
7
7
  "license": "MIT",