@mikro-orm/migrations 7.0.0-dev.32 → 7.0.0-dev.320
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 +3 -3
- package/Migration.d.ts +1 -1
- package/MigrationGenerator.d.ts +1 -1
- package/MigrationGenerator.js +5 -6
- package/MigrationRunner.d.ts +1 -1
- package/MigrationRunner.js +1 -1
- package/MigrationStorage.d.ts +10 -6
- package/MigrationStorage.js +25 -18
- package/Migrator.d.ts +18 -55
- package/Migrator.js +110 -202
- package/README.md +7 -4
- package/TSMigrationGenerator.js +2 -2
- package/index.d.ts +1 -1
- package/index.js +0 -1
- package/package.json +32 -33
- package/tsconfig.build.tsbuildinfo +1 -0
- package/typings.d.ts +1 -1
package/Migrator.js
CHANGED
|
@@ -1,53 +1,65 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { t, Type, UnknownType, Utils, } from '@mikro-orm/core';
|
|
5
|
-
import { DatabaseSchema, DatabaseTable, SqlSchemaGenerator, } from '@mikro-orm/knex';
|
|
1
|
+
import { t, Type, UnknownType, } from '@mikro-orm/core';
|
|
2
|
+
import { AbstractMigrator } from '@mikro-orm/core/migrations';
|
|
3
|
+
import { DatabaseSchema, DatabaseTable, } from '@mikro-orm/sql';
|
|
6
4
|
import { MigrationRunner } from './MigrationRunner.js';
|
|
7
5
|
import { MigrationStorage } from './MigrationStorage.js';
|
|
8
6
|
import { TSMigrationGenerator } from './TSMigrationGenerator.js';
|
|
9
7
|
import { JSMigrationGenerator } from './JSMigrationGenerator.js';
|
|
10
|
-
export class Migrator {
|
|
11
|
-
em;
|
|
12
|
-
umzug;
|
|
13
|
-
runner;
|
|
14
|
-
storage;
|
|
15
|
-
generator;
|
|
16
|
-
driver;
|
|
8
|
+
export class Migrator extends AbstractMigrator {
|
|
17
9
|
schemaGenerator;
|
|
18
|
-
config;
|
|
19
|
-
options;
|
|
20
|
-
absolutePath;
|
|
21
10
|
snapshotPath;
|
|
22
11
|
constructor(em) {
|
|
23
|
-
|
|
24
|
-
this.
|
|
25
|
-
this.schemaGenerator = new SqlSchemaGenerator(this.em);
|
|
26
|
-
this.config = this.em.config;
|
|
27
|
-
this.options = this.config.get('migrations');
|
|
28
|
-
/* v8 ignore next */
|
|
29
|
-
const key = (this.config.get('preferTs', Utils.detectTypeScriptSupport()) && this.options.pathTs) ? 'pathTs' : 'path';
|
|
30
|
-
this.absolutePath = Utils.absolutePath(this.options[key], this.config.get('baseDir'));
|
|
31
|
-
// for snapshots, we always want to use the path based on `emit` option, regardless of whether we run in TS context
|
|
32
|
-
/* v8 ignore next */
|
|
33
|
-
const snapshotPath = this.options.emit === 'ts' && this.options.pathTs ? this.options.pathTs : this.options.path;
|
|
34
|
-
const absoluteSnapshotPath = Utils.absolutePath(snapshotPath, this.config.get('baseDir'));
|
|
35
|
-
const dbName = basename(this.config.get('dbName'));
|
|
36
|
-
const snapshotName = this.options.snapshotName ?? `.snapshot-${dbName}`;
|
|
37
|
-
this.snapshotPath = Utils.normalizePath(absoluteSnapshotPath, `${snapshotName}.json`);
|
|
38
|
-
this.createUmzug();
|
|
12
|
+
super(em);
|
|
13
|
+
this.schemaGenerator = this.config.getExtension('@mikro-orm/schema-generator');
|
|
39
14
|
}
|
|
40
15
|
static register(orm) {
|
|
41
16
|
orm.config.registerExtension('@mikro-orm/migrator', () => new Migrator(orm.em));
|
|
42
17
|
}
|
|
18
|
+
createRunner() {
|
|
19
|
+
return new MigrationRunner(this.driver, this.options, this.config);
|
|
20
|
+
}
|
|
21
|
+
createStorage() {
|
|
22
|
+
return new MigrationStorage(this.driver, this.options);
|
|
23
|
+
}
|
|
24
|
+
getDefaultGenerator() {
|
|
25
|
+
if (this.options.emit === 'js' || this.options.emit === 'cjs') {
|
|
26
|
+
return new JSMigrationGenerator(this.driver, this.config.getNamingStrategy(), this.options);
|
|
27
|
+
}
|
|
28
|
+
return new TSMigrationGenerator(this.driver, this.config.getNamingStrategy(), this.options);
|
|
29
|
+
}
|
|
30
|
+
async getSnapshotPath() {
|
|
31
|
+
if (!this.snapshotPath) {
|
|
32
|
+
const { fs } = await import('@mikro-orm/core/fs-utils');
|
|
33
|
+
// for snapshots, we always want to use the path based on `emit` option, regardless of whether we run in TS context
|
|
34
|
+
/* v8 ignore next */
|
|
35
|
+
const snapshotPath = this.options.emit === 'ts' && this.options.pathTs ? this.options.pathTs : this.options.path;
|
|
36
|
+
const absoluteSnapshotPath = fs.absolutePath(snapshotPath, this.config.get('baseDir'));
|
|
37
|
+
const dbName = this.config.get('dbName').replace(/\\/g, '/').split('/').pop().replace(/:/g, '');
|
|
38
|
+
const snapshotName = this.options.snapshotName ?? `.snapshot-${dbName}`;
|
|
39
|
+
this.snapshotPath = fs.normalizePath(absoluteSnapshotPath, `${snapshotName}.json`);
|
|
40
|
+
}
|
|
41
|
+
return this.snapshotPath;
|
|
42
|
+
}
|
|
43
|
+
async init() {
|
|
44
|
+
if (this.initialized) {
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
await super.init();
|
|
48
|
+
const created = await this.schemaGenerator.ensureDatabase();
|
|
49
|
+
/* v8 ignore next */
|
|
50
|
+
if (created) {
|
|
51
|
+
this.initServices();
|
|
52
|
+
}
|
|
53
|
+
await this.storage.ensureTable();
|
|
54
|
+
}
|
|
43
55
|
/**
|
|
44
56
|
* @inheritDoc
|
|
45
57
|
*/
|
|
46
|
-
async
|
|
58
|
+
async create(path, blank = false, initial = false, name) {
|
|
59
|
+
await this.init();
|
|
47
60
|
if (initial) {
|
|
48
|
-
return this.
|
|
61
|
+
return this.createInitial(path, name, blank);
|
|
49
62
|
}
|
|
50
|
-
this.ensureMigrationsDirExists();
|
|
51
63
|
const diff = await this.getSchemaDiff(blank, initial);
|
|
52
64
|
if (diff.up.length === 0) {
|
|
53
65
|
return { fileName: '', code: '', diff };
|
|
@@ -60,22 +72,22 @@ export class Migrator {
|
|
|
60
72
|
diff,
|
|
61
73
|
};
|
|
62
74
|
}
|
|
63
|
-
async
|
|
64
|
-
this.
|
|
75
|
+
async checkSchema() {
|
|
76
|
+
await this.init();
|
|
65
77
|
const diff = await this.getSchemaDiff(false, false);
|
|
66
78
|
return diff.up.length > 0;
|
|
67
79
|
}
|
|
68
80
|
/**
|
|
69
81
|
* @inheritDoc
|
|
70
82
|
*/
|
|
71
|
-
async
|
|
72
|
-
this.
|
|
83
|
+
async createInitial(path, name, blank = false) {
|
|
84
|
+
await this.init();
|
|
73
85
|
const schemaExists = await this.validateInitialMigration(blank);
|
|
74
86
|
const diff = await this.getSchemaDiff(blank, true);
|
|
75
87
|
const migration = await this.generator.generate(diff, path, name);
|
|
76
88
|
await this.storeCurrentSchema();
|
|
77
89
|
if (schemaExists && !blank) {
|
|
78
|
-
await this.storage.logMigration({ name: migration[1]
|
|
90
|
+
await this.storage.logMigration({ name: migration[1] });
|
|
79
91
|
}
|
|
80
92
|
return {
|
|
81
93
|
fileName: migration[1],
|
|
@@ -83,56 +95,21 @@ export class Migrator {
|
|
|
83
95
|
diff,
|
|
84
96
|
};
|
|
85
97
|
}
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
off(eventName, listener) {
|
|
97
|
-
this.umzug.off(eventName, listener);
|
|
98
|
-
return this;
|
|
99
|
-
}
|
|
100
|
-
createUmzug() {
|
|
101
|
-
this.runner = new MigrationRunner(this.driver, this.options, this.config);
|
|
102
|
-
this.storage = new MigrationStorage(this.driver, this.options);
|
|
103
|
-
let migrations = {
|
|
104
|
-
glob: join(this.absolutePath, this.options.glob).replace(/\\/g, '/'),
|
|
105
|
-
resolve: (params) => this.resolve(params),
|
|
106
|
-
};
|
|
107
|
-
if (this.options.migrationsList) {
|
|
108
|
-
migrations = this.options.migrationsList.map(migration => {
|
|
109
|
-
if (typeof migration === 'function') {
|
|
110
|
-
return this.initialize(migration, migration.name);
|
|
111
|
-
}
|
|
112
|
-
return this.initialize(migration.class, migration.name);
|
|
113
|
-
});
|
|
114
|
-
}
|
|
115
|
-
this.umzug = new Umzug({
|
|
116
|
-
storage: this.storage,
|
|
117
|
-
logger: undefined,
|
|
118
|
-
migrations,
|
|
119
|
-
});
|
|
120
|
-
if (!this.options.silent) {
|
|
121
|
-
const logger = this.config.getLogger();
|
|
122
|
-
this.umzug.on('migrating', event => logger.log('migrator', `Processing '${event.name}'`, { enabled: true }));
|
|
123
|
-
this.umzug.on('migrated', event => logger.log('migrator', `Applied '${event.name}'`, { enabled: true }));
|
|
124
|
-
this.umzug.on('reverting', event => logger.log('migrator', `Processing '${event.name}'`, { enabled: true }));
|
|
125
|
-
this.umzug.on('reverted', event => logger.log('migrator', `Reverted '${event.name}'`, { enabled: true }));
|
|
126
|
-
}
|
|
127
|
-
if (this.options.generator) {
|
|
128
|
-
this.generator = new this.options.generator(this.driver, this.config.getNamingStrategy(), this.options);
|
|
129
|
-
}
|
|
130
|
-
else if (this.options.emit === 'js' || this.options.emit === 'cjs') {
|
|
131
|
-
this.generator = new JSMigrationGenerator(this.driver, this.config.getNamingStrategy(), this.options);
|
|
132
|
-
}
|
|
133
|
-
else {
|
|
134
|
-
this.generator = new TSMigrationGenerator(this.driver, this.config.getNamingStrategy(), this.options);
|
|
98
|
+
async runMigrations(method, options) {
|
|
99
|
+
const result = await super.runMigrations(method, options);
|
|
100
|
+
if (result.length > 0 && this.options.snapshot) {
|
|
101
|
+
const schema = await DatabaseSchema.create(this.em.getConnection(), this.em.getPlatform(), this.config);
|
|
102
|
+
try {
|
|
103
|
+
await this.storeCurrentSchema(schema);
|
|
104
|
+
}
|
|
105
|
+
catch {
|
|
106
|
+
// Silently ignore for read-only filesystems (production).
|
|
107
|
+
}
|
|
135
108
|
}
|
|
109
|
+
return result;
|
|
110
|
+
}
|
|
111
|
+
getStorage() {
|
|
112
|
+
return this.storage;
|
|
136
113
|
}
|
|
137
114
|
/**
|
|
138
115
|
* Initial migration can be created only if:
|
|
@@ -143,15 +120,15 @@ export class Migrator {
|
|
|
143
120
|
* If only some of the tables are present, exception is thrown.
|
|
144
121
|
*/
|
|
145
122
|
async validateInitialMigration(blank) {
|
|
146
|
-
const executed = await this.
|
|
147
|
-
const pending = await this.
|
|
123
|
+
const executed = await this.getExecuted();
|
|
124
|
+
const pending = await this.getPending();
|
|
148
125
|
if (executed.length > 0 || pending.length > 0) {
|
|
149
126
|
throw new Error('Initial migration cannot be created, as some migrations already exist');
|
|
150
127
|
}
|
|
151
128
|
const schema = await DatabaseSchema.create(this.em.getConnection(), this.em.getPlatform(), this.config);
|
|
152
129
|
const exists = new Set();
|
|
153
130
|
const expected = new Set();
|
|
154
|
-
|
|
131
|
+
[...this.em.getMetadata().getAll().values()]
|
|
155
132
|
.filter(meta => meta.tableName && !meta.embeddable && !meta.virtual)
|
|
156
133
|
.forEach(meta => {
|
|
157
134
|
const schema = meta.schema ?? this.config.get('schema', this.em.getPlatform().getDefaultSchemaName());
|
|
@@ -172,62 +149,16 @@ export class Migrator {
|
|
|
172
149
|
}
|
|
173
150
|
return expected.size === exists.size;
|
|
174
151
|
}
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
async getExecutedMigrations() {
|
|
179
|
-
await this.ensureDatabase();
|
|
180
|
-
return this.storage.getExecutedMigrations();
|
|
181
|
-
}
|
|
182
|
-
async ensureDatabase() {
|
|
183
|
-
this.ensureMigrationsDirExists();
|
|
184
|
-
const created = await this.schemaGenerator.ensureDatabase();
|
|
185
|
-
/* v8 ignore next 3 */
|
|
186
|
-
if (created) {
|
|
187
|
-
this.createUmzug();
|
|
152
|
+
async getSchemaFromSnapshot() {
|
|
153
|
+
if (!this.options.snapshot) {
|
|
154
|
+
return undefined;
|
|
188
155
|
}
|
|
189
|
-
await this.
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
* @inheritDoc
|
|
193
|
-
*/
|
|
194
|
-
async getPendingMigrations() {
|
|
195
|
-
await this.ensureDatabase();
|
|
196
|
-
return this.umzug.pending();
|
|
197
|
-
}
|
|
198
|
-
/**
|
|
199
|
-
* @inheritDoc
|
|
200
|
-
*/
|
|
201
|
-
async up(options) {
|
|
202
|
-
return this.runMigrations('up', options);
|
|
203
|
-
}
|
|
204
|
-
/**
|
|
205
|
-
* @inheritDoc
|
|
206
|
-
*/
|
|
207
|
-
async down(options) {
|
|
208
|
-
return this.runMigrations('down', options);
|
|
209
|
-
}
|
|
210
|
-
getStorage() {
|
|
211
|
-
return this.storage;
|
|
212
|
-
}
|
|
213
|
-
resolve(params) {
|
|
214
|
-
const createMigrationHandler = async (method) => {
|
|
215
|
-
const migration = await Utils.dynamicImport(params.path);
|
|
216
|
-
const MigrationClass = Object.values(migration).find(cls => typeof cls === 'function' && typeof cls.constructor === 'function');
|
|
217
|
-
const instance = new MigrationClass(this.driver, this.config);
|
|
218
|
-
await this.runner.run(instance, method);
|
|
219
|
-
};
|
|
220
|
-
return {
|
|
221
|
-
name: this.storage.getMigrationName(params.name),
|
|
222
|
-
up: () => createMigrationHandler('up'),
|
|
223
|
-
down: () => createMigrationHandler('down'),
|
|
224
|
-
};
|
|
225
|
-
}
|
|
226
|
-
getSchemaFromSnapshot() {
|
|
227
|
-
if (!this.options.snapshot || !existsSync(this.snapshotPath)) {
|
|
156
|
+
const snapshotPath = await this.getSnapshotPath();
|
|
157
|
+
const { fs } = await import('@mikro-orm/core/fs-utils');
|
|
158
|
+
if (!fs.pathExists(snapshotPath)) {
|
|
228
159
|
return undefined;
|
|
229
160
|
}
|
|
230
|
-
const data =
|
|
161
|
+
const data = fs.readJSONSync(snapshotPath);
|
|
231
162
|
const schema = new DatabaseSchema(this.driver.getPlatform(), this.config.get('schema'));
|
|
232
163
|
const { tables, namespaces, ...rest } = data;
|
|
233
164
|
const tableInstances = tables.map((tbl) => {
|
|
@@ -245,47 +176,67 @@ export class Migrator {
|
|
|
245
176
|
Object.assign(schema, { tables: tableInstances, namespaces: new Set(namespaces), ...rest });
|
|
246
177
|
return schema;
|
|
247
178
|
}
|
|
248
|
-
async storeCurrentSchema() {
|
|
179
|
+
async storeCurrentSchema(schema) {
|
|
249
180
|
if (!this.options.snapshot) {
|
|
250
181
|
return;
|
|
251
182
|
}
|
|
252
|
-
const
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
const instance = new MigrationClass(this.driver, this.config);
|
|
257
|
-
return {
|
|
258
|
-
name: this.storage.getMigrationName(name),
|
|
259
|
-
up: () => this.runner.run(instance, 'up'),
|
|
260
|
-
down: () => this.runner.run(instance, 'down'),
|
|
261
|
-
};
|
|
183
|
+
const snapshotPath = await this.getSnapshotPath();
|
|
184
|
+
schema ??= this.schemaGenerator.getTargetSchema();
|
|
185
|
+
const { fs } = await import('@mikro-orm/core/fs-utils');
|
|
186
|
+
await fs.writeFile(snapshotPath, JSON.stringify(schema, null, 2));
|
|
262
187
|
}
|
|
263
188
|
async getSchemaDiff(blank, initial) {
|
|
264
189
|
const up = [];
|
|
265
190
|
const down = [];
|
|
191
|
+
// Split SQL by statement boundaries (semicolons followed by newline) rather than
|
|
192
|
+
// just newlines, to preserve multiline statements like view definitions.
|
|
193
|
+
// Blank lines (from double newlines) are preserved as empty strings for grouping.
|
|
194
|
+
// Splits inside single-quoted string literals are re-merged (GH #7185).
|
|
195
|
+
const splitStatements = (sql) => {
|
|
196
|
+
const result = [];
|
|
197
|
+
let buf = '';
|
|
198
|
+
for (const chunk of sql.split(/;\n/)) {
|
|
199
|
+
buf += (buf ? ';\n' : '') + chunk;
|
|
200
|
+
// odd number of single quotes means we're inside a string literal
|
|
201
|
+
if (buf.split(`'`).length % 2 === 0) {
|
|
202
|
+
continue;
|
|
203
|
+
}
|
|
204
|
+
// A chunk starting with \n indicates there was a blank line (grouping separator)
|
|
205
|
+
if (buf.startsWith('\n')) {
|
|
206
|
+
result.push('');
|
|
207
|
+
}
|
|
208
|
+
const trimmed = buf.trim();
|
|
209
|
+
if (trimmed) {
|
|
210
|
+
result.push(trimmed.endsWith(';') ? trimmed : trimmed + ';');
|
|
211
|
+
}
|
|
212
|
+
buf = '';
|
|
213
|
+
}
|
|
214
|
+
return result;
|
|
215
|
+
};
|
|
266
216
|
if (blank) {
|
|
267
217
|
up.push('select 1');
|
|
268
218
|
down.push('select 1');
|
|
269
219
|
}
|
|
270
220
|
else if (initial) {
|
|
271
221
|
const dump = await this.schemaGenerator.getCreateSchemaSQL({ wrap: false });
|
|
272
|
-
up.push(...dump
|
|
222
|
+
up.push(...splitStatements(dump));
|
|
273
223
|
}
|
|
274
224
|
else {
|
|
275
225
|
const diff = await this.schemaGenerator.getUpdateSchemaMigrationSQL({
|
|
276
226
|
wrap: false,
|
|
277
227
|
safe: this.options.safe,
|
|
278
228
|
dropTables: this.options.dropTables,
|
|
279
|
-
fromSchema: this.getSchemaFromSnapshot(),
|
|
229
|
+
fromSchema: await this.getSchemaFromSnapshot(),
|
|
280
230
|
});
|
|
281
|
-
up.push(...diff.up
|
|
282
|
-
down.push(...diff.down
|
|
231
|
+
up.push(...splitStatements(diff.up));
|
|
232
|
+
down.push(...splitStatements(diff.down));
|
|
283
233
|
}
|
|
284
234
|
const cleanUp = (diff) => {
|
|
285
235
|
for (let i = diff.length - 1; i >= 0; i--) {
|
|
286
236
|
if (diff[i]) {
|
|
287
237
|
break;
|
|
288
238
|
}
|
|
239
|
+
/* v8 ignore next */
|
|
289
240
|
diff.splice(i, 1);
|
|
290
241
|
}
|
|
291
242
|
};
|
|
@@ -293,47 +244,4 @@ export class Migrator {
|
|
|
293
244
|
cleanUp(down);
|
|
294
245
|
return { up, down };
|
|
295
246
|
}
|
|
296
|
-
getMigrationFilename(name) {
|
|
297
|
-
name = name.replace(/\.[jt]s$/, '');
|
|
298
|
-
return name.match(/^\d{14}$/) ? this.options.fileName(name) : name;
|
|
299
|
-
}
|
|
300
|
-
prefix(options) {
|
|
301
|
-
if (Utils.isString(options) || Array.isArray(options)) {
|
|
302
|
-
return { migrations: Utils.asArray(options).map(name => this.getMigrationFilename(name)) };
|
|
303
|
-
}
|
|
304
|
-
if (!options) {
|
|
305
|
-
return {};
|
|
306
|
-
}
|
|
307
|
-
if (options.migrations) {
|
|
308
|
-
options.migrations = options.migrations.map(name => this.getMigrationFilename(name));
|
|
309
|
-
}
|
|
310
|
-
if (options.transaction) {
|
|
311
|
-
delete options.transaction;
|
|
312
|
-
}
|
|
313
|
-
['from', 'to'].filter(k => options[k]).forEach(k => options[k] = this.getMigrationFilename(options[k]));
|
|
314
|
-
return options;
|
|
315
|
-
}
|
|
316
|
-
async runMigrations(method, options) {
|
|
317
|
-
await this.ensureDatabase();
|
|
318
|
-
if (!this.options.transactional || !this.options.allOrNothing) {
|
|
319
|
-
return this.umzug[method](this.prefix(options));
|
|
320
|
-
}
|
|
321
|
-
if (Utils.isObject(options) && options.transaction) {
|
|
322
|
-
return this.runInTransaction(options.transaction, method, options);
|
|
323
|
-
}
|
|
324
|
-
return this.driver.getConnection().transactional(trx => this.runInTransaction(trx, method, options));
|
|
325
|
-
}
|
|
326
|
-
async runInTransaction(trx, method, options) {
|
|
327
|
-
this.runner.setMasterMigration(trx);
|
|
328
|
-
this.storage.setMasterMigration(trx);
|
|
329
|
-
const ret = await this.umzug[method](this.prefix(options));
|
|
330
|
-
this.runner.unsetMasterMigration();
|
|
331
|
-
this.storage.unsetMasterMigration();
|
|
332
|
-
return ret;
|
|
333
|
-
}
|
|
334
|
-
ensureMigrationsDirExists() {
|
|
335
|
-
if (!this.options.migrationsList) {
|
|
336
|
-
Utils.ensureDir(this.absolutePath);
|
|
337
|
-
}
|
|
338
|
-
}
|
|
339
247
|
}
|
package/README.md
CHANGED
|
@@ -2,14 +2,14 @@
|
|
|
2
2
|
<a href="https://mikro-orm.io"><img src="https://raw.githubusercontent.com/mikro-orm/mikro-orm/master/docs/static/img/logo-readme.svg?sanitize=true" alt="MikroORM" /></a>
|
|
3
3
|
</h1>
|
|
4
4
|
|
|
5
|
-
TypeScript ORM for Node.js based on Data Mapper, [Unit of Work](https://mikro-orm.io/docs/unit-of-work/) and [Identity Map](https://mikro-orm.io/docs/identity-map/) patterns. Supports MongoDB, MySQL, MariaDB, PostgreSQL
|
|
5
|
+
TypeScript ORM for Node.js based on Data Mapper, [Unit of Work](https://mikro-orm.io/docs/unit-of-work/) and [Identity Map](https://mikro-orm.io/docs/identity-map/) patterns. Supports MongoDB, MySQL, MariaDB, PostgreSQL, SQLite (including libSQL), MSSQL and Oracle databases.
|
|
6
6
|
|
|
7
7
|
> Heavily inspired by [Doctrine](https://www.doctrine-project.org/) and [Hibernate](https://hibernate.org/).
|
|
8
8
|
|
|
9
|
-
[](https://
|
|
10
|
-
[](https://
|
|
9
|
+
[](https://npmx.dev/package/@mikro-orm/core)
|
|
10
|
+
[](https://npmx.dev/package/@mikro-orm/core)
|
|
11
11
|
[](https://discord.gg/w8bjxFHS7X)
|
|
12
|
-
[](https://
|
|
12
|
+
[](https://npmx.dev/package/@mikro-orm/core)
|
|
13
13
|
[](https://coveralls.io/r/mikro-orm/mikro-orm?branch=master)
|
|
14
14
|
[](https://github.com/mikro-orm/mikro-orm/actions?workflow=tests)
|
|
15
15
|
|
|
@@ -181,6 +181,7 @@ yarn add @mikro-orm/core @mikro-orm/mysql # for mysql/mariadb
|
|
|
181
181
|
yarn add @mikro-orm/core @mikro-orm/mariadb # for mysql/mariadb
|
|
182
182
|
yarn add @mikro-orm/core @mikro-orm/postgresql # for postgresql
|
|
183
183
|
yarn add @mikro-orm/core @mikro-orm/mssql # for mssql
|
|
184
|
+
yarn add @mikro-orm/core @mikro-orm/oracledb # for oracle
|
|
184
185
|
yarn add @mikro-orm/core @mikro-orm/sqlite # for sqlite
|
|
185
186
|
yarn add @mikro-orm/core @mikro-orm/libsql # for libsql
|
|
186
187
|
```
|
|
@@ -381,6 +382,8 @@ See also the list of contributors who [participated](https://github.com/mikro-or
|
|
|
381
382
|
|
|
382
383
|
Please ⭐️ this repository if this project helped you!
|
|
383
384
|
|
|
385
|
+
> If you'd like to support my open-source work, consider sponsoring me directly at [github.com/sponsors/b4nan](https://github.com/sponsors/b4nan).
|
|
386
|
+
|
|
384
387
|
## 📝 License
|
|
385
388
|
|
|
386
389
|
Copyright © 2018 [Martin Adámek](https://github.com/b4nan).
|
package/TSMigrationGenerator.js
CHANGED
|
@@ -7,11 +7,11 @@ export class TSMigrationGenerator extends MigrationGenerator {
|
|
|
7
7
|
let ret = `import { Migration } from '@mikro-orm/migrations';\n\n`;
|
|
8
8
|
ret += `export class ${className} extends Migration {\n\n`;
|
|
9
9
|
ret += ` override async up(): Promise<void> {\n`;
|
|
10
|
-
diff.up.forEach(sql => ret += this.createStatement(sql, 4));
|
|
10
|
+
diff.up.forEach(sql => (ret += this.createStatement(sql, 4)));
|
|
11
11
|
ret += ` }\n\n`;
|
|
12
12
|
if (diff.down.length > 0) {
|
|
13
13
|
ret += ` override async down(): Promise<void> {\n`;
|
|
14
|
-
diff.down.forEach(sql => ret += this.createStatement(sql, 4));
|
|
14
|
+
diff.down.forEach(sql => (ret += this.createStatement(sql, 4)));
|
|
15
15
|
ret += ` }\n\n`;
|
|
16
16
|
}
|
|
17
17
|
ret += `}\n`;
|
package/index.d.ts
CHANGED
package/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,62 +1,61 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mikro-orm/migrations",
|
|
3
|
-
"
|
|
4
|
-
"version": "7.0.0-dev.32",
|
|
3
|
+
"version": "7.0.0-dev.320",
|
|
5
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.",
|
|
6
|
-
"exports": {
|
|
7
|
-
"./package.json": "./package.json",
|
|
8
|
-
".": "./index.js"
|
|
9
|
-
},
|
|
10
|
-
"repository": {
|
|
11
|
-
"type": "git",
|
|
12
|
-
"url": "git+ssh://git@github.com/mikro-orm/mikro-orm.git"
|
|
13
|
-
},
|
|
14
5
|
"keywords": [
|
|
15
|
-
"
|
|
6
|
+
"data-mapper",
|
|
7
|
+
"ddd",
|
|
8
|
+
"entity",
|
|
9
|
+
"identity-map",
|
|
10
|
+
"javascript",
|
|
11
|
+
"js",
|
|
12
|
+
"mariadb",
|
|
13
|
+
"mikro-orm",
|
|
16
14
|
"mongo",
|
|
17
15
|
"mongodb",
|
|
18
16
|
"mysql",
|
|
19
|
-
"
|
|
17
|
+
"orm",
|
|
20
18
|
"postgresql",
|
|
21
19
|
"sqlite",
|
|
22
20
|
"sqlite3",
|
|
23
21
|
"ts",
|
|
24
22
|
"typescript",
|
|
25
|
-
"
|
|
26
|
-
"javascript",
|
|
27
|
-
"entity",
|
|
28
|
-
"ddd",
|
|
29
|
-
"mikro-orm",
|
|
30
|
-
"unit-of-work",
|
|
31
|
-
"data-mapper",
|
|
32
|
-
"identity-map"
|
|
23
|
+
"unit-of-work"
|
|
33
24
|
],
|
|
34
|
-
"
|
|
35
|
-
"license": "MIT",
|
|
25
|
+
"homepage": "https://mikro-orm.io",
|
|
36
26
|
"bugs": {
|
|
37
27
|
"url": "https://github.com/mikro-orm/mikro-orm/issues"
|
|
38
28
|
},
|
|
39
|
-
"
|
|
40
|
-
"
|
|
41
|
-
|
|
29
|
+
"license": "MIT",
|
|
30
|
+
"author": "Martin Adámek",
|
|
31
|
+
"repository": {
|
|
32
|
+
"type": "git",
|
|
33
|
+
"url": "git+ssh://git@github.com/mikro-orm/mikro-orm.git"
|
|
34
|
+
},
|
|
35
|
+
"type": "module",
|
|
36
|
+
"exports": {
|
|
37
|
+
"./package.json": "./package.json",
|
|
38
|
+
".": "./index.js"
|
|
39
|
+
},
|
|
40
|
+
"publishConfig": {
|
|
41
|
+
"access": "public"
|
|
42
42
|
},
|
|
43
43
|
"scripts": {
|
|
44
|
-
"build": "yarn
|
|
44
|
+
"build": "yarn compile && yarn copy",
|
|
45
45
|
"clean": "yarn run -T rimraf ./dist",
|
|
46
46
|
"compile": "yarn run -T tsc -p tsconfig.build.json",
|
|
47
47
|
"copy": "node ../../scripts/copy.mjs"
|
|
48
48
|
},
|
|
49
|
-
"publishConfig": {
|
|
50
|
-
"access": "public"
|
|
51
|
-
},
|
|
52
49
|
"dependencies": {
|
|
53
|
-
"@mikro-orm/
|
|
54
|
-
"umzug": "3.8.2"
|
|
50
|
+
"@mikro-orm/sql": "7.0.0-dev.320"
|
|
55
51
|
},
|
|
56
52
|
"devDependencies": {
|
|
57
|
-
"@mikro-orm/core": "^6.
|
|
53
|
+
"@mikro-orm/core": "^6.6.9"
|
|
58
54
|
},
|
|
59
55
|
"peerDependencies": {
|
|
60
|
-
"@mikro-orm/core": "7.0.0-dev.
|
|
56
|
+
"@mikro-orm/core": "7.0.0-dev.320"
|
|
57
|
+
},
|
|
58
|
+
"engines": {
|
|
59
|
+
"node": ">= 22.17.0"
|
|
61
60
|
}
|
|
62
61
|
}
|