@mikro-orm/migrations-mongodb 7.0.0-dev.76 → 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/JSMigrationGenerator.js +1 -1
- package/MigrationGenerator.d.ts +1 -3
- package/MigrationGenerator.js +4 -5
- package/Migrator.d.ts +9 -2
- package/Migrator.js +34 -8
- package/TSMigrationGenerator.js +1 -1
- package/package.json +3 -3
package/JSMigrationGenerator.js
CHANGED
|
@@ -12,7 +12,7 @@ export class JSMigrationGenerator extends MigrationGenerator {
|
|
|
12
12
|
/* v8 ignore next */
|
|
13
13
|
diff.up.forEach(sql => ret += this.createStatement(sql, 4));
|
|
14
14
|
ret += ` }\n\n`;
|
|
15
|
-
/* v8 ignore next
|
|
15
|
+
/* v8 ignore next */
|
|
16
16
|
if (diff.down.length > 0) {
|
|
17
17
|
ret += ` async down() {\n`;
|
|
18
18
|
diff.down.forEach(sql => ret += this.createStatement(sql, 4));
|
package/MigrationGenerator.d.ts
CHANGED
|
@@ -12,9 +12,7 @@ export declare abstract class MigrationGenerator implements IMigrationGenerator
|
|
|
12
12
|
up: string[];
|
|
13
13
|
down: string[];
|
|
14
14
|
}, path?: string, name?: string): Promise<[string, string]>;
|
|
15
|
-
/**
|
|
16
|
-
* @inheritDoc
|
|
17
|
-
*/
|
|
15
|
+
/** @inheritDoc */
|
|
18
16
|
createStatement(query: string, padLeft: number): string;
|
|
19
17
|
/**
|
|
20
18
|
* @inheritDoc
|
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}`;
|
|
@@ -24,10 +25,8 @@ export class MigrationGenerator {
|
|
|
24
25
|
await writeFile(path + '/' + fileName, ret, { flush: true });
|
|
25
26
|
return [ret, fileName];
|
|
26
27
|
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
* @inheritDoc
|
|
30
|
-
*/
|
|
28
|
+
/** @inheritDoc */
|
|
29
|
+
/* v8 ignore next */
|
|
31
30
|
createStatement(query, padLeft) {
|
|
32
31
|
if (query) {
|
|
33
32
|
const padding = ' '.repeat(padLeft);
|
package/Migrator.d.ts
CHANGED
|
@@ -17,12 +17,19 @@ export declare class Migrator implements IMigrator {
|
|
|
17
17
|
constructor(em: EntityManager);
|
|
18
18
|
static register(orm: MikroORM): void;
|
|
19
19
|
/**
|
|
20
|
-
*
|
|
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.
|
|
21
26
|
*/
|
|
22
|
-
|
|
27
|
+
private detectSourceFolder;
|
|
23
28
|
/**
|
|
24
29
|
* @inheritDoc
|
|
25
30
|
*/
|
|
31
|
+
create(path?: string, blank?: boolean, initial?: boolean, name?: string): Promise<MigrationResult>;
|
|
32
|
+
/** @inheritDoc */
|
|
26
33
|
checkSchema(): Promise<boolean>;
|
|
27
34
|
/**
|
|
28
35
|
* @inheritDoc
|
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
|
*/
|
|
@@ -41,14 +70,11 @@ export class Migrator {
|
|
|
41
70
|
diff,
|
|
42
71
|
};
|
|
43
72
|
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
* @inheritDoc
|
|
47
|
-
*/
|
|
73
|
+
/** @inheritDoc */
|
|
74
|
+
/* v8 ignore next */
|
|
48
75
|
async checkSchema() {
|
|
49
76
|
return true;
|
|
50
77
|
}
|
|
51
|
-
/* v8 ignore stop */
|
|
52
78
|
/**
|
|
53
79
|
* @inheritDoc
|
|
54
80
|
*/
|
|
@@ -76,7 +102,7 @@ export class Migrator {
|
|
|
76
102
|
glob: join(this.absolutePath, this.options.glob).replace(/\\/g, '/'),
|
|
77
103
|
resolve: (params) => this.resolve(params),
|
|
78
104
|
};
|
|
79
|
-
/* v8 ignore next
|
|
105
|
+
/* v8 ignore next */
|
|
80
106
|
if (this.options.migrationsList) {
|
|
81
107
|
migrations = this.options.migrationsList.map(migration => {
|
|
82
108
|
if (typeof migration === 'function') {
|
|
@@ -97,7 +123,7 @@ export class Migrator {
|
|
|
97
123
|
this.umzug.on('reverting', event => logger.log('migrator', `Processing '${event.name}'`, { enabled: true }));
|
|
98
124
|
this.umzug.on('reverted', event => logger.log('migrator', `Reverted '${event.name}'`, { enabled: true }));
|
|
99
125
|
}
|
|
100
|
-
/* v8 ignore next
|
|
126
|
+
/* v8 ignore next */
|
|
101
127
|
if (this.options.generator) {
|
|
102
128
|
this.generator = new this.options.generator(this.driver, this.config.getNamingStrategy(), this.options);
|
|
103
129
|
}
|
|
@@ -199,7 +225,7 @@ export class Migrator {
|
|
|
199
225
|
}
|
|
200
226
|
ensureMigrationsDirExists() {
|
|
201
227
|
if (!this.options.migrationsList) {
|
|
202
|
-
|
|
228
|
+
fs.ensureDir(this.absolutePath);
|
|
203
229
|
}
|
|
204
230
|
}
|
|
205
231
|
}
|
package/TSMigrationGenerator.js
CHANGED
|
@@ -10,7 +10,7 @@ export class TSMigrationGenerator extends MigrationGenerator {
|
|
|
10
10
|
/* v8 ignore next */
|
|
11
11
|
diff.up.forEach(sql => ret += this.createStatement(sql, 4));
|
|
12
12
|
ret += ` }\n\n`;
|
|
13
|
-
/* v8 ignore next
|
|
13
|
+
/* v8 ignore next */
|
|
14
14
|
if (diff.down.length > 0) {
|
|
15
15
|
ret += ` async down(): Promise<void> {\n`;
|
|
16
16
|
diff.down.forEach(sql => ret += this.createStatement(sql, 4));
|
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
|
}
|