Feat: Improvements to the migrations CLI and workflow (#8060)

This commit is contained in:
Harminder Virk
2024-07-11 16:52:34 +05:30
committed by GitHub
parent bb0303cd6a
commit 45c573b03a
10 changed files with 257 additions and 144 deletions
+12 -5
View File
@@ -5,6 +5,7 @@ import {
UmzugMigration,
} from "@mikro-orm/migrations"
import { MikroORM, MikroORMOptions } from "@mikro-orm/core"
import { PostgreSqlDriver } from "@mikro-orm/postgresql"
/**
* Events emitted by the migrations class
@@ -20,11 +21,13 @@ export type MigrationsEvents = {
* Exposes the API to programmatically manage Mikro ORM migrations
*/
export class Migrations extends EventEmitter<MigrationsEvents> {
#config: Partial<MikroORMOptions>
#configOrConnection: Partial<MikroORMOptions> | MikroORM<PostgreSqlDriver>
constructor(config: Partial<MikroORMOptions>) {
constructor(
configOrConnection: Partial<MikroORMOptions> | MikroORM<PostgreSqlDriver>
) {
super()
this.#config = config
this.#configOrConnection = configOrConnection
}
/**
@@ -32,10 +35,14 @@ export class Migrations extends EventEmitter<MigrationsEvents> {
* one
*/
async #getConnection() {
if ("connect" in this.#configOrConnection) {
return this.#configOrConnection as MikroORM<PostgreSqlDriver>
}
return await MikroORM.init({
...this.#config,
...this.#configOrConnection,
migrations: {
...this.#config.migrations,
...this.#configOrConnection.migrations,
silent: true,
},
})