@mikro-orm/migrations
Advanced tools
@@ -12,3 +12,3 @@ import { MigrationGenerator } from './MigrationGenerator.js'; | ||
| ret += ` async up() {\n`; | ||
| diff.up.forEach(sql => ret += this.createStatement(sql, 4)); | ||
| diff.up.forEach(sql => (ret += this.createStatement(sql, 4))); | ||
| ret += ` }\n\n`; | ||
@@ -18,3 +18,3 @@ /* v8 ignore next */ | ||
| ret += ` async down() {\n`; | ||
| diff.down.forEach(sql => ret += this.createStatement(sql, 4)); | ||
| diff.down.forEach(sql => (ret += this.createStatement(sql, 4))); | ||
| ret += ` }\n\n`; | ||
@@ -21,0 +21,0 @@ } |
@@ -19,3 +19,3 @@ export class MigrationGenerator { | ||
| fs.ensureDir(path); | ||
| const timestamp = new Date().toISOString().replace(/[-T:]|\.\d{3}z$/ig, ''); | ||
| const timestamp = new Date().toISOString().replace(/[-T:]|\.\d{3}z$/gi, ''); | ||
| const className = this.namingStrategy.classToMigrationName(timestamp, name); | ||
@@ -22,0 +22,0 @@ const fileName = `${this.options.fileName(timestamp, name)}.${this.options.emit}`; |
@@ -34,3 +34,4 @@ import { defineEntity, p } from '@mikro-orm/core'; | ||
| const { entity, schemaName } = this.getTableName(); | ||
| const res = await this.driver.createQueryBuilder(entity, this.masterTransaction) | ||
| const res = await this.driver | ||
| .createQueryBuilder(entity, this.masterTransaction) | ||
| .withSchema(schemaName) | ||
@@ -37,0 +38,0 @@ .orderBy({ id: 'asc' }) |
+3
-2
@@ -1,2 +0,2 @@ | ||
| import { type IMigrationGenerator, type IMigrationRunner, type IMigratorStorage, type MikroORM } from '@mikro-orm/core'; | ||
| import { type IMigrationGenerator, type IMigrationRunner, type IMigratorStorage, type MigrateOptions, type MigrationInfo, type MikroORM } from '@mikro-orm/core'; | ||
| import { AbstractMigrator } from '@mikro-orm/core/migrations'; | ||
@@ -25,2 +25,3 @@ import { type AbstractSqlDriver, DatabaseSchema, type EntityManager } from '@mikro-orm/sql'; | ||
| createInitial(path?: string, name?: string, blank?: boolean): Promise<MigrationResult>; | ||
| protected runMigrations(method: 'up' | 'down', options?: string | string[] | MigrateOptions): Promise<MigrationInfo[]>; | ||
| getStorage(): MigrationStorage; | ||
@@ -37,4 +38,4 @@ /** | ||
| protected getSchemaFromSnapshot(): Promise<DatabaseSchema | undefined>; | ||
| protected storeCurrentSchema(): Promise<void>; | ||
| protected storeCurrentSchema(schema?: DatabaseSchema): Promise<void>; | ||
| private getSchemaDiff; | ||
| } |
+16
-3
@@ -37,3 +37,3 @@ import { t, Type, UnknownType, } from '@mikro-orm/core'; | ||
| const absoluteSnapshotPath = fs.absolutePath(snapshotPath, this.config.get('baseDir')); | ||
| const dbName = this.config.get('dbName').replace(/\\/g, '/').split('/').pop(); | ||
| const dbName = this.config.get('dbName').replace(/\\/g, '/').split('/').pop().replace(/:/g, ''); | ||
| const snapshotName = this.options.snapshotName ?? `.snapshot-${dbName}`; | ||
@@ -99,2 +99,15 @@ this.snapshotPath = fs.normalizePath(absoluteSnapshotPath, `${snapshotName}.json`); | ||
| } | ||
| async runMigrations(method, options) { | ||
| const result = await super.runMigrations(method, options); | ||
| if (result.length > 0 && this.options.snapshot) { | ||
| const schema = await DatabaseSchema.create(this.em.getConnection(), this.em.getPlatform(), this.config); | ||
| try { | ||
| await this.storeCurrentSchema(schema); | ||
| } | ||
| catch { | ||
| // Silently ignore for read-only filesystems (production). | ||
| } | ||
| } | ||
| return result; | ||
| } | ||
| getStorage() { | ||
@@ -168,3 +181,3 @@ return this.storage; | ||
| } | ||
| async storeCurrentSchema() { | ||
| async storeCurrentSchema(schema) { | ||
| if (!this.options.snapshot) { | ||
@@ -174,3 +187,3 @@ return; | ||
| const snapshotPath = await this.getSnapshotPath(); | ||
| const schema = this.schemaGenerator.getTargetSchema(); | ||
| schema ??= this.schemaGenerator.getTargetSchema(); | ||
| const { fs } = await import('@mikro-orm/core/fs-utils'); | ||
@@ -177,0 +190,0 @@ await fs.writeFile(snapshotPath, JSON.stringify(schema, null, 2)); |
+31
-31
| { | ||
| "name": "@mikro-orm/migrations", | ||
| "type": "module", | ||
| "version": "7.0.0-rc.2", | ||
| "version": "7.0.0-rc.3", | ||
| "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.", | ||
| "exports": { | ||
| "./package.json": "./package.json", | ||
| ".": "./index.js" | ||
| }, | ||
| "repository": { | ||
| "type": "git", | ||
| "url": "git+ssh://git@github.com/mikro-orm/mikro-orm.git" | ||
| }, | ||
| "keywords": [ | ||
| "orm", | ||
| "data-mapper", | ||
| "ddd", | ||
| "entity", | ||
| "identity-map", | ||
| "javascript", | ||
| "js", | ||
| "mariadb", | ||
| "mikro-orm", | ||
| "mongo", | ||
| "mongodb", | ||
| "mysql", | ||
| "mariadb", | ||
| "orm", | ||
| "postgresql", | ||
@@ -25,20 +23,22 @@ "sqlite", | ||
| "typescript", | ||
| "js", | ||
| "javascript", | ||
| "entity", | ||
| "ddd", | ||
| "mikro-orm", | ||
| "unit-of-work", | ||
| "data-mapper", | ||
| "identity-map" | ||
| "unit-of-work" | ||
| ], | ||
| "author": "Martin Adámek", | ||
| "license": "MIT", | ||
| "homepage": "https://mikro-orm.io", | ||
| "bugs": { | ||
| "url": "https://github.com/mikro-orm/mikro-orm/issues" | ||
| }, | ||
| "homepage": "https://mikro-orm.io", | ||
| "engines": { | ||
| "node": ">= 22.17.0" | ||
| "license": "MIT", | ||
| "author": "Martin Adámek", | ||
| "repository": { | ||
| "type": "git", | ||
| "url": "git+ssh://git@github.com/mikro-orm/mikro-orm.git" | ||
| }, | ||
| "type": "module", | ||
| "exports": { | ||
| "./package.json": "./package.json", | ||
| ".": "./index.js" | ||
| }, | ||
| "publishConfig": { | ||
| "access": "public" | ||
| }, | ||
| "scripts": { | ||
@@ -50,14 +50,14 @@ "build": "yarn compile && yarn copy", | ||
| }, | ||
| "publishConfig": { | ||
| "access": "public" | ||
| }, | ||
| "dependencies": { | ||
| "@mikro-orm/sql": "7.0.0-rc.2" | ||
| "@mikro-orm/sql": "7.0.0-rc.3" | ||
| }, | ||
| "devDependencies": { | ||
| "@mikro-orm/core": "^6.6.4" | ||
| "@mikro-orm/core": "^6.6.8" | ||
| }, | ||
| "peerDependencies": { | ||
| "@mikro-orm/core": "7.0.0-rc.2" | ||
| "@mikro-orm/core": "7.0.0-rc.3" | ||
| }, | ||
| "engines": { | ||
| "node": ">= 22.17.0" | ||
| } | ||
| } |
@@ -10,7 +10,7 @@ import { MigrationGenerator } from './MigrationGenerator.js'; | ||
| ret += ` override async up(): Promise<void> {\n`; | ||
| diff.up.forEach(sql => ret += this.createStatement(sql, 4)); | ||
| diff.up.forEach(sql => (ret += this.createStatement(sql, 4))); | ||
| ret += ` }\n\n`; | ||
| if (diff.down.length > 0) { | ||
| ret += ` override async down(): Promise<void> {\n`; | ||
| diff.down.forEach(sql => ret += this.createStatement(sql, 4)); | ||
| diff.down.forEach(sql => (ret += this.createStatement(sql, 4))); | ||
| ret += ` }\n\n`; | ||
@@ -17,0 +17,0 @@ } |
Sorry, the diff of this file is too big to display
182409
0.66%723
2.12%+ Added
+ Added
- Removed
- Removed
Updated