class Version (View source)

Class which wraps a migration version and allows execution of the individual migration version up or down method.

Constants

STATE_NONE

STATE_PRE

STATE_EXEC

STATE_POST

DIRECTION_UP

DIRECTION_DOWN

Methods

__construct(Configuration $configuration, $version, $class, SchemaDiffProviderInterface $schemaProvider = null)

No description

string
getVersion()

Returns the string version in the format YYYYMMDDHHMMSS

getConfiguration()

Returns the Migrations Configuration object instance

boolean
isMigrated()

Check if this version has been migrated or not.

markMigrated()

No description

markNotMigrated()

No description

addSql(array|string $sql, array $params = [], array $types = [])

Add some SQL queries to this versions migration

boolean
writeSqlFile(string $path, string $direction = self::DIRECTION_UP)

Write a migration SQL file to the given path

getMigration()

No description

array
execute(string $direction, boolean $dryRun = false, boolean $timeAllQueries = false)

Execute this migration version up or down and and return the SQL.

getExecutionState()

No description

integer
getTime()

Returns the time this migration version took to execute

__toString()

No description

Details

__construct(Configuration $configuration, $version, $class, SchemaDiffProviderInterface $schemaProvider = null)

Parameters

Configuration $configuration
$version
$class
SchemaDiffProviderInterface $schemaProvider

string getVersion()

Returns the string version in the format YYYYMMDDHHMMSS

Return Value

string $version

Configuration getConfiguration()

Returns the Migrations Configuration object instance

Return Value

Configuration $configuration

boolean isMigrated()

Check if this version has been migrated or not.

Return Value

boolean

markMigrated()

markNotMigrated()

addSql(array|string $sql, array $params = [], array $types = [])

Add some SQL queries to this versions migration

Parameters

array|string $sql
array $params
array $types

boolean writeSqlFile(string $path, string $direction = self::DIRECTION_UP)

Write a migration SQL file to the given path

Parameters

string $path The path to write the migration SQL file.
string $direction The direction to execute.

Return Value

boolean $written

Exceptions

MigrationException

AbstractMigration getMigration()

Return Value

AbstractMigration

array execute(string $direction, boolean $dryRun = false, boolean $timeAllQueries = false)

Execute this migration version up or down and and return the SQL.

We are only allowing the addSql call and the schema modification to take effect in the up and down call. This is necessary to ensure that the migration is revertable. The schema is passed to the pre and post method only to be able to test the presence of some table, And the connection that can get used trough it allow for the test of the presence of records.

Parameters

string $direction The direction to execute the migration.
boolean $dryRun Whether to not actually execute the migration SQL and just do a dry run.
boolean $timeAllQueries Measuring or not the execution time of each SQL query.

Return Value

array $sql

Exceptions

Exception when migration fails

getExecutionState()

integer getTime()

Returns the time this migration version took to execute

Return Value

integer $time The time this migration version took to execute

__toString()