@mikro-orm/migrations 6.4.7-dev.0 → 7.0.0-dev.0
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/Migration.d.ts +5 -6
- package/Migration.js +1 -4
- package/MigrationStorage.d.ts +2 -2
- package/MigrationStorage.js +32 -19
- package/README.md +0 -2
- package/package.json +5 -5
package/Migration.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import type
|
|
2
|
-
import type { AbstractSqlDriver,
|
|
3
|
-
export type Query = string |
|
|
1
|
+
import { type Configuration, type RawQueryFragment, type Transaction } from '@mikro-orm/core';
|
|
2
|
+
import type { AbstractSqlDriver, EntityManager, NativeQueryBuilder } from '@mikro-orm/knex';
|
|
3
|
+
export type Query = string | NativeQueryBuilder | RawQueryFragment;
|
|
4
4
|
export declare abstract class Migration {
|
|
5
5
|
protected readonly driver: AbstractSqlDriver;
|
|
6
6
|
protected readonly config: Configuration;
|
|
7
7
|
private readonly queries;
|
|
8
|
-
protected ctx?: Transaction
|
|
8
|
+
protected ctx?: Transaction;
|
|
9
9
|
private em?;
|
|
10
10
|
constructor(driver: AbstractSqlDriver, config: Configuration);
|
|
11
11
|
abstract up(): Promise<void> | void;
|
|
@@ -15,11 +15,10 @@ export declare abstract class Migration {
|
|
|
15
15
|
reset(): void;
|
|
16
16
|
setTransactionContext(ctx: Transaction): void;
|
|
17
17
|
/**
|
|
18
|
-
* Executes a raw SQL query. Accepts a string SQL or a
|
|
18
|
+
* Executes a raw SQL query. Accepts a string SQL, `raw()` SQL fragment, or a native query builder instance.
|
|
19
19
|
* The `params` parameter is respected only if you use string SQL in the first parameter.
|
|
20
20
|
*/
|
|
21
21
|
execute(sql: Query, params?: unknown[]): Promise<import("@mikro-orm/core").EntityData<Partial<any>>[]>;
|
|
22
|
-
getKnex(): Knex<any, any[]>;
|
|
23
22
|
/**
|
|
24
23
|
* Creates a cached `EntityManager` instance for this migration, which will respect
|
|
25
24
|
* the current transaction context.
|
package/Migration.js
CHANGED
|
@@ -28,15 +28,12 @@ class Migration {
|
|
|
28
28
|
this.ctx = ctx;
|
|
29
29
|
}
|
|
30
30
|
/**
|
|
31
|
-
* Executes a raw SQL query. Accepts a string SQL or a
|
|
31
|
+
* Executes a raw SQL query. Accepts a string SQL, `raw()` SQL fragment, or a native query builder instance.
|
|
32
32
|
* The `params` parameter is respected only if you use string SQL in the first parameter.
|
|
33
33
|
*/
|
|
34
34
|
async execute(sql, params) {
|
|
35
35
|
return this.driver.execute(sql, params, 'all', this.ctx);
|
|
36
36
|
}
|
|
37
|
-
getKnex() {
|
|
38
|
-
return this.driver.getConnection('write').getKnex();
|
|
39
|
-
}
|
|
40
37
|
/**
|
|
41
38
|
* Creates a cached `EntityManager` instance for this migration, which will respect
|
|
42
39
|
* the current transaction context.
|
package/MigrationStorage.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { MigrationsOptions, Transaction } from '@mikro-orm/core';
|
|
2
|
-
import type
|
|
2
|
+
import { type AbstractSqlDriver } from '@mikro-orm/knex';
|
|
3
3
|
import type { MigrationParams, UmzugStorage } from 'umzug';
|
|
4
4
|
import type { MigrationRow } from './typings';
|
|
5
5
|
export declare class MigrationStorage implements UmzugStorage {
|
|
@@ -8,6 +8,7 @@ export declare class MigrationStorage implements UmzugStorage {
|
|
|
8
8
|
private readonly connection;
|
|
9
9
|
private readonly helper;
|
|
10
10
|
private masterTransaction?;
|
|
11
|
+
private readonly platform;
|
|
11
12
|
constructor(driver: AbstractSqlDriver, options: MigrationsOptions);
|
|
12
13
|
executed(): Promise<string[]>;
|
|
13
14
|
logMigration(params: MigrationParams<any>): Promise<void>;
|
|
@@ -27,5 +28,4 @@ export declare class MigrationStorage implements UmzugStorage {
|
|
|
27
28
|
tableName: string;
|
|
28
29
|
schemaName: string;
|
|
29
30
|
};
|
|
30
|
-
private get knex();
|
|
31
31
|
}
|
package/MigrationStorage.js
CHANGED
|
@@ -34,6 +34,7 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
36
|
exports.MigrationStorage = void 0;
|
|
37
|
+
const knex_1 = require("@mikro-orm/knex");
|
|
37
38
|
const path = __importStar(require("node:path"));
|
|
38
39
|
class MigrationStorage {
|
|
39
40
|
driver;
|
|
@@ -41,11 +42,13 @@ class MigrationStorage {
|
|
|
41
42
|
connection;
|
|
42
43
|
helper;
|
|
43
44
|
masterTransaction;
|
|
45
|
+
platform;
|
|
44
46
|
constructor(driver, options) {
|
|
45
47
|
this.driver = driver;
|
|
46
48
|
this.options = options;
|
|
47
49
|
this.connection = this.driver.getConnection();
|
|
48
|
-
this.
|
|
50
|
+
this.platform = this.driver.getPlatform();
|
|
51
|
+
this.helper = this.platform.getSchemaHelper();
|
|
49
52
|
}
|
|
50
53
|
async executed() {
|
|
51
54
|
const migrations = await this.getExecutedMigrations();
|
|
@@ -60,19 +63,14 @@ class MigrationStorage {
|
|
|
60
63
|
const { tableName, schemaName } = this.getTableName();
|
|
61
64
|
const withoutExt = this.getMigrationName(params.name);
|
|
62
65
|
const names = [withoutExt, withoutExt + '.js', withoutExt + '.ts'];
|
|
63
|
-
|
|
64
|
-
if (this.masterTransaction) {
|
|
65
|
-
qb.transacting(this.masterTransaction);
|
|
66
|
-
}
|
|
67
|
-
await this.connection.execute(qb);
|
|
66
|
+
await this.driver.nativeDelete(tableName, { name: { $in: [params.name, ...names] } }, { schema: schemaName, ctx: this.masterTransaction });
|
|
68
67
|
}
|
|
69
68
|
async getExecutedMigrations() {
|
|
70
69
|
const { tableName, schemaName } = this.getTableName();
|
|
71
|
-
const
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
const res = await this.connection.execute(qb);
|
|
70
|
+
const res = await this.driver.createQueryBuilder(tableName, this.masterTransaction)
|
|
71
|
+
.withSchema(schemaName)
|
|
72
|
+
.orderBy({ id: 'asc' })
|
|
73
|
+
.execute();
|
|
76
74
|
return res.map(row => {
|
|
77
75
|
if (typeof row.executed_at === 'string') {
|
|
78
76
|
row.executed_at = new Date(row.executed_at);
|
|
@@ -91,11 +89,29 @@ class MigrationStorage {
|
|
|
91
89
|
const sql = this.helper.getCreateNamespaceSQL(schemaName);
|
|
92
90
|
await this.connection.execute(sql);
|
|
93
91
|
}
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
92
|
+
const table = new knex_1.DatabaseTable(this.platform, tableName, schemaName);
|
|
93
|
+
table.addColumn({
|
|
94
|
+
name: 'id',
|
|
95
|
+
type: this.platform.getIntegerTypeDeclarationSQL({ autoincrement: true, unsigned: true }),
|
|
96
|
+
mappedType: this.platform.getMappedType('number'),
|
|
97
|
+
primary: true,
|
|
98
|
+
autoincrement: true,
|
|
99
|
+
});
|
|
100
|
+
table.addColumn({
|
|
101
|
+
name: 'name',
|
|
102
|
+
type: this.platform.getVarcharTypeDeclarationSQL({}),
|
|
103
|
+
mappedType: this.platform.getMappedType('string'),
|
|
104
|
+
});
|
|
105
|
+
const length = this.platform.getDefaultDateTimeLength();
|
|
106
|
+
table.addColumn({
|
|
107
|
+
name: 'executed_at',
|
|
108
|
+
type: this.platform.getDateTimeTypeDeclarationSQL({ length }),
|
|
109
|
+
mappedType: this.platform.getMappedType('datetime'),
|
|
110
|
+
default: this.platform.getCurrentTimestampSQL(length),
|
|
111
|
+
length,
|
|
112
|
+
});
|
|
113
|
+
const sql = this.helper.createTable(table);
|
|
114
|
+
await this.connection.execute(sql.join(';\n'));
|
|
99
115
|
}
|
|
100
116
|
setMasterMigration(trx) {
|
|
101
117
|
this.masterTransaction = trx;
|
|
@@ -123,8 +139,5 @@ class MigrationStorage {
|
|
|
123
139
|
const schemaName = parts.length > 1 ? parts[0] : this.driver.config.get('schema', this.driver.getPlatform().getDefaultSchemaName());
|
|
124
140
|
return { tableName, schemaName };
|
|
125
141
|
}
|
|
126
|
-
get knex() {
|
|
127
|
-
return this.connection.getKnex();
|
|
128
|
-
}
|
|
129
142
|
}
|
|
130
143
|
exports.MigrationStorage = MigrationStorage;
|
package/README.md
CHANGED
|
@@ -183,7 +183,6 @@ yarn add @mikro-orm/core @mikro-orm/mariadb # for mysql/mariadb
|
|
|
183
183
|
yarn add @mikro-orm/core @mikro-orm/postgresql # for postgresql
|
|
184
184
|
yarn add @mikro-orm/core @mikro-orm/mssql # for mssql
|
|
185
185
|
yarn add @mikro-orm/core @mikro-orm/sqlite # for sqlite
|
|
186
|
-
yarn add @mikro-orm/core @mikro-orm/better-sqlite # for better-sqlite
|
|
187
186
|
yarn add @mikro-orm/core @mikro-orm/libsql # for libsql
|
|
188
187
|
```
|
|
189
188
|
|
|
@@ -196,7 +195,6 @@ npm i -s @mikro-orm/core @mikro-orm/mariadb # for mysql/mariadb
|
|
|
196
195
|
npm i -s @mikro-orm/core @mikro-orm/postgresql # for postgresql
|
|
197
196
|
npm i -s @mikro-orm/core @mikro-orm/mssql # for mssql
|
|
198
197
|
npm i -s @mikro-orm/core @mikro-orm/sqlite # for sqlite
|
|
199
|
-
npm i -s @mikro-orm/core @mikro-orm/better-sqlite # for better-sqlite
|
|
200
198
|
npm i -s @mikro-orm/core @mikro-orm/libsql # for libsql
|
|
201
199
|
```
|
|
202
200
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mikro-orm/migrations",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "7.0.0-dev.0",
|
|
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
|
"main": "index.js",
|
|
6
6
|
"module": "index.mjs",
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
},
|
|
47
47
|
"homepage": "https://mikro-orm.io",
|
|
48
48
|
"engines": {
|
|
49
|
-
"node": ">=
|
|
49
|
+
"node": ">= 22.11.0"
|
|
50
50
|
},
|
|
51
51
|
"scripts": {
|
|
52
52
|
"build": "yarn clean && yarn compile && yarn copy && yarn run -T gen-esm-wrapper index.js index.mjs",
|
|
@@ -58,14 +58,14 @@
|
|
|
58
58
|
"access": "public"
|
|
59
59
|
},
|
|
60
60
|
"dependencies": {
|
|
61
|
-
"@mikro-orm/knex": "
|
|
61
|
+
"@mikro-orm/knex": "7.0.0-dev.0",
|
|
62
62
|
"fs-extra": "11.3.0",
|
|
63
63
|
"umzug": "3.8.2"
|
|
64
64
|
},
|
|
65
65
|
"devDependencies": {
|
|
66
|
-
"@mikro-orm/core": "^6.4.
|
|
66
|
+
"@mikro-orm/core": "^6.4.5"
|
|
67
67
|
},
|
|
68
68
|
"peerDependencies": {
|
|
69
|
-
"@mikro-orm/core": "
|
|
69
|
+
"@mikro-orm/core": "7.0.0-dev.0"
|
|
70
70
|
}
|
|
71
71
|
}
|