@mikro-orm/core 7.0.15-dev.6 → 7.0.15-dev.8
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/EntityManager.js +7 -4
- package/package.json +1 -1
- package/typings.d.ts +3 -3
- package/utils/AbstractMigrator.d.ts +2 -2
- package/utils/AbstractMigrator.js +15 -13
- package/utils/Utils.js +1 -1
package/EntityManager.js
CHANGED
|
@@ -355,7 +355,8 @@ export class EntityManager {
|
|
|
355
355
|
const field = hint.field.split(':')[0];
|
|
356
356
|
const prop = meta.properties[field];
|
|
357
357
|
const strategy = getLoadingStrategy(prop.strategy || hint.strategy || options.strategy || this.config.get('loadStrategy'), prop.kind);
|
|
358
|
-
const joined = strategy === LoadStrategy.JOINED
|
|
358
|
+
const joined = (strategy === LoadStrategy.JOINED || (prop.kind === ReferenceKind.ONE_TO_ONE && !prop.owner)) &&
|
|
359
|
+
prop.kind !== ReferenceKind.SCALAR;
|
|
359
360
|
if (!joined && !hint.filter) {
|
|
360
361
|
continue;
|
|
361
362
|
}
|
|
@@ -424,11 +425,13 @@ export class EntityManager {
|
|
|
424
425
|
const populated = options.populate.filter(({ field }) => field.split(':')[0] === prop.name);
|
|
425
426
|
let found = false;
|
|
426
427
|
for (const hint of populated) {
|
|
427
|
-
|
|
428
|
+
const strategy = getLoadingStrategy(prop.strategy || hint.strategy || options.strategy || this.config.get('loadStrategy'), prop.kind);
|
|
429
|
+
// inverse 1:1 always produces a JOIN (forced by `joinedProps()`), regardless of strategy
|
|
430
|
+
const willJoin = strategy === LoadStrategy.JOINED || (prop.kind === ReferenceKind.ONE_TO_ONE && !prop.owner);
|
|
431
|
+
if (!hint.all || willJoin) {
|
|
428
432
|
hint.filter = true;
|
|
429
433
|
}
|
|
430
|
-
|
|
431
|
-
if (hint.field === `${prop.name}:ref` || (hint.filter && strategy === LoadStrategy.JOINED)) {
|
|
434
|
+
if (hint.field === `${prop.name}:ref` || (hint.filter && willJoin)) {
|
|
432
435
|
found = true;
|
|
433
436
|
}
|
|
434
437
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mikro-orm/core",
|
|
3
|
-
"version": "7.0.15-dev.
|
|
3
|
+
"version": "7.0.15-dev.8",
|
|
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/typings.d.ts
CHANGED
|
@@ -990,7 +990,7 @@ export type MigrationRow = {
|
|
|
990
990
|
* @internal
|
|
991
991
|
*/
|
|
992
992
|
export interface IMigrationRunner {
|
|
993
|
-
run(migration: Migration, method: 'up' | 'down'): Promise<void>;
|
|
993
|
+
run(migration: Migration, method: 'up' | 'down', afterRun?: (tx?: Transaction) => Promise<void>): Promise<void>;
|
|
994
994
|
setMasterMigration(trx: Transaction): void;
|
|
995
995
|
unsetMasterMigration(): void;
|
|
996
996
|
}
|
|
@@ -999,8 +999,8 @@ export interface IMigrationRunner {
|
|
|
999
999
|
*/
|
|
1000
1000
|
export interface IMigratorStorage {
|
|
1001
1001
|
executed(): Promise<string[]>;
|
|
1002
|
-
logMigration(params: Dictionary): Promise<void>;
|
|
1003
|
-
unlogMigration(params: Dictionary): Promise<void>;
|
|
1002
|
+
logMigration(params: Dictionary, tx?: Transaction): Promise<void>;
|
|
1003
|
+
unlogMigration(params: Dictionary, tx?: Transaction): Promise<void>;
|
|
1004
1004
|
getExecutedMigrations(): Promise<MigrationRow[]>;
|
|
1005
1005
|
ensureTable?(): Promise<void>;
|
|
1006
1006
|
setMasterMigration(trx: Transaction): void;
|
|
@@ -5,8 +5,8 @@ import type { EntityManagerType, IDatabaseDriver } from '../drivers/IDatabaseDri
|
|
|
5
5
|
interface RunnableMigration {
|
|
6
6
|
name: string;
|
|
7
7
|
path?: string;
|
|
8
|
-
up: () => MaybePromise<void>;
|
|
9
|
-
down: () => MaybePromise<void>;
|
|
8
|
+
up: (afterRun?: (tx?: Transaction) => Promise<void>) => MaybePromise<void>;
|
|
9
|
+
down: (afterRun?: (tx?: Transaction) => Promise<void>) => MaybePromise<void>;
|
|
10
10
|
}
|
|
11
11
|
type MigrateOptions = {
|
|
12
12
|
from?: string | number;
|
|
@@ -98,26 +98,26 @@ export class AbstractMigrator {
|
|
|
98
98
|
}
|
|
99
99
|
}
|
|
100
100
|
resolve(params) {
|
|
101
|
-
const createMigrationHandler = async (method) => {
|
|
101
|
+
const createMigrationHandler = async (method, afterRun) => {
|
|
102
102
|
const { fs } = await import('@mikro-orm/core/fs-utils');
|
|
103
103
|
const migration = await fs.dynamicImport(params.path);
|
|
104
104
|
const MigrationClass = Object.values(migration).find(cls => typeof cls === 'function' && typeof cls.constructor === 'function');
|
|
105
105
|
const instance = new MigrationClass(this.driver, this.config);
|
|
106
|
-
await this.runner.run(instance, method);
|
|
106
|
+
await this.runner.run(instance, method, afterRun);
|
|
107
107
|
};
|
|
108
108
|
return {
|
|
109
109
|
name: this.storage.getMigrationName(params.name),
|
|
110
110
|
path: params.path,
|
|
111
|
-
up:
|
|
112
|
-
down:
|
|
111
|
+
up: afterRun => createMigrationHandler('up', afterRun),
|
|
112
|
+
down: afterRun => createMigrationHandler('down', afterRun),
|
|
113
113
|
};
|
|
114
114
|
}
|
|
115
115
|
initialize(MigrationClass, name) {
|
|
116
116
|
const instance = new MigrationClass(this.driver, this.config);
|
|
117
117
|
return {
|
|
118
118
|
name: this.storage.getMigrationName(name),
|
|
119
|
-
up:
|
|
120
|
-
down:
|
|
119
|
+
up: afterRun => this.runner.run(instance, 'up', afterRun),
|
|
120
|
+
down: afterRun => this.runner.run(instance, 'down', afterRun),
|
|
121
121
|
};
|
|
122
122
|
}
|
|
123
123
|
/**
|
|
@@ -196,13 +196,15 @@ export class AbstractMigrator {
|
|
|
196
196
|
for (const migration of toRun) {
|
|
197
197
|
const event = { name: migration.name, path: migration.path };
|
|
198
198
|
await this.emit(eventBefore, event);
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
199
|
+
// log inside the runner's tx (if any) so a logMigration failure rolls the migration back
|
|
200
|
+
await migration[method](async (tx) => {
|
|
201
|
+
if (method === 'up') {
|
|
202
|
+
await this.storage.logMigration({ name: migration.name }, tx);
|
|
203
|
+
}
|
|
204
|
+
else {
|
|
205
|
+
await this.storage.unlogMigration({ name: migration.name }, tx);
|
|
206
|
+
}
|
|
207
|
+
});
|
|
206
208
|
await this.emit(eventAfter, event);
|
|
207
209
|
result.push(event);
|
|
208
210
|
}
|
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.0.15-dev.
|
|
144
|
+
static #ORM_VERSION = '7.0.15-dev.8';
|
|
145
145
|
/**
|
|
146
146
|
* Checks if the argument is instance of `Object`. Returns false for arrays.
|
|
147
147
|
*/
|