@mikro-orm/sql 7.1.12-dev.4 → 7.1.12-dev.6

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.1.12-dev.4",
3
+ "version": "7.1.12-dev.6",
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.1.11"
54
54
  },
55
55
  "peerDependencies": {
56
- "@mikro-orm/core": "7.1.12-dev.4"
56
+ "@mikro-orm/core": "7.1.12-dev.6"
57
57
  },
58
58
  "engines": {
59
59
  "node": ">= 22.17.0"
@@ -1030,8 +1030,12 @@ export class DatabaseTable {
1030
1030
  // mysql stores decimal defaults padded to scale (`0` → `0.00`); collapse to canonical numeric form
1031
1031
  // so the metadata-side (`0`) and introspection-side (`0.00`) snapshots agree
1032
1032
  let defaultValue = c.default ?? null;
1033
- if (defaultValue != null && c.mappedType instanceof DecimalType && Number.isFinite(+defaultValue)) {
1034
- defaultValue = this.#platform.formatDecimal(defaultValue, c.scale).toString();
1033
+ if (defaultValue != null && c.mappedType instanceof DecimalType) {
1034
+ // string defaults like `default: '0.00'` are quoted in metadata, so strip the quotes first
1035
+ const unquoted = defaultValue.replace(/^'(.*)'$/, '$1');
1036
+ if (Number.isFinite(+unquoted)) {
1037
+ defaultValue = this.#platform.formatDecimal(unquoted, c.scale).toString();
1038
+ }
1035
1039
  }
1036
1040
  const normalized = {
1037
1041
  name: c.name,
@@ -89,6 +89,7 @@ export declare class SchemaComparator {
89
89
  private diffViewExpression;
90
90
  private diffTrigger;
91
91
  parseJsonDefault(defaultValue?: string | null): Dictionary | string | null;
92
+ private parseDecimalDefault;
92
93
  hasSameDefaultValue(from: Column, to: Column): boolean;
93
94
  private mapColumnToProperty;
94
95
  private log;
@@ -993,6 +993,10 @@ export class SchemaComparator {
993
993
  const val = defaultValue.replace(/^(_\w+\\)?'(.*?)\\?'$/, '$2').replace(/^\(?'(.*?)'\)?$/, '$1');
994
994
  return parseJsonSafe(val);
995
995
  }
996
+ parseDecimalDefault(defaultValue) {
997
+ const value = +('' + defaultValue).replace(/^'(.+)'$/, '$1');
998
+ return Number.isFinite(value) ? value : null;
999
+ }
996
1000
  hasSameDefaultValue(from, to) {
997
1001
  if (from.default == null ||
998
1002
  from.default.toString().toLowerCase() === 'null' ||
@@ -1018,10 +1022,15 @@ export class SchemaComparator {
1018
1022
  const defaultValueTo = to.default.toLowerCase().replace('current_timestamp', 'now').replace(/\(\)$/, '');
1019
1023
  return defaultValueFrom === defaultValueTo;
1020
1024
  }
1021
- // mysql stores decimal defaults padded to scale (`0` → `0.00`); compare numerically so the
1022
- // entity-side raw literal and the introspected padded form don't churn the no-op migration
1023
- if (to.mappedType instanceof DecimalType && Number.isFinite(+from.default) && Number.isFinite(+to.default)) {
1024
- return (this.#platform.formatDecimal(from.default, to.scale) === this.#platform.formatDecimal(to.default, to.scale));
1025
+ // mysql pads decimal defaults to scale (`0` → `0.00`) and postgres reports them unquoted
1026
+ // while metadata keeps them quoted; compare numerically so neither churns a no-op migration
1027
+ if (to.mappedType instanceof DecimalType) {
1028
+ const defaultValueFrom = this.parseDecimalDefault(from.default);
1029
+ const defaultValueTo = this.parseDecimalDefault(to.default);
1030
+ if (defaultValueFrom != null && defaultValueTo != null) {
1031
+ return (this.#platform.formatDecimal(defaultValueFrom, to.scale) ===
1032
+ this.#platform.formatDecimal(defaultValueTo, to.scale));
1033
+ }
1025
1034
  }
1026
1035
  if (from.default && to.default) {
1027
1036
  return from.default.toString().toLowerCase() === to.default.toString().toLowerCase();