@mikro-orm/migrations 7.0.0-dev.7 → 7.0.0-dev.70
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/MigrationRunner.js +1 -1
- package/MigrationStorage.js +1 -1
- package/Migrator.d.ts +6 -6
- package/Migrator.js +13 -13
- package/README.md +3 -2
- package/package.json +5 -5
package/MigrationRunner.js
CHANGED
|
@@ -39,7 +39,7 @@ export class MigrationRunner {
|
|
|
39
39
|
let queries = migration.getQueries();
|
|
40
40
|
queries.unshift(...this.helper.getSchemaBeginning(charset, this.options.disableForeignKeys).split('\n'));
|
|
41
41
|
queries.push(...this.helper.getSchemaEnd(this.options.disableForeignKeys).split('\n'));
|
|
42
|
-
queries = queries.filter(sql =>
|
|
42
|
+
queries = queries.filter(sql => typeof sql !== 'string' || sql.trim().length > 0);
|
|
43
43
|
return queries;
|
|
44
44
|
}
|
|
45
45
|
}
|
package/MigrationStorage.js
CHANGED
|
@@ -75,7 +75,7 @@ export class MigrationStorage {
|
|
|
75
75
|
length,
|
|
76
76
|
});
|
|
77
77
|
const sql = this.helper.createTable(table);
|
|
78
|
-
await this.connection.execute(sql.join(';\n'));
|
|
78
|
+
await this.connection.execute(sql.join(';\n'), [], 'run', this.masterTransaction);
|
|
79
79
|
}
|
|
80
80
|
setMasterMigration(trx) {
|
|
81
81
|
this.masterTransaction = trx;
|
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 { DatabaseSchema, type EntityManager } from '@mikro-orm/knex';
|
|
4
4
|
import type { Migration } from './Migration.js';
|
|
5
5
|
import { MigrationStorage } from './MigrationStorage.js';
|
|
@@ -21,12 +21,12 @@ export declare class Migrator implements IMigrator {
|
|
|
21
21
|
/**
|
|
22
22
|
* @inheritDoc
|
|
23
23
|
*/
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
create(path?: string, blank?: boolean, initial?: boolean, name?: string): Promise<MigrationResult>;
|
|
25
|
+
checkSchema(): Promise<boolean>;
|
|
26
26
|
/**
|
|
27
27
|
* @inheritDoc
|
|
28
28
|
*/
|
|
29
|
-
|
|
29
|
+
createInitial(path?: string, name?: string, blank?: boolean): Promise<MigrationResult>;
|
|
30
30
|
/**
|
|
31
31
|
* @inheritDoc
|
|
32
32
|
*/
|
|
@@ -48,12 +48,12 @@ export declare class Migrator implements IMigrator {
|
|
|
48
48
|
/**
|
|
49
49
|
* @inheritDoc
|
|
50
50
|
*/
|
|
51
|
-
|
|
51
|
+
getExecuted(): Promise<MigrationRow[]>;
|
|
52
52
|
private ensureDatabase;
|
|
53
53
|
/**
|
|
54
54
|
* @inheritDoc
|
|
55
55
|
*/
|
|
56
|
-
|
|
56
|
+
getPending(): Promise<UmzugMigration[]>;
|
|
57
57
|
/**
|
|
58
58
|
* @inheritDoc
|
|
59
59
|
*/
|
package/Migrator.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { Umzug } from 'umzug';
|
|
1
|
+
import { Umzug, } from 'umzug';
|
|
2
2
|
import { basename, join } from 'node:path';
|
|
3
3
|
import { existsSync, writeFileSync } from 'node:fs';
|
|
4
4
|
import { t, Type, UnknownType, Utils, } from '@mikro-orm/core';
|
|
5
|
-
import { DatabaseSchema, DatabaseTable,
|
|
5
|
+
import { DatabaseSchema, DatabaseTable, } from '@mikro-orm/knex';
|
|
6
6
|
import { MigrationRunner } from './MigrationRunner.js';
|
|
7
7
|
import { MigrationStorage } from './MigrationStorage.js';
|
|
8
8
|
import { TSMigrationGenerator } from './TSMigrationGenerator.js';
|
|
@@ -22,9 +22,9 @@ export class Migrator {
|
|
|
22
22
|
constructor(em) {
|
|
23
23
|
this.em = em;
|
|
24
24
|
this.driver = this.em.getDriver();
|
|
25
|
-
this.schemaGenerator = new SqlSchemaGenerator(this.em);
|
|
26
25
|
this.config = this.em.config;
|
|
27
26
|
this.options = this.config.get('migrations');
|
|
27
|
+
this.schemaGenerator = this.config.getExtension('@mikro-orm/schema-generator');
|
|
28
28
|
/* v8 ignore next */
|
|
29
29
|
const key = (this.config.get('preferTs', Utils.detectTypeScriptSupport()) && this.options.pathTs) ? 'pathTs' : 'path';
|
|
30
30
|
this.absolutePath = Utils.absolutePath(this.options[key], this.config.get('baseDir'));
|
|
@@ -43,9 +43,9 @@ export class Migrator {
|
|
|
43
43
|
/**
|
|
44
44
|
* @inheritDoc
|
|
45
45
|
*/
|
|
46
|
-
async
|
|
46
|
+
async create(path, blank = false, initial = false, name) {
|
|
47
47
|
if (initial) {
|
|
48
|
-
return this.
|
|
48
|
+
return this.createInitial(path, name, blank);
|
|
49
49
|
}
|
|
50
50
|
this.ensureMigrationsDirExists();
|
|
51
51
|
const diff = await this.getSchemaDiff(blank, initial);
|
|
@@ -60,7 +60,7 @@ export class Migrator {
|
|
|
60
60
|
diff,
|
|
61
61
|
};
|
|
62
62
|
}
|
|
63
|
-
async
|
|
63
|
+
async checkSchema() {
|
|
64
64
|
this.ensureMigrationsDirExists();
|
|
65
65
|
const diff = await this.getSchemaDiff(false, false);
|
|
66
66
|
return diff.up.length > 0;
|
|
@@ -68,7 +68,7 @@ export class Migrator {
|
|
|
68
68
|
/**
|
|
69
69
|
* @inheritDoc
|
|
70
70
|
*/
|
|
71
|
-
async
|
|
71
|
+
async createInitial(path, name, blank = false) {
|
|
72
72
|
this.ensureMigrationsDirExists();
|
|
73
73
|
const schemaExists = await this.validateInitialMigration(blank);
|
|
74
74
|
const diff = await this.getSchemaDiff(blank, true);
|
|
@@ -143,8 +143,8 @@ export class Migrator {
|
|
|
143
143
|
* If only some of the tables are present, exception is thrown.
|
|
144
144
|
*/
|
|
145
145
|
async validateInitialMigration(blank) {
|
|
146
|
-
const executed = await this.
|
|
147
|
-
const pending = await this.
|
|
146
|
+
const executed = await this.getExecuted();
|
|
147
|
+
const pending = await this.getPending();
|
|
148
148
|
if (executed.length > 0 || pending.length > 0) {
|
|
149
149
|
throw new Error('Initial migration cannot be created, as some migrations already exist');
|
|
150
150
|
}
|
|
@@ -175,7 +175,7 @@ export class Migrator {
|
|
|
175
175
|
/**
|
|
176
176
|
* @inheritDoc
|
|
177
177
|
*/
|
|
178
|
-
async
|
|
178
|
+
async getExecuted() {
|
|
179
179
|
await this.ensureDatabase();
|
|
180
180
|
return this.storage.getExecutedMigrations();
|
|
181
181
|
}
|
|
@@ -191,7 +191,7 @@ export class Migrator {
|
|
|
191
191
|
/**
|
|
192
192
|
* @inheritDoc
|
|
193
193
|
*/
|
|
194
|
-
async
|
|
194
|
+
async getPending() {
|
|
195
195
|
await this.ensureDatabase();
|
|
196
196
|
return this.umzug.pending();
|
|
197
197
|
}
|
|
@@ -213,7 +213,7 @@ export class Migrator {
|
|
|
213
213
|
resolve(params) {
|
|
214
214
|
const createMigrationHandler = async (method) => {
|
|
215
215
|
const migration = await Utils.dynamicImport(params.path);
|
|
216
|
-
const MigrationClass = Object.values(migration)
|
|
216
|
+
const MigrationClass = Object.values(migration).find(cls => typeof cls === 'function' && typeof cls.constructor === 'function');
|
|
217
217
|
const instance = new MigrationClass(this.driver, this.config);
|
|
218
218
|
await this.runner.run(instance, method);
|
|
219
219
|
};
|
|
@@ -298,7 +298,7 @@ export class Migrator {
|
|
|
298
298
|
return name.match(/^\d{14}$/) ? this.options.fileName(name) : name;
|
|
299
299
|
}
|
|
300
300
|
prefix(options) {
|
|
301
|
-
if (
|
|
301
|
+
if (typeof options === 'string' || Array.isArray(options)) {
|
|
302
302
|
return { migrations: Utils.asArray(options).map(name => this.getMigrationFilename(name)) };
|
|
303
303
|
}
|
|
304
304
|
if (!options) {
|
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/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mikro-orm/migrations",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "7.0.0-dev.
|
|
4
|
+
"version": "7.0.0-dev.70",
|
|
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,13 +50,13 @@
|
|
|
50
50
|
"access": "public"
|
|
51
51
|
},
|
|
52
52
|
"dependencies": {
|
|
53
|
-
"@mikro-orm/knex": "7.0.0-dev.
|
|
53
|
+
"@mikro-orm/knex": "7.0.0-dev.70",
|
|
54
54
|
"umzug": "3.8.2"
|
|
55
55
|
},
|
|
56
56
|
"devDependencies": {
|
|
57
|
-
"@mikro-orm/core": "^6.
|
|
57
|
+
"@mikro-orm/core": "^6.6.1"
|
|
58
58
|
},
|
|
59
59
|
"peerDependencies": {
|
|
60
|
-
"@mikro-orm/core": "7.0.0-dev.
|
|
60
|
+
"@mikro-orm/core": "7.0.0-dev.70"
|
|
61
61
|
}
|
|
62
62
|
}
|