@mikro-orm/migrations 7.0.0-dev.113 → 7.0.0-dev.115
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/MigrationStorage.d.ts +2 -1
- package/MigrationStorage.js +20 -8
- package/Migrator.js +1 -1
- package/package.json +3 -3
- package/tsconfig.build.tsbuildinfo +1 -1
package/MigrationStorage.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type MigrationsOptions, type Transaction, type EntitySchema } from '@mikro-orm/core';
|
|
2
2
|
import { type AbstractSqlDriver } from '@mikro-orm/sql';
|
|
3
3
|
import type { MigrationParams, UmzugStorage } from 'umzug';
|
|
4
4
|
import type { MigrationRow } from './typings.js';
|
|
@@ -27,5 +27,6 @@ export declare class MigrationStorage implements UmzugStorage {
|
|
|
27
27
|
getTableName(): {
|
|
28
28
|
tableName: string;
|
|
29
29
|
schemaName: string;
|
|
30
|
+
entity: EntitySchema;
|
|
30
31
|
};
|
|
31
32
|
}
|
package/MigrationStorage.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { defineEntity, p } from '@mikro-orm/core';
|
|
1
2
|
import { DatabaseTable, } from '@mikro-orm/sql';
|
|
2
3
|
import { parse } from 'node:path';
|
|
3
4
|
export class MigrationStorage {
|
|
@@ -19,22 +20,22 @@ export class MigrationStorage {
|
|
|
19
20
|
return migrations.map(({ name }) => `${this.getMigrationName(name)}`);
|
|
20
21
|
}
|
|
21
22
|
async logMigration(params) {
|
|
22
|
-
const {
|
|
23
|
+
const { entity } = this.getTableName();
|
|
23
24
|
const name = this.getMigrationName(params.name);
|
|
24
|
-
await this.driver.nativeInsert(
|
|
25
|
+
await this.driver.nativeInsert(entity, { name }, { ctx: this.masterTransaction });
|
|
25
26
|
}
|
|
26
27
|
async unlogMigration(params) {
|
|
27
|
-
const {
|
|
28
|
+
const { entity } = this.getTableName();
|
|
28
29
|
const withoutExt = this.getMigrationName(params.name);
|
|
29
30
|
const names = [withoutExt, withoutExt + '.js', withoutExt + '.ts'];
|
|
30
|
-
await this.driver.nativeDelete(
|
|
31
|
+
await this.driver.nativeDelete(entity, { name: { $in: [params.name, ...names] } }, { ctx: this.masterTransaction });
|
|
31
32
|
}
|
|
32
33
|
async getExecutedMigrations() {
|
|
33
|
-
const {
|
|
34
|
-
const res = await this.driver.createQueryBuilder(
|
|
34
|
+
const { entity, schemaName } = this.getTableName();
|
|
35
|
+
const res = await this.driver.createQueryBuilder(entity, this.masterTransaction)
|
|
35
36
|
.withSchema(schemaName)
|
|
36
37
|
.orderBy({ id: 'asc' })
|
|
37
|
-
.execute();
|
|
38
|
+
.execute('all', false);
|
|
38
39
|
return res.map(row => {
|
|
39
40
|
if (typeof row.executed_at === 'string') {
|
|
40
41
|
row.executed_at = new Date(row.executed_at);
|
|
@@ -101,6 +102,17 @@ export class MigrationStorage {
|
|
|
101
102
|
const parts = this.options.tableName.split('.');
|
|
102
103
|
const tableName = parts.length > 1 ? parts[1] : parts[0];
|
|
103
104
|
const schemaName = parts.length > 1 ? parts[0] : this.driver.config.get('schema', this.driver.getPlatform().getDefaultSchemaName());
|
|
104
|
-
|
|
105
|
+
const entity = defineEntity({
|
|
106
|
+
name: 'Migration',
|
|
107
|
+
tableName,
|
|
108
|
+
schema: schemaName,
|
|
109
|
+
properties: {
|
|
110
|
+
id: p.integer().primary().fieldNames('id'),
|
|
111
|
+
name: p.string().fieldNames('name'),
|
|
112
|
+
executedAt: p.datetime().defaultRaw('current_timestamp').fieldNames('executed_at'),
|
|
113
|
+
},
|
|
114
|
+
}).init();
|
|
115
|
+
entity.meta.sync();
|
|
116
|
+
return { tableName, schemaName, entity };
|
|
105
117
|
}
|
|
106
118
|
}
|
package/Migrator.js
CHANGED
|
@@ -181,7 +181,7 @@ export class Migrator {
|
|
|
181
181
|
const schema = await DatabaseSchema.create(this.em.getConnection(), this.em.getPlatform(), this.config);
|
|
182
182
|
const exists = new Set();
|
|
183
183
|
const expected = new Set();
|
|
184
|
-
|
|
184
|
+
[...this.em.getMetadata().getAll().values()]
|
|
185
185
|
.filter(meta => meta.tableName && !meta.embeddable && !meta.virtual)
|
|
186
186
|
.forEach(meta => {
|
|
187
187
|
const schema = meta.schema ?? this.config.get('schema', this.em.getPlatform().getDefaultSchemaName());
|
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.115",
|
|
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,13 +50,13 @@
|
|
|
50
50
|
"access": "public"
|
|
51
51
|
},
|
|
52
52
|
"dependencies": {
|
|
53
|
-
"@mikro-orm/sql": "7.0.0-dev.
|
|
53
|
+
"@mikro-orm/sql": "7.0.0-dev.115",
|
|
54
54
|
"umzug": "3.8.2"
|
|
55
55
|
},
|
|
56
56
|
"devDependencies": {
|
|
57
57
|
"@mikro-orm/core": "^6.6.2"
|
|
58
58
|
},
|
|
59
59
|
"peerDependencies": {
|
|
60
|
-
"@mikro-orm/core": "7.0.0-dev.
|
|
60
|
+
"@mikro-orm/core": "7.0.0-dev.115"
|
|
61
61
|
}
|
|
62
62
|
}
|