class Migration (View source)

Class for running migrations to the current version or a manually specified version.

Methods

__construct(Configuration $configuration)

Construct a Migration instance

array
getSql(string $to = null)

Get the array of versions and SQL queries that would be executed for each version but do not execute anything.

boolean
writeSqlFile(string $path, string $to = null)

Write a migration SQL file to the given path

setNoMigrationException(boolean $noMigrationException = false)

No description

array
migrate(string $to = null, boolean $dryRun = false, boolean $timeAllQueries = false, callable $confirm = null)

Run a migration to the current version or the given target version.

Details

__construct(Configuration $configuration)

Construct a Migration instance

Parameters

Configuration $configuration A migration Configuration instance

array getSql(string $to = null)

Get the array of versions and SQL queries that would be executed for each version but do not execute anything.

Parameters

string $to The version to migrate to.

Return Value

array $sql The array of SQL queries.

boolean writeSqlFile(string $path, string $to = null)

Write a migration SQL file to the given path

Parameters

string $path The path to write the migration SQL file.
string $to The version to migrate to.

Return Value

boolean $written

setNoMigrationException(boolean $noMigrationException = false)

Parameters

boolean $noMigrationException Throw an exception or not if no migration is found. Mostly for Continuous Integration.

array migrate(string $to = null, boolean $dryRun = false, boolean $timeAllQueries = false, callable $confirm = null)

Run a migration to the current version or the given target version.

Parameters

string $to The version to migrate to.
boolean $dryRun Whether or not to make this a dry run and not execute anything.
boolean $timeAllQueries Measuring or not the execution time of each SQL query.
callable $confirm A callback to confirm whether the migrations should be executed.

Return Value

array An array of migration sql statements. This will be empty if the the $confirm callback declines to execute the migration

Exceptions

MigrationException