Options
All
  • Public
  • Public/Protected
  • All
Menu

Class MySQLMigrator

Database migrator for MySQL.

Hierarchy

Index

Constructors

constructor

Properties

Protected dataContext

dataContext: DataContext

A connected DataContext instance use for running queries.

Protected logger

logger: Logger

A Logger instance for logging info about the migration process.

Protected migDir

migDir: string

The directory to use for migration scripts, which defaults to "migrations." If the path is not absolute, it's considered relative to the current working directory.

Protected pathHelper

pathHelper: PathHelper

A PathHelper instance for creating the migration directory.

Methods

create

  • create(migrationName: string, migDir?: string): Promise<void>
  • Create a migration.

    Parameters

    • migrationName: string

      The name of the migration file.

    • Optional migDir: string

    Returns Promise<void>

createMigrationsDir

  • createMigrationsDir(): Promise<void>

createMigrationsTable

  • createMigrationsTable(): Promise<void>

down

  • down(): Promise<void>

listMigrationFiles

  • listMigrationFiles(order: number): Promise<string[]>
  • List all the migration files in the migrations directory, ordered by name, descending (newest first).

    Parameters

    • order: number

      The order of the returned files. 1 for ascending; -1 for descending.

    Returns Promise<string[]>

loadMigrationScript

  • loadMigrationScript(migration: string): object
  • Helper to load a migration script. It's just a wrapper around require(), but is helpful for mocking.

    Parameters

    • migration: string

      The full path to the migration script.

    Returns object

retrieve

retrieveLatest

run

  • run(migration: string): Promise<any>
  • Run a script against the database.

    Parameters

    • migration: string

      The migration script, which will be resolved using [[PathHelper#getAbsolutePath]].

    Returns Promise<any>

runMigration

  • runMigration(migration: string, direction: string): Promise<any>
  • Run a migration in a given direction (up or down).

    Parameters

    • migration: string

      The migration file without the path.

    • direction: string

      The direction, up or down.

    Returns Promise<any>

    The return value from the migration method is returned.

up

  • up(): Promise<void>

Generated using TypeDoc