@mikro-orm/core 7.1.2-dev.9 → 7.1.3-dev.0
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.
|
@@ -1379,15 +1379,17 @@ export class MetadataDiscovery {
|
|
|
1379
1379
|
}
|
|
1380
1380
|
// When multiple STI children share the same unique relation (OneToOne/ManyToOne),
|
|
1381
1381
|
// replace the simple unique with a composite one including the discriminator column
|
|
1382
|
-
// so different subtypes can independently reference the same target row.
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1382
|
+
// so different subtypes can independently reference the same target row. The second
|
|
1383
|
+
// child already cleared `rootProp.unique`, so for 3+ children we key on the shared
|
|
1384
|
+
// root property existing rather than its (now false) flag, and dedupe the composite.
|
|
1385
|
+
if (rootProp && newProp.unique && [ReferenceKind.ONE_TO_ONE, ReferenceKind.MANY_TO_ONE].includes(newProp.kind)) {
|
|
1386
1386
|
newProp.unique = false;
|
|
1387
1387
|
rootProp.unique = false;
|
|
1388
|
-
meta.root.
|
|
1389
|
-
|
|
1390
|
-
|
|
1388
|
+
const properties = [prop.name, meta.root.discriminatorColumn];
|
|
1389
|
+
const exists = meta.root.uniques.some(u => Utils.equals(Utils.asArray(u.properties), properties));
|
|
1390
|
+
if (!exists) {
|
|
1391
|
+
meta.root.uniques.push({ properties });
|
|
1392
|
+
}
|
|
1391
1393
|
}
|
|
1392
1394
|
newProp.nullable = true;
|
|
1393
1395
|
newProp.inherited = !rootProp;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mikro-orm/core",
|
|
3
|
-
"version": "7.1.
|
|
3
|
+
"version": "7.1.3-dev.0",
|
|
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",
|
package/platforms/Platform.d.ts
CHANGED
|
@@ -167,6 +167,13 @@ export declare abstract class Platform {
|
|
|
167
167
|
precision?: number;
|
|
168
168
|
scale?: number;
|
|
169
169
|
}): string;
|
|
170
|
+
/**
|
|
171
|
+
* Rounds a decimal value to the column's scale and returns it as a number. Used to compare
|
|
172
|
+
* decimal values across representations — `EntityComparator` for `compareValues`, and the
|
|
173
|
+
* schema layer for collapsing snapshot defaults like `0` / `0.00` to the same canonical form
|
|
174
|
+
* so databases that pad to scale (mysql) don't churn no-op migrations.
|
|
175
|
+
*/
|
|
176
|
+
formatDecimal(value: string | number, scale?: number): number;
|
|
170
177
|
getUuidTypeDeclarationSQL(column: {
|
|
171
178
|
length?: number;
|
|
172
179
|
}): string;
|
|
@@ -277,6 +284,8 @@ export declare abstract class Platform {
|
|
|
277
284
|
isNumericColumn(mappedType: Type<unknown>): boolean;
|
|
278
285
|
/** Whether the platform supports unsigned integer columns. */
|
|
279
286
|
supportsUnsigned(): boolean;
|
|
287
|
+
/** Whether the platform persists table/column comments (so they round-trip through introspection). */
|
|
288
|
+
supportsComments(): boolean;
|
|
280
289
|
/**
|
|
281
290
|
* Maximum length of identifiers (table, column, index, constraint, …) the platform supports.
|
|
282
291
|
* Names produced by {@link getIndexName} above this limit are hash-truncated. Defaults to
|
package/platforms/Platform.js
CHANGED
|
@@ -232,6 +232,19 @@ export class Platform {
|
|
|
232
232
|
const scale = column.scale ?? 0;
|
|
233
233
|
return `numeric(${precision},${scale})`;
|
|
234
234
|
}
|
|
235
|
+
/**
|
|
236
|
+
* Rounds a decimal value to the column's scale and returns it as a number. Used to compare
|
|
237
|
+
* decimal values across representations — `EntityComparator` for `compareValues`, and the
|
|
238
|
+
* schema layer for collapsing snapshot defaults like `0` / `0.00` to the same canonical form
|
|
239
|
+
* so databases that pad to scale (mysql) don't churn no-op migrations.
|
|
240
|
+
*/
|
|
241
|
+
formatDecimal(value, scale) {
|
|
242
|
+
if (scale == null) {
|
|
243
|
+
return +value;
|
|
244
|
+
}
|
|
245
|
+
const base = Math.pow(10, scale);
|
|
246
|
+
return Math.round((+value + Number.EPSILON) * base) / base;
|
|
247
|
+
}
|
|
235
248
|
getUuidTypeDeclarationSQL(column) {
|
|
236
249
|
column.length ??= 36;
|
|
237
250
|
return this.getVarcharTypeDeclarationSQL(column);
|
|
@@ -629,6 +642,10 @@ export class Platform {
|
|
|
629
642
|
supportsUnsigned() {
|
|
630
643
|
return false;
|
|
631
644
|
}
|
|
645
|
+
/** Whether the platform persists table/column comments (so they round-trip through introspection). */
|
|
646
|
+
supportsComments() {
|
|
647
|
+
return true;
|
|
648
|
+
}
|
|
632
649
|
/**
|
|
633
650
|
* Maximum length of identifiers (table, column, index, constraint, …) the platform supports.
|
|
634
651
|
* Names produced by {@link getIndexName} above this limit are hash-truncated. Defaults to
|
package/types/DecimalType.d.ts
CHANGED
|
@@ -9,7 +9,6 @@ export declare class DecimalType<Mode extends 'number' | 'string' = 'string'> ex
|
|
|
9
9
|
constructor(mode?: Mode | undefined);
|
|
10
10
|
convertToJSValue(value: string): JSTypeByMode<Mode>;
|
|
11
11
|
compareValues(a: string, b: string): boolean;
|
|
12
|
-
private format;
|
|
13
12
|
getColumnType(prop: EntityProperty, platform: Platform): string;
|
|
14
13
|
compareAsType(): string;
|
|
15
14
|
}
|
package/types/DecimalType.js
CHANGED
|
@@ -16,15 +16,7 @@ export class DecimalType extends Type {
|
|
|
16
16
|
return String(value);
|
|
17
17
|
}
|
|
18
18
|
compareValues(a, b) {
|
|
19
|
-
return this.
|
|
20
|
-
}
|
|
21
|
-
format(val) {
|
|
22
|
-
/* v8 ignore next */
|
|
23
|
-
if (this.prop?.scale == null) {
|
|
24
|
-
return +val;
|
|
25
|
-
}
|
|
26
|
-
const base = Math.pow(10, this.prop.scale);
|
|
27
|
-
return Math.round((+val + Number.EPSILON) * base) / base;
|
|
19
|
+
return this.platform.formatDecimal(a, this.prop?.scale) === this.platform.formatDecimal(b, this.prop?.scale);
|
|
28
20
|
}
|
|
29
21
|
getColumnType(prop, platform) {
|
|
30
22
|
return platform.getDecimalTypeDeclarationSQL(prop);
|
package/utils/Utils.js
CHANGED
|
@@ -141,7 +141,7 @@ export function parseJsonSafe(value) {
|
|
|
141
141
|
/** Collection of general-purpose utility methods used throughout the ORM. */
|
|
142
142
|
export class Utils {
|
|
143
143
|
static PK_SEPARATOR = '~~~';
|
|
144
|
-
static #ORM_VERSION = '7.1.
|
|
144
|
+
static #ORM_VERSION = '7.1.3-dev.0';
|
|
145
145
|
/**
|
|
146
146
|
* Checks if the argument is instance of `Object`. Returns false for arrays.
|
|
147
147
|
*/
|
package/utils/upsert-utils.js
CHANGED
|
@@ -86,7 +86,10 @@ export function getOnConflictReturningFields(meta, data, uniqueFields, options)
|
|
|
86
86
|
if (p.autoincrement) {
|
|
87
87
|
return true;
|
|
88
88
|
}
|
|
89
|
-
|
|
89
|
+
// for a raw `onConflictFields` fragment we can't introspect which columns form the conflict
|
|
90
|
+
// target, so we keep every comparable prop (returning the unique key columns is harmless) –
|
|
91
|
+
// otherwise the non-merged columns would never be reloaded and the entity would diverge from db
|
|
92
|
+
return !Array.isArray(uniqueFields) || !uniqueFields.includes(p.name);
|
|
90
93
|
})
|
|
91
94
|
.map(p => p.name);
|
|
92
95
|
if (meta.versionProperty) {
|