Skip to main content
Module

x/typeorm/src/index.ts>MigrationExecutor

Forked from https://github.com/typeorm/typeorm
Latest
class MigrationExecutor
import { MigrationExecutor } from "https://deno.land/x/typeorm@v0.2.23-rc10/src/index.ts";

Executes migrations: runs pending and reverts previously executed migrations.

Constructors

new
MigrationExecutor(connection: Connection, queryRunner?: QueryRunner)

Properties

private
readonly
migrationsTable: string
private
readonly
migrationsTableName: string
transaction: "all" | "none" | "each"

Indicates how migrations should be run in transactions. all: all migrations are run in a single transaction none: all migrations are run without a transaction each: each migration is run in a separate transaction

Methods

protected
checkForDuplicateMigrations(migrations: Migration[])
protected
createMigrationsTableIfNotExist(queryRunner: QueryRunner): Promise<void>

Creates table "migrations" that will store information about executed migrations.

protected
deleteExecutedMigration(queryRunner: QueryRunner, migration: Migration): Promise<void>

Delete previously executed migration's data from the migrations table.

protected
getLatestExecutedMigration(sortedMigrations: Migration[]): Migration | undefined

Finds the latest migration in the given array of migrations. PRE: Migration array must be sorted by descending id.

protected
getLatestTimestampMigration(migrations: Migration[]): Migration | undefined

Finds the latest migration (sorts by timestamp) in the given array of migrations.

protected
getMigrations(): Migration[]

Gets all migrations that setup for this connection.

protected
insertExecutedMigration(queryRunner: QueryRunner, migration: Migration): Promise<void>

Inserts new executed migration's data into migrations table.

protected
loadExecutedMigrations(queryRunner: QueryRunner): Promise<Migration[]>

Loads all migrations that were executed and saved into the database (sorts by id).

protected
withQueryRunner<T extends any>(callback: (queryRunner: QueryRunner) => T)
deleteMigration(migration: Migration): Promise<void>

Deletes an executed migration.

executeMigration(migration: Migration): Promise<Migration>

Tries to execute a single migration given.

executePendingMigrations(): Promise<Migration[]>

Executes all pending migrations. Pending migrations are migrations that are not yet executed, thus not saved in the database.

getAllMigrations(): Promise<Migration[]>

Returns an array of all migrations.

getExecutedMigrations(): Promise<Migration[]>

Returns an array of all executed migrations.

getPendingMigrations(): Promise<Migration[]>

Returns an array of all pending migrations.

insertMigration(migration: Migration): Promise<void>

Inserts an executed migration.

showMigrations(): Promise<boolean>

Lists all migrations and whether they have been executed or not returns true if there are unapplied migrations

undoLastMigration(): Promise<void>

Reverts last migration that were run.