@mikro-orm/migrations-mongodb 7.0.0-dev.113 → 7.0.0-dev.115

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/Migration.d.ts CHANGED
@@ -11,5 +11,5 @@ export declare abstract class Migration {
11
11
  isTransactional(): boolean;
12
12
  reset(): void;
13
13
  setTransactionContext(ctx: Transaction): void;
14
- getCollection<T extends Document>(entityName: EntityName<any>): Collection<T>;
14
+ getCollection<T extends Document>(entityName: EntityName): Collection<T>;
15
15
  }
@@ -1,4 +1,4 @@
1
- import type { MigrationsOptions, Transaction } from '@mikro-orm/core';
1
+ import { type EntitySchema, type MigrationsOptions, type Transaction } from '@mikro-orm/core';
2
2
  import type { MongoDriver } from '@mikro-orm/mongodb';
3
3
  import type { MigrationParams, UmzugStorage } from 'umzug';
4
4
  import type { MigrationRow } from './typings.js';
@@ -17,4 +17,8 @@ export declare class MigrationStorage implements UmzugStorage {
17
17
  * @internal
18
18
  */
19
19
  getMigrationName(name: string): string;
20
+ /**
21
+ * @internal
22
+ */
23
+ getEntityDefinition(): EntitySchema;
20
24
  }
@@ -1,3 +1,4 @@
1
+ import { defineEntity, p } from '@mikro-orm/core';
1
2
  import { parse } from 'node:path';
2
3
  export class MigrationStorage {
3
4
  driver;
@@ -12,18 +13,18 @@ export class MigrationStorage {
12
13
  return migrations.map(({ name }) => `${this.getMigrationName(name)}`);
13
14
  }
14
15
  async logMigration(params) {
15
- const tableName = this.options.tableName;
16
16
  const name = this.getMigrationName(params.name);
17
- await this.driver.nativeInsert(tableName, { name, executed_at: new Date() }, { ctx: this.masterTransaction });
17
+ const entity = this.getEntityDefinition();
18
+ await this.driver.nativeInsert(entity, { name, executed_at: new Date() }, { ctx: this.masterTransaction });
18
19
  }
19
20
  async unlogMigration(params) {
20
- const tableName = this.options.tableName;
21
21
  const withoutExt = this.getMigrationName(params.name);
22
- await this.driver.nativeDelete(tableName, { name: { $in: [params.name, withoutExt] } }, { ctx: this.masterTransaction });
22
+ const entity = this.getEntityDefinition();
23
+ await this.driver.nativeDelete(entity, { name: { $in: [params.name, withoutExt] } }, { ctx: this.masterTransaction });
23
24
  }
24
25
  async getExecutedMigrations() {
25
- const tableName = this.options.tableName;
26
- return this.driver.find(tableName, {}, { ctx: this.masterTransaction, orderBy: { _id: 'asc' } });
26
+ const entity = this.getEntityDefinition();
27
+ return this.driver.find(entity, {}, { ctx: this.masterTransaction, orderBy: { _id: 'asc' } });
27
28
  }
28
29
  setMasterMigration(trx) {
29
30
  this.masterTransaction = trx;
@@ -42,4 +43,20 @@ export class MigrationStorage {
42
43
  }
43
44
  return name;
44
45
  }
46
+ /**
47
+ * @internal
48
+ */
49
+ getEntityDefinition() {
50
+ const entity = defineEntity({
51
+ name: 'Migration',
52
+ tableName: this.options.tableName,
53
+ properties: {
54
+ id: p.integer().primary().fieldNames('id'),
55
+ name: p.string().fieldNames('name'),
56
+ executedAt: p.datetime().defaultRaw('current_timestamp').fieldNames('executed_at'),
57
+ },
58
+ }).init();
59
+ entity.meta.sync();
60
+ return entity;
61
+ }
45
62
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@mikro-orm/migrations-mongodb",
3
3
  "type": "module",
4
- "version": "7.0.0-dev.113",
4
+ "version": "7.0.0-dev.115",
5
5
  "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.",
6
6
  "exports": {
7
7
  "./package.json": "./package.json",
@@ -50,7 +50,7 @@
50
50
  "access": "public"
51
51
  },
52
52
  "dependencies": {
53
- "@mikro-orm/mongodb": "7.0.0-dev.113",
53
+ "@mikro-orm/mongodb": "7.0.0-dev.115",
54
54
  "mongodb": "7.0.0",
55
55
  "umzug": "3.8.2"
56
56
  },
@@ -58,6 +58,6 @@
58
58
  "@mikro-orm/core": "^6.6.2"
59
59
  },
60
60
  "peerDependencies": {
61
- "@mikro-orm/core": "7.0.0-dev.113"
61
+ "@mikro-orm/core": "7.0.0-dev.115"
62
62
  }
63
63
  }