Version: 4.3

Class: Migrator

Hierarchy

  • Migrator

Constructors

constructor

+ new Migrator(em: EntityManager): Migrator

Defined in packages/migrations/src/Migrator.ts:20

Parameters:

NameType
emEntityManager

Returns: Migrator

Properties

config

Private Readonly config: Configuration<IDatabaseDriver<Connection>> = this.em.config

Defined in packages/migrations/src/Migrator.ts:16


driver

Private Readonly driver: AbstractSqlDriver<AbstractSqlConnection> = this.em.getDriver()

Defined in packages/migrations/src/Migrator.ts:14


em

Private Readonly em: EntityManager

Defined in packages/migrations/src/Migrator.ts:22


generator

Private Readonly generator: MigrationGenerator = new MigrationGenerator(this.driver, this.config.getNamingStrategy(), this.options)

Defined in packages/migrations/src/Migrator.ts:19


options

Private Readonly options: MigrationsOptions = this.config.get('migrations')

Defined in packages/migrations/src/Migrator.ts:17


runner

Private Readonly runner: MigrationRunner = new MigrationRunner(this.driver, this.options, this.config)

Defined in packages/migrations/src/Migrator.ts:18


schemaGenerator

Private Readonly schemaGenerator: SchemaGenerator = new SchemaGenerator(this.em)

Defined in packages/migrations/src/Migrator.ts:15


storage

Private Readonly storage: MigrationStorage = new MigrationStorage(this.driver, this.options)

Defined in packages/migrations/src/Migrator.ts:20


umzug

Private Readonly umzug: Umzug

Defined in packages/migrations/src/Migrator.ts:13

Methods

createInitialMigration

createInitialMigration(path?: string): Promise<MigrationResult>

Defined in packages/migrations/src/Migrator.ts:62

Parameters:

NameType
path?string

Returns: Promise<MigrationResult>


createMigration

createMigration(path?: string, blank?: boolean, initial?: boolean): Promise<MigrationResult>

Defined in packages/migrations/src/Migrator.ts:41

Parameters:

NameTypeDefault value
path?string-
blankbooleanfalse
initialbooleanfalse

Returns: Promise<MigrationResult>


down

down(options?: string | string[] | MigrateOptions): Promise<UmzugMigration[]>

Defined in packages/migrations/src/Migrator.ts:139

Parameters:

NameType
options?string | string[] | MigrateOptions

Returns: Promise<UmzugMigration[]>


ensureMigrationsDirExists

PrivateensureMigrationsDirExists(): Promise<void>

Defined in packages/migrations/src/Migrator.ts:239

Returns: Promise<void>


getExecutedMigrations

getExecutedMigrations(): Promise<MigrationRow[]>

Defined in packages/migrations/src/Migrator.ts:123

Returns: Promise<MigrationRow[]>


getPendingMigrations

getPendingMigrations(): Promise<UmzugMigration[]>

Defined in packages/migrations/src/Migrator.ts:129

Returns: Promise<UmzugMigration[]>


getSchemaDiff

PrivategetSchemaDiff(blank: boolean, initial: boolean): Promise<string[]>

Defined in packages/migrations/src/Migrator.ts:165

Parameters:

NameType
blankboolean
initialboolean

Returns: Promise<string[]>


getStorage

getStorage(): MigrationStorage

Defined in packages/migrations/src/Migrator.ts:143

Returns: MigrationStorage


initialize

Protectedinitialize(MigrationClass: Constructor<Migration>, name?: string): object

Defined in packages/migrations/src/Migrator.ts:155

Parameters:

NameType
MigrationClassConstructor<Migration>
name?string

Returns: object

NameType
namestring
down() => Promise<void>
up() => Promise<void>

prefix

Privateprefix<T>(options?: T): T

Defined in packages/migrations/src/Migrator.ts:189

Type parameters:

NameType
Tstring | string[] | { from?: string ; migrations?: string[] ; to?: string ; transaction?: Transaction }

Parameters:

NameType
options?T

Returns: T


resolve

Protectedresolve(file: string): object

Defined in packages/migrations/src/Migrator.ts:147

Parameters:

NameType
filestring

Returns: object

NameType
namestring
down() => Promise<void>
up() => Promise<void>

runInTransaction

PrivaterunInTransaction(trx: Transaction, method: "up" | "down", options: string | string[] | undefined | MigrateOptions): Promise<Migration[]>

Defined in packages/migrations/src/Migrator.ts:229

Parameters:

NameType
trxTransaction
method"up" | "down"
optionsstring | string[] | undefined | MigrateOptions

Returns: Promise<Migration[]>


runMigrations

PrivaterunMigrations(method: "up" | "down", options?: string | string[] | MigrateOptions): Promise<Migration[]>

Defined in packages/migrations/src/Migrator.ts:214

Parameters:

NameType
method"up" | "down"
options?string | string[] | MigrateOptions

Returns: Promise<Migration[]>


up

up(options?: string | string[] | MigrateOptions): Promise<UmzugMigration[]>

Defined in packages/migrations/src/Migrator.ts:135

Parameters:

NameType
options?string | string[] | MigrateOptions

Returns: Promise<UmzugMigration[]>


validateInitialMigration

PrivatevalidateInitialMigration(): Promise<boolean>

Defined in packages/migrations/src/Migrator.ts:87

Initial migration can be created only if:

  1. no previous migrations were generated or executed
  2. existing schema do not contain any of the tables defined by metadata

If existing schema contains all of the tables already, we return true, based on that we mark the migration as already executed. If only some of the tables are present, exception is thrown.

Returns: Promise<boolean>

Last updated on by Martin Adámek