@mikro-orm/migrations-mongodb 7.0.0-dev.77 → 7.0.0-dev.78
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/MigrationGenerator.js +2 -1
- package/Migrator.d.ts +9 -0
- package/Migrator.js +30 -1
- package/package.json +3 -3
package/MigrationGenerator.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Utils, } from '@mikro-orm/core';
|
|
2
|
+
import { fs } from '@mikro-orm/core/fs-utils';
|
|
2
3
|
import { writeFile } from 'node:fs/promises';
|
|
3
4
|
export class MigrationGenerator {
|
|
4
5
|
driver;
|
|
@@ -16,7 +17,7 @@ export class MigrationGenerator {
|
|
|
16
17
|
/* v8 ignore next */
|
|
17
18
|
const defaultPath = this.options.emit === 'ts' && this.options.pathTs ? this.options.pathTs : this.options.path;
|
|
18
19
|
path = Utils.normalizePath(this.driver.config.get('baseDir'), path ?? defaultPath);
|
|
19
|
-
|
|
20
|
+
fs.ensureDir(path);
|
|
20
21
|
const timestamp = new Date().toISOString().replace(/[-T:]|\.\d{3}z$/ig, '');
|
|
21
22
|
const className = this.namingStrategy.classToMigrationName(timestamp, name);
|
|
22
23
|
const fileName = `${this.options.fileName(timestamp, name)}.${this.options.emit}`;
|
package/Migrator.d.ts
CHANGED
|
@@ -16,6 +16,15 @@ export declare class Migrator implements IMigrator {
|
|
|
16
16
|
private readonly absolutePath;
|
|
17
17
|
constructor(em: EntityManager);
|
|
18
18
|
static register(orm: MikroORM): void;
|
|
19
|
+
/**
|
|
20
|
+
* Checks if `src` folder exists, it so, tries to adjust the migrations and seeders paths automatically to use it.
|
|
21
|
+
* If there is a `dist` or `build` folder, it will be used for the JS variant (`path` option), while the `src` folder will be
|
|
22
|
+
* used for the TS variant (`pathTs` option).
|
|
23
|
+
*
|
|
24
|
+
* If the default folder exists (e.g. `/migrations`), the config will respect that, so this auto-detection should not
|
|
25
|
+
* break existing projects, only help with the new ones.
|
|
26
|
+
*/
|
|
27
|
+
private detectSourceFolder;
|
|
19
28
|
/**
|
|
20
29
|
* @inheritDoc
|
|
21
30
|
*/
|
package/Migrator.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Umzug, } from 'umzug';
|
|
2
2
|
import { join } from 'node:path';
|
|
3
3
|
import { Utils, } from '@mikro-orm/core';
|
|
4
|
+
import { fs } from '@mikro-orm/core/fs-utils';
|
|
4
5
|
import { MigrationRunner } from './MigrationRunner.js';
|
|
5
6
|
import { MigrationStorage } from './MigrationStorage.js';
|
|
6
7
|
import { TSMigrationGenerator } from './TSMigrationGenerator.js';
|
|
@@ -20,6 +21,7 @@ export class Migrator {
|
|
|
20
21
|
this.driver = this.em.getDriver();
|
|
21
22
|
this.config = this.em.config;
|
|
22
23
|
this.options = this.config.get('migrations');
|
|
24
|
+
this.detectSourceFolder();
|
|
23
25
|
/* v8 ignore next */
|
|
24
26
|
const key = (this.config.get('preferTs', Utils.detectTypeScriptSupport()) && this.options.pathTs) ? 'pathTs' : 'path';
|
|
25
27
|
this.absolutePath = Utils.absolutePath(this.options[key], this.config.get('baseDir'));
|
|
@@ -28,6 +30,33 @@ export class Migrator {
|
|
|
28
30
|
static register(orm) {
|
|
29
31
|
orm.config.registerExtension('@mikro-orm/migrator', () => new Migrator(orm.em));
|
|
30
32
|
}
|
|
33
|
+
/**
|
|
34
|
+
* Checks if `src` folder exists, it so, tries to adjust the migrations and seeders paths automatically to use it.
|
|
35
|
+
* If there is a `dist` or `build` folder, it will be used for the JS variant (`path` option), while the `src` folder will be
|
|
36
|
+
* used for the TS variant (`pathTs` option).
|
|
37
|
+
*
|
|
38
|
+
* If the default folder exists (e.g. `/migrations`), the config will respect that, so this auto-detection should not
|
|
39
|
+
* break existing projects, only help with the new ones.
|
|
40
|
+
*/
|
|
41
|
+
detectSourceFolder() {
|
|
42
|
+
const baseDir = this.config.get('baseDir');
|
|
43
|
+
const defaultPath = './migrations';
|
|
44
|
+
if (!fs.pathExists(baseDir + '/src')) {
|
|
45
|
+
this.options.path ??= defaultPath;
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
const exists = fs.pathExists(`${baseDir}/${defaultPath}`);
|
|
49
|
+
const distDir = fs.pathExists(baseDir + '/dist');
|
|
50
|
+
const buildDir = fs.pathExists(baseDir + '/build');
|
|
51
|
+
// if neither `dist` nor `build` exist, we use the `src` folder as it might be a JS project without building, but with `src` folder
|
|
52
|
+
/* v8 ignore next */
|
|
53
|
+
const path = distDir ? './dist' : (buildDir ? './build' : './src');
|
|
54
|
+
// only if the user did not provide any values and if the default path does not exist
|
|
55
|
+
if (!this.options.path && !this.options.pathTs && !exists) {
|
|
56
|
+
this.options.path = `${path}/migrations`;
|
|
57
|
+
this.options.pathTs = './src/migrations';
|
|
58
|
+
}
|
|
59
|
+
}
|
|
31
60
|
/**
|
|
32
61
|
* @inheritDoc
|
|
33
62
|
*/
|
|
@@ -196,7 +225,7 @@ export class Migrator {
|
|
|
196
225
|
}
|
|
197
226
|
ensureMigrationsDirExists() {
|
|
198
227
|
if (!this.options.migrationsList) {
|
|
199
|
-
|
|
228
|
+
fs.ensureDir(this.absolutePath);
|
|
200
229
|
}
|
|
201
230
|
}
|
|
202
231
|
}
|
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.
|
|
4
|
+
"version": "7.0.0-dev.78",
|
|
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.
|
|
53
|
+
"@mikro-orm/mongodb": "7.0.0-dev.78",
|
|
54
54
|
"mongodb": "6.20.0",
|
|
55
55
|
"umzug": "3.8.2"
|
|
56
56
|
},
|
|
@@ -58,6 +58,6 @@
|
|
|
58
58
|
"@mikro-orm/core": "^6.6.1"
|
|
59
59
|
},
|
|
60
60
|
"peerDependencies": {
|
|
61
|
-
"@mikro-orm/core": "7.0.0-dev.
|
|
61
|
+
"@mikro-orm/core": "7.0.0-dev.78"
|
|
62
62
|
}
|
|
63
63
|
}
|