@mikro-orm/sql 7.0.3-dev.0 → 7.0.3-dev.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mikro-orm/sql",
3
- "version": "7.0.3-dev.0",
3
+ "version": "7.0.3-dev.2",
4
4
  "description": "TypeScript ORM for Node.js based on Data Mapper, Unit of Work and Identity Map patterns. Supports MongoDB, MySQL, PostgreSQL and SQLite databases as well as usage with vanilla JavaScript.",
5
5
  "keywords": [
6
6
  "data-mapper",
@@ -53,7 +53,7 @@
53
53
  "@mikro-orm/core": "^7.0.2"
54
54
  },
55
55
  "peerDependencies": {
56
- "@mikro-orm/core": "7.0.3-dev.0"
56
+ "@mikro-orm/core": "7.0.3-dev.2"
57
57
  },
58
58
  "engines": {
59
59
  "node": ">= 22.17.0"
@@ -57,6 +57,18 @@ export declare class SchemaComparator {
57
57
  */
58
58
  private compareArrays;
59
59
  diffExpression(expr1: string, expr2: string): boolean;
60
+ /**
61
+ * Compares two view expressions, with special handling for SELECT *.
62
+ * Databases like PostgreSQL and MySQL expand `SELECT *` to explicit column names
63
+ * in their stored view definitions, which makes diffExpression always detect changes.
64
+ * When SELECT * is present, we strip the first SELECT...FROM column list from both
65
+ * sides and compare only the structural parts (FROM clause onwards).
66
+ * Note: this means changes *within* subqueries in the SELECT list of a SELECT * view
67
+ * may not be detected — an acceptable tradeoff since SELECT * views are inherently
68
+ * column-list-agnostic.
69
+ * @see https://github.com/mikro-orm/mikro-orm/issues/7308
70
+ */
71
+ private diffViewExpression;
60
72
  parseJsonDefault(defaultValue?: string | null): Dictionary | string | null;
61
73
  hasSameDefaultValue(from: Column, to: Column): boolean;
62
74
  private mapColumnToProperty;
@@ -123,7 +123,7 @@ export class SchemaComparator {
123
123
  }
124
124
  else {
125
125
  const fromView = fromSchema.getView(toView.name) ?? fromSchema.getView(viewName);
126
- if (fromView && this.diffExpression(fromView.definition, toView.definition)) {
126
+ if (fromView && this.diffViewExpression(fromView.definition, toView.definition)) {
127
127
  diff.changedViews[viewName] = { from: fromView, to: toView };
128
128
  this.log(`view ${viewName} changed`);
129
129
  }
@@ -666,6 +666,28 @@ export class SchemaComparator {
666
666
  };
667
667
  return simplify(expr1) !== simplify(expr2);
668
668
  }
669
+ /**
670
+ * Compares two view expressions, with special handling for SELECT *.
671
+ * Databases like PostgreSQL and MySQL expand `SELECT *` to explicit column names
672
+ * in their stored view definitions, which makes diffExpression always detect changes.
673
+ * When SELECT * is present, we strip the first SELECT...FROM column list from both
674
+ * sides and compare only the structural parts (FROM clause onwards).
675
+ * Note: this means changes *within* subqueries in the SELECT list of a SELECT * view
676
+ * may not be detected — an acceptable tradeoff since SELECT * views are inherently
677
+ * column-list-agnostic.
678
+ * @see https://github.com/mikro-orm/mikro-orm/issues/7308
679
+ */
680
+ diffViewExpression(fromDef, toDef) {
681
+ if (!this.diffExpression(fromDef, toDef)) {
682
+ return false;
683
+ }
684
+ // If either expression uses SELECT *, the diff may be due to * expansion
685
+ if (/\bselect\s+\*/i.test(fromDef) || /\bselect\s+\*/i.test(toDef)) {
686
+ const stripColumns = (s) => s.replace(/\bselect\b[\s\S]*?\bfrom\b/i, 'select from');
687
+ return this.diffExpression(stripColumns(fromDef), stripColumns(toDef));
688
+ }
689
+ return true;
690
+ }
669
691
  parseJsonDefault(defaultValue) {
670
692
  /* v8 ignore next */
671
693
  if (!defaultValue) {