@mikro-orm/migrations-mongodb 7.0.0-dev.9 → 7.0.0-dev.91
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 +14 -7
- package/Migrator.js +43 -17
- package/README.md +3 -2
- package/TSMigrationGenerator.js +1 -1
- package/package.json +6 -6
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
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type MigrationParams, type RunnableMigration } from 'umzug';
|
|
2
|
-
import { type Constructor, type IMigrator, type
|
|
2
|
+
import { type Constructor, type IMigrator, type MaybePromise, type MigratorEvent, type MikroORM } from '@mikro-orm/core';
|
|
3
3
|
import type { EntityManager } from '@mikro-orm/mongodb';
|
|
4
4
|
import type { Migration } from './Migration.js';
|
|
5
5
|
import { MigrationStorage } from './MigrationStorage.js';
|
|
@@ -17,17 +17,24 @@ 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
|
*/
|
|
26
|
-
|
|
31
|
+
create(path?: string, blank?: boolean, initial?: boolean, name?: string): Promise<MigrationResult>;
|
|
32
|
+
/** @inheritDoc */
|
|
33
|
+
checkSchema(): Promise<boolean>;
|
|
27
34
|
/**
|
|
28
35
|
* @inheritDoc
|
|
29
36
|
*/
|
|
30
|
-
|
|
37
|
+
createInitial(path?: string): Promise<MigrationResult>;
|
|
31
38
|
/**
|
|
32
39
|
* @inheritDoc
|
|
33
40
|
*/
|
|
@@ -40,11 +47,11 @@ export declare class Migrator implements IMigrator {
|
|
|
40
47
|
/**
|
|
41
48
|
* @inheritDoc
|
|
42
49
|
*/
|
|
43
|
-
|
|
50
|
+
getExecuted(): Promise<MigrationRow[]>;
|
|
44
51
|
/**
|
|
45
52
|
* @inheritDoc
|
|
46
53
|
*/
|
|
47
|
-
|
|
54
|
+
getPending(): Promise<UmzugMigration[]>;
|
|
48
55
|
/**
|
|
49
56
|
* @inheritDoc
|
|
50
57
|
*/
|
package/Migrator.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { Umzug } from 'umzug';
|
|
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,10 +30,37 @@ 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
|
*/
|
|
34
|
-
async
|
|
63
|
+
async create(path, blank = false, initial = false, name) {
|
|
35
64
|
this.ensureMigrationsDirExists();
|
|
36
65
|
const diff = { up: [], down: [] };
|
|
37
66
|
const migration = await this.generator.generate(diff, path, name);
|
|
@@ -41,19 +70,16 @@ export class Migrator {
|
|
|
41
70
|
diff,
|
|
42
71
|
};
|
|
43
72
|
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
*/
|
|
48
|
-
async checkMigrationNeeded() {
|
|
73
|
+
/** @inheritDoc */
|
|
74
|
+
/* v8 ignore next */
|
|
75
|
+
async checkSchema() {
|
|
49
76
|
return true;
|
|
50
77
|
}
|
|
51
|
-
/* v8 ignore stop */
|
|
52
78
|
/**
|
|
53
79
|
* @inheritDoc
|
|
54
80
|
*/
|
|
55
|
-
async
|
|
56
|
-
return this.
|
|
81
|
+
async createInitial(path) {
|
|
82
|
+
return this.create(path);
|
|
57
83
|
}
|
|
58
84
|
/**
|
|
59
85
|
* @inheritDoc
|
|
@@ -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
|
}
|
|
@@ -111,14 +137,14 @@ export class Migrator {
|
|
|
111
137
|
/**
|
|
112
138
|
* @inheritDoc
|
|
113
139
|
*/
|
|
114
|
-
async
|
|
140
|
+
async getExecuted() {
|
|
115
141
|
this.ensureMigrationsDirExists();
|
|
116
142
|
return this.storage.getExecutedMigrations();
|
|
117
143
|
}
|
|
118
144
|
/**
|
|
119
145
|
* @inheritDoc
|
|
120
146
|
*/
|
|
121
|
-
async
|
|
147
|
+
async getPending() {
|
|
122
148
|
this.ensureMigrationsDirExists();
|
|
123
149
|
return this.umzug.pending();
|
|
124
150
|
}
|
|
@@ -140,7 +166,7 @@ export class Migrator {
|
|
|
140
166
|
resolve(params) {
|
|
141
167
|
const createMigrationHandler = async (method) => {
|
|
142
168
|
const migration = await Utils.dynamicImport(params.path);
|
|
143
|
-
const MigrationClass = Object.values(migration)
|
|
169
|
+
const MigrationClass = Object.values(migration).find(cls => typeof cls === 'function' && typeof cls.constructor === 'function');
|
|
144
170
|
const instance = new MigrationClass(this.driver, this.config);
|
|
145
171
|
await this.runner.run(instance, method);
|
|
146
172
|
};
|
|
@@ -164,7 +190,7 @@ export class Migrator {
|
|
|
164
190
|
return name.match(/^\d{14}$/) ? this.options.fileName(name) : name;
|
|
165
191
|
}
|
|
166
192
|
prefix(options) {
|
|
167
|
-
if (
|
|
193
|
+
if (typeof options === 'string' || Array.isArray(options)) {
|
|
168
194
|
return { migrations: Utils.asArray(options).map(name => this.getMigrationFilename(name)) };
|
|
169
195
|
}
|
|
170
196
|
if (!options) {
|
|
@@ -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/README.md
CHANGED
|
@@ -11,7 +11,6 @@ TypeScript ORM for Node.js based on Data Mapper, [Unit of Work](https://mikro-or
|
|
|
11
11
|
[](https://discord.gg/w8bjxFHS7X)
|
|
12
12
|
[](https://www.npmjs.com/package/@mikro-orm/core)
|
|
13
13
|
[](https://coveralls.io/r/mikro-orm/mikro-orm?branch=master)
|
|
14
|
-
[](https://codeclimate.com/github/mikro-orm/mikro-orm/maintainability)
|
|
15
14
|
[](https://github.com/mikro-orm/mikro-orm/actions?workflow=tests)
|
|
16
15
|
|
|
17
16
|
## 🤔 Unit of What?
|
|
@@ -141,7 +140,7 @@ There is also auto-generated [CHANGELOG.md](CHANGELOG.md) file based on commit m
|
|
|
141
140
|
- [Composite and Foreign Keys as Primary Key](https://mikro-orm.io/docs/composite-keys)
|
|
142
141
|
- [Filters](https://mikro-orm.io/docs/filters)
|
|
143
142
|
- [Using `QueryBuilder`](https://mikro-orm.io/docs/query-builder)
|
|
144
|
-
- [
|
|
143
|
+
- [Populating relations](https://mikro-orm.io/docs/populating-relations)
|
|
145
144
|
- [Property Validation](https://mikro-orm.io/docs/property-validation)
|
|
146
145
|
- [Lifecycle Hooks](https://mikro-orm.io/docs/events#hooks)
|
|
147
146
|
- [Vanilla JS Support](https://mikro-orm.io/docs/usage-with-js)
|
|
@@ -382,6 +381,8 @@ See also the list of contributors who [participated](https://github.com/mikro-or
|
|
|
382
381
|
|
|
383
382
|
Please ⭐️ this repository if this project helped you!
|
|
384
383
|
|
|
384
|
+
> If you'd like to support my open-source work, consider sponsoring me directly at [github.com/sponsors/b4nan](https://github.com/sponsors/b4nan).
|
|
385
|
+
|
|
385
386
|
## 📝 License
|
|
386
387
|
|
|
387
388
|
Copyright © 2018 [Martin Adámek](https://github.com/b4nan).
|
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.91",
|
|
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",
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
},
|
|
39
39
|
"homepage": "https://mikro-orm.io",
|
|
40
40
|
"engines": {
|
|
41
|
-
"node": ">= 22.
|
|
41
|
+
"node": ">= 22.17.0"
|
|
42
42
|
},
|
|
43
43
|
"scripts": {
|
|
44
44
|
"build": "yarn clean && yarn compile && yarn copy",
|
|
@@ -50,14 +50,14 @@
|
|
|
50
50
|
"access": "public"
|
|
51
51
|
},
|
|
52
52
|
"dependencies": {
|
|
53
|
-
"@mikro-orm/mongodb": "7.0.0-dev.
|
|
54
|
-
"mongodb": "6.
|
|
53
|
+
"@mikro-orm/mongodb": "7.0.0-dev.91",
|
|
54
|
+
"mongodb": "6.20.0",
|
|
55
55
|
"umzug": "3.8.2"
|
|
56
56
|
},
|
|
57
57
|
"devDependencies": {
|
|
58
|
-
"@mikro-orm/core": "^6.
|
|
58
|
+
"@mikro-orm/core": "^6.6.2"
|
|
59
59
|
},
|
|
60
60
|
"peerDependencies": {
|
|
61
|
-
"@mikro-orm/core": "7.0.0-dev.
|
|
61
|
+
"@mikro-orm/core": "7.0.0-dev.91"
|
|
62
62
|
}
|
|
63
63
|
}
|