@mikro-orm/migrations 7.0.11-dev.14 → 7.0.11-dev.15

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/Migrator.d.ts CHANGED
@@ -17,6 +17,8 @@ export declare class Migrator extends AbstractMigrator<AbstractSqlDriver> {
17
17
  * @inheritDoc
18
18
  */
19
19
  create(path?: string, blank?: boolean, initial?: boolean, name?: string): Promise<MigrationResult>;
20
+ getPending(): Promise<MigrationInfo[]>;
21
+ private hasSnapshot;
20
22
  checkSchema(): Promise<boolean>;
21
23
  /**
22
24
  * @inheritDoc
package/Migrator.js CHANGED
@@ -57,7 +57,8 @@ export class Migrator extends AbstractMigrator {
57
57
  * @inheritDoc
58
58
  */
59
59
  async create(path, blank = false, initial = false, name) {
60
- await this.init();
60
+ const offline = !initial && (await this.hasSnapshot());
61
+ await (offline ? this.initPaths() : this.init());
61
62
  if (initial) {
62
63
  return this.createInitial(path, name, blank);
63
64
  }
@@ -73,6 +74,31 @@ export class Migrator extends AbstractMigrator {
73
74
  diff,
74
75
  };
75
76
  }
77
+ async getPending() {
78
+ if (!(await this.hasSnapshot())) {
79
+ return super.getPending();
80
+ }
81
+ await this.initPaths();
82
+ const all = await this.discoverMigrations();
83
+ // probe the DB via `ensureTable` — if it fails, the DB is unreachable and
84
+ // we treat every discovered migration as pending; otherwise let errors
85
+ // from `storage.executed()` propagate so real bugs are not swallowed
86
+ try {
87
+ await this.storage.ensureTable();
88
+ }
89
+ catch {
90
+ return all.map(m => ({ name: m.name, path: m.path }));
91
+ }
92
+ const executed = new Set(await this.storage.executed());
93
+ return all.filter(m => !executed.has(m.name)).map(m => ({ name: m.name, path: m.path }));
94
+ }
95
+ async hasSnapshot() {
96
+ if (!this.options.snapshot) {
97
+ return false;
98
+ }
99
+ const { fs } = await import('@mikro-orm/core/fs-utils');
100
+ return fs.pathExists(await this.getSnapshotPath());
101
+ }
76
102
  async checkSchema() {
77
103
  const snapshot = await this.getSchemaFromSnapshot();
78
104
  if (!snapshot) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mikro-orm/migrations",
3
- "version": "7.0.11-dev.14",
3
+ "version": "7.0.11-dev.15",
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,13 +47,13 @@
47
47
  "copy": "node ../../scripts/copy.mjs"
48
48
  },
49
49
  "dependencies": {
50
- "@mikro-orm/sql": "7.0.11-dev.14"
50
+ "@mikro-orm/sql": "7.0.11-dev.15"
51
51
  },
52
52
  "devDependencies": {
53
53
  "@mikro-orm/core": "^7.0.10"
54
54
  },
55
55
  "peerDependencies": {
56
- "@mikro-orm/core": "7.0.11-dev.14"
56
+ "@mikro-orm/core": "7.0.11-dev.15"
57
57
  },
58
58
  "engines": {
59
59
  "node": ">= 22.17.0"