@mikro-orm/migrations-mongodb 7.1.0-dev.3 → 7.1.0-dev.30

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.
@@ -8,7 +8,9 @@ export declare class MigrationRunner {
8
8
  private readonly connection;
9
9
  private masterTransaction?;
10
10
  constructor(driver: MongoDriver, options: MigrationsOptions);
11
- run(migration: Migration, method: 'up' | 'down'): Promise<void>;
11
+ run(migration: Migration, method: 'up' | 'down', afterRun?: (tx?: Transaction) => Promise<void>): Promise<void>;
12
12
  setMasterMigration(trx: Transaction): void;
13
13
  unsetMasterMigration(): void;
14
+ setRunSchema(schema?: string): void;
15
+ unsetRunSchema(): void;
14
16
  }
@@ -1,3 +1,4 @@
1
+ import { rejectRuntimeSchema } from './typings.js';
1
2
  /** Executes individual MongoDB migration files within optional transaction contexts. */
2
3
  export class MigrationRunner {
3
4
  driver;
@@ -9,19 +10,22 @@ export class MigrationRunner {
9
10
  this.options = options;
10
11
  this.connection = this.driver.getConnection();
11
12
  }
12
- async run(migration, method) {
13
+ async run(migration, method, afterRun) {
13
14
  migration.reset();
14
15
  if (!this.options.transactional || !migration.isTransactional()) {
15
16
  await migration[method]();
17
+ await afterRun?.();
16
18
  }
17
19
  else if (this.masterTransaction) {
18
20
  migration.setTransactionContext(this.masterTransaction);
19
21
  await migration[method]();
22
+ await afterRun?.(this.masterTransaction);
20
23
  }
21
24
  else {
22
25
  await this.connection.transactional(async (tx) => {
23
26
  migration.setTransactionContext(tx);
24
27
  await migration[method]();
28
+ await afterRun?.(tx);
25
29
  }, { ctx: this.masterTransaction });
26
30
  }
27
31
  }
@@ -31,4 +35,10 @@ export class MigrationRunner {
31
35
  unsetMasterMigration() {
32
36
  delete this.masterTransaction;
33
37
  }
38
+ setRunSchema(schema) {
39
+ rejectRuntimeSchema(schema);
40
+ }
41
+ unsetRunSchema() {
42
+ /* nothing to do */
43
+ }
34
44
  }
@@ -1,6 +1,6 @@
1
1
  import { type EntitySchema, type MigrationsOptions, type Transaction } from '@mikro-orm/core';
2
2
  import type { MongoDriver } from '@mikro-orm/mongodb';
3
- import type { MigrationRow } from './typings.js';
3
+ import { type MigrationRow } from './typings.js';
4
4
  /** Tracks executed MongoDB migrations in a collection. */
5
5
  export declare class MigrationStorage {
6
6
  protected readonly driver: MongoDriver;
@@ -10,13 +10,15 @@ export declare class MigrationStorage {
10
10
  executed(): Promise<string[]>;
11
11
  logMigration(params: {
12
12
  name: string;
13
- }): Promise<void>;
13
+ }, tx?: Transaction): Promise<void>;
14
14
  unlogMigration(params: {
15
15
  name: string;
16
- }): Promise<void>;
16
+ }, tx?: Transaction): Promise<void>;
17
17
  getExecutedMigrations(): Promise<MigrationRow[]>;
18
18
  setMasterMigration(trx: Transaction): void;
19
19
  unsetMasterMigration(): void;
20
+ setRunSchema(schema?: string): void;
21
+ unsetRunSchema(): void;
20
22
  /**
21
23
  * @internal
22
24
  */
@@ -1,4 +1,5 @@
1
1
  import { defineEntity, p, } from '@mikro-orm/core';
2
+ import { rejectRuntimeSchema } from './typings.js';
2
3
  /** Tracks executed MongoDB migrations in a collection. */
3
4
  export class MigrationStorage {
4
5
  driver;
@@ -12,15 +13,15 @@ export class MigrationStorage {
12
13
  const migrations = await this.getExecutedMigrations();
13
14
  return migrations.map(({ name }) => this.getMigrationName(name));
14
15
  }
15
- async logMigration(params) {
16
+ async logMigration(params, tx) {
16
17
  const name = this.getMigrationName(params.name);
17
18
  const entity = this.getEntityDefinition();
18
- await this.driver.nativeInsert(entity, { name, executed_at: new Date() }, { ctx: this.masterTransaction });
19
+ await this.driver.nativeInsert(entity, { name, executed_at: new Date() }, { ctx: tx ?? this.masterTransaction });
19
20
  }
20
- async unlogMigration(params) {
21
+ async unlogMigration(params, tx) {
21
22
  const withoutExt = this.getMigrationName(params.name);
22
23
  const entity = this.getEntityDefinition();
23
- await this.driver.nativeDelete(entity, { name: { $in: [params.name, withoutExt] } }, { ctx: this.masterTransaction });
24
+ await this.driver.nativeDelete(entity, { name: { $in: [params.name, withoutExt] } }, { ctx: tx ?? this.masterTransaction });
24
25
  }
25
26
  async getExecutedMigrations() {
26
27
  const entity = this.getEntityDefinition();
@@ -32,6 +33,12 @@ export class MigrationStorage {
32
33
  unsetMasterMigration() {
33
34
  delete this.masterTransaction;
34
35
  }
36
+ setRunSchema(schema) {
37
+ rejectRuntimeSchema(schema);
38
+ }
39
+ unsetRunSchema() {
40
+ /* nothing to do */
41
+ }
35
42
  /**
36
43
  * @internal
37
44
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mikro-orm/migrations-mongodb",
3
- "version": "7.1.0-dev.3",
3
+ "version": "7.1.0-dev.30",
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",
@@ -47,14 +47,14 @@
47
47
  "copy": "node ../../scripts/copy.mjs"
48
48
  },
49
49
  "dependencies": {
50
- "@mikro-orm/mongodb": "7.1.0-dev.3",
51
- "mongodb": "7.1.1"
50
+ "@mikro-orm/mongodb": "7.1.0-dev.30",
51
+ "mongodb": "7.2.0"
52
52
  },
53
53
  "devDependencies": {
54
- "@mikro-orm/core": "^7.0.11"
54
+ "@mikro-orm/core": "^7.0.15"
55
55
  },
56
56
  "peerDependencies": {
57
- "@mikro-orm/core": "7.1.0-dev.3"
57
+ "@mikro-orm/core": "7.1.0-dev.30"
58
58
  },
59
59
  "engines": {
60
60
  "node": ">= 22.17.0"
package/typings.d.ts CHANGED
@@ -1 +1,3 @@
1
1
  export type { MigrationInfo, MigrateOptions, MigrationResult, MigrationRow } from '@mikro-orm/core';
2
+ /** @internal */
3
+ export declare function rejectRuntimeSchema(schema: string | undefined): void;
package/typings.js CHANGED
@@ -1 +1,6 @@
1
- export {};
1
+ /** @internal */
2
+ export function rejectRuntimeSchema(schema) {
3
+ if (schema) {
4
+ throw new Error('Runtime schema for migrations is not supported by the MongoDriver');
5
+ }
6
+ }