@mikro-orm/migrations 7.1.2-dev.13 → 7.1.2-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 +2 -0
- package/Migrator.js +14 -1
- package/package.json +3 -3
package/Migrator.d.ts
CHANGED
|
@@ -27,6 +27,8 @@ export declare class Migrator extends AbstractMigrator<AbstractSqlDriver> {
|
|
|
27
27
|
*/
|
|
28
28
|
createInitial(path?: string, name?: string, blank?: boolean): Promise<MigrationResult>;
|
|
29
29
|
protected runMigrations(method: 'up' | 'down', options?: string | string[] | MigrateOptions): Promise<MigrationInfo[]>;
|
|
30
|
+
/** Whether the introspected schema differs from the snapshot in any way the comparator turns into SQL. */
|
|
31
|
+
private snapshotDiffers;
|
|
30
32
|
getStorage(): MigrationStorage;
|
|
31
33
|
/**
|
|
32
34
|
* Initial migration can be created only if:
|
package/Migrator.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Utils, t, Type, UnknownType, } from '@mikro-orm/core';
|
|
2
2
|
import { AbstractMigrator } from '@mikro-orm/core/migrations';
|
|
3
|
-
import { DatabaseSchema, DatabaseTable, } from '@mikro-orm/sql';
|
|
3
|
+
import { DatabaseSchema, DatabaseTable, SchemaComparator, } from '@mikro-orm/sql';
|
|
4
4
|
import { MigrationRunner } from './MigrationRunner.js';
|
|
5
5
|
import { MigrationStorage } from './MigrationStorage.js';
|
|
6
6
|
import { TSMigrationGenerator } from './TSMigrationGenerator.js';
|
|
@@ -149,6 +149,13 @@ export class Migrator extends AbstractMigrator {
|
|
|
149
149
|
if (result.length > 0 && this.options.snapshot) {
|
|
150
150
|
const ctx = Utils.isObject(options) ? options.transaction : undefined;
|
|
151
151
|
const schema = await DatabaseSchema.create(this.em.getConnection(), this.em.getPlatform(), this.config, undefined, undefined, undefined, undefined, undefined, ctx);
|
|
152
|
+
// keep the snapshot authored by `migration:create` when the migrated DB still matches it
|
|
153
|
+
// semantically — rewriting it from introspection only churns cosmetic serialization noise
|
|
154
|
+
// (expression casing/reformatting, native-enum mapped type, index method, ...) into the diff
|
|
155
|
+
const existing = await this.getSchemaFromSnapshot();
|
|
156
|
+
if (existing && !this.snapshotDiffers(existing, schema)) {
|
|
157
|
+
return result;
|
|
158
|
+
}
|
|
152
159
|
try {
|
|
153
160
|
await this.storeCurrentSchema(schema);
|
|
154
161
|
}
|
|
@@ -158,6 +165,12 @@ export class Migrator extends AbstractMigrator {
|
|
|
158
165
|
}
|
|
159
166
|
return result;
|
|
160
167
|
}
|
|
168
|
+
/** Whether the introspected schema differs from the snapshot in any way the comparator turns into SQL. */
|
|
169
|
+
snapshotDiffers(snapshot, schema) {
|
|
170
|
+
const comparator = new SchemaComparator(this.driver.getPlatform());
|
|
171
|
+
const diff = comparator.compare(snapshot, schema);
|
|
172
|
+
return this.#schemaGenerator.diffToSQL(diff, { wrap: false, safe: false, dropTables: true }).trim().length > 0;
|
|
173
|
+
}
|
|
161
174
|
getStorage() {
|
|
162
175
|
return this.storage;
|
|
163
176
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mikro-orm/migrations",
|
|
3
|
-
"version": "7.1.2-dev.
|
|
3
|
+
"version": "7.1.2-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.1.2-dev.
|
|
50
|
+
"@mikro-orm/sql": "7.1.2-dev.15"
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
53
|
"@mikro-orm/core": "^7.1.1"
|
|
54
54
|
},
|
|
55
55
|
"peerDependencies": {
|
|
56
|
-
"@mikro-orm/core": "7.1.2-dev.
|
|
56
|
+
"@mikro-orm/core": "7.1.2-dev.15"
|
|
57
57
|
},
|
|
58
58
|
"engines": {
|
|
59
59
|
"node": ">= 22.17.0"
|