bun-query-builder 0.2.14 → 0.2.16

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
@@ -28885,6 +28885,20 @@ function buildMigrationPlan2(models, options) {
28885
28885
  ensureTable({ table: pivotTable, columns: cols, indexes: idx });
28886
28886
  }
28887
28887
  }
28888
+ const tablesByName = new Map(tables.map((table) => [table.table, table]));
28889
+ for (const table of tables) {
28890
+ for (const column of table.columns) {
28891
+ if (!column.references)
28892
+ continue;
28893
+ const referenced = tablesByName.get(column.references.table)?.columns.find((candidate) => candidate.name === column.references.column);
28894
+ if (!referenced || column.type === referenced.type)
28895
+ continue;
28896
+ column.type = referenced.type;
28897
+ column.maxLength = referenced.maxLength;
28898
+ column.enumValues = referenced.enumValues;
28899
+ column.enumTypeName = referenced.enumTypeName;
28900
+ }
28901
+ }
28888
28902
  return { dialect: options.dialect, vitessSharded: options.vitessSharded, tables };
28889
28903
  }
28890
28904
  function generateSql(plan, opts = {}) {
@@ -29296,14 +29310,20 @@ function generateDiffOperations(previous, next, opts = {}) {
29296
29310
  removedCols = detected.removed;
29297
29311
  addedCols = detected.added;
29298
29312
  }
29299
- if (preserveUnknownColumns && removedCols.length > 0) {
29313
+ if (preserveUnknownColumns) {
29300
29314
  const preserved = removedCols.map((name) => prevCols[name]);
29301
- const preservedNames = new Set(removedCols);
29302
- const keptIndexes = prev.indexes.filter((idx) => idx.columns.some((c2) => preservedNames.has(c2)) && !currIdx[indexKey(idx, prev.table)]);
29303
- info2(`-- Keeping ${preserved.length} column(s) on "${curr.table}" no model declares: ${removedCols.join(", ")} \u2014 reconciled from the database, where an undeclared column is out of scope rather than removed`);
29304
- curr = { ...curr, columns: [...curr.columns, ...preserved], indexes: [...curr.indexes, ...keptIndexes] };
29305
- currCols = mapColumnsByName(curr.columns);
29306
- currIdx = mapIndexesByKey(curr.indexes, curr.table);
29315
+ const keptIndexes = prev.indexes.filter((idx) => !currIdx[indexKey(idx, prev.table)]);
29316
+ if (preserved.length > 0 || keptIndexes.length > 0) {
29317
+ if (preserved.length > 0) {
29318
+ info2(`-- Keeping ${preserved.length} column(s) on "${curr.table}" no model declares: ${removedCols.join(", ")} \u2014 reconciled from the database, where an undeclared column is out of scope rather than removed`);
29319
+ }
29320
+ if (keptIndexes.length > 0) {
29321
+ info2(`-- Keeping ${keptIndexes.length} index(es) on "${curr.table}" no model declares: ${keptIndexes.map((index) => index.name).join(", ")} \u2014 reconciled from the database, where an undeclared index is out of scope rather than removed`);
29322
+ }
29323
+ curr = { ...curr, columns: [...curr.columns, ...preserved], indexes: [...curr.indexes, ...keptIndexes] };
29324
+ currCols = mapColumnsByName(curr.columns);
29325
+ currIdx = mapIndexesByKey(curr.indexes, curr.table);
29326
+ }
29307
29327
  removedCols = [];
29308
29328
  }
29309
29329
  const modifiedCols = Object.keys(currCols).filter((n2) => prevCols[n2] && columnsAreDifferent(prevCols[n2], currCols[n2], dialect));
@@ -31542,7 +31562,7 @@ function getPrefix() {
31542
31562
  }
31543
31563
  var prefix = getPrefix();
31544
31564
  // package.json
31545
- var version2 = "0.2.14";
31565
+ var version2 = "0.2.16";
31546
31566
 
31547
31567
  // bin/cli.ts
31548
31568
  init_actions();
package/dist/src/index.js CHANGED
@@ -28884,6 +28884,20 @@ function buildMigrationPlan2(models, options) {
28884
28884
  ensureTable({ table: pivotTable, columns: cols, indexes: idx });
28885
28885
  }
28886
28886
  }
28887
+ const tablesByName = new Map(tables.map((table) => [table.table, table]));
28888
+ for (const table of tables) {
28889
+ for (const column of table.columns) {
28890
+ if (!column.references)
28891
+ continue;
28892
+ const referenced = tablesByName.get(column.references.table)?.columns.find((candidate) => candidate.name === column.references.column);
28893
+ if (!referenced || column.type === referenced.type)
28894
+ continue;
28895
+ column.type = referenced.type;
28896
+ column.maxLength = referenced.maxLength;
28897
+ column.enumValues = referenced.enumValues;
28898
+ column.enumTypeName = referenced.enumTypeName;
28899
+ }
28900
+ }
28887
28901
  return { dialect: options.dialect, vitessSharded: options.vitessSharded, tables };
28888
28902
  }
28889
28903
  function generateSql(plan, opts = {}) {
@@ -29295,14 +29309,20 @@ function generateDiffOperations(previous, next, opts = {}) {
29295
29309
  removedCols = detected.removed;
29296
29310
  addedCols = detected.added;
29297
29311
  }
29298
- if (preserveUnknownColumns && removedCols.length > 0) {
29312
+ if (preserveUnknownColumns) {
29299
29313
  const preserved = removedCols.map((name) => prevCols[name]);
29300
- const preservedNames = new Set(removedCols);
29301
- const keptIndexes = prev.indexes.filter((idx) => idx.columns.some((c2) => preservedNames.has(c2)) && !currIdx[indexKey(idx, prev.table)]);
29302
- info2(`-- Keeping ${preserved.length} column(s) on "${curr.table}" no model declares: ${removedCols.join(", ")} \u2014 reconciled from the database, where an undeclared column is out of scope rather than removed`);
29303
- curr = { ...curr, columns: [...curr.columns, ...preserved], indexes: [...curr.indexes, ...keptIndexes] };
29304
- currCols = mapColumnsByName(curr.columns);
29305
- currIdx = mapIndexesByKey(curr.indexes, curr.table);
29314
+ const keptIndexes = prev.indexes.filter((idx) => !currIdx[indexKey(idx, prev.table)]);
29315
+ if (preserved.length > 0 || keptIndexes.length > 0) {
29316
+ if (preserved.length > 0) {
29317
+ info2(`-- Keeping ${preserved.length} column(s) on "${curr.table}" no model declares: ${removedCols.join(", ")} \u2014 reconciled from the database, where an undeclared column is out of scope rather than removed`);
29318
+ }
29319
+ if (keptIndexes.length > 0) {
29320
+ info2(`-- Keeping ${keptIndexes.length} index(es) on "${curr.table}" no model declares: ${keptIndexes.map((index) => index.name).join(", ")} \u2014 reconciled from the database, where an undeclared index is out of scope rather than removed`);
29321
+ }
29322
+ curr = { ...curr, columns: [...curr.columns, ...preserved], indexes: [...curr.indexes, ...keptIndexes] };
29323
+ currCols = mapColumnsByName(curr.columns);
29324
+ currIdx = mapIndexesByKey(curr.indexes, curr.table);
29325
+ }
29306
29326
  removedCols = [];
29307
29327
  }
29308
29328
  const modifiedCols = Object.keys(currCols).filter((n2) => prevCols[n2] && columnsAreDifferent(prevCols[n2], currCols[n2], dialect));
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "bun-query-builder",
3
3
  "type": "module",
4
- "version": "0.2.14",
4
+ "version": "0.2.16",
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",