class YamlConfiguration extends AbstractFileConfiguration (View source)

Load migration configuration information from a YAML configuration file.

Constants

VERSIONS_ORGANIZATION_BY_YEAR

Configure versions to be organized by year.

VERSIONS_ORGANIZATION_BY_YEAR_AND_MONTH

Configure versions to be organized by year and month.

VERSION_FORMAT

The date format for new version numbers

Methods

__construct(Connection $connection, OutputWriter $outputWriter = null, MigrationFinderInterface $finder = null, QueryWriter $queryWriter = null)

Construct a migration configuration object.

bool
areMigrationsOrganizedByYear()

No description

validate()

Validation that this instance has all the required properties configured

setName(string $name)

Set the name of this set of migrations

string
getName()

Returns the name of this set of migrations

setOutputWriter(OutputWriter $outputWriter)

Sets the output writer.

getOutputWriter()

Returns the OutputWriter instance

string
formatVersion(string $version) deprecated

Returns a timestamp version as a formatted date

string
getDateTime(string $version)

Returns the datetime of a migration

Connection
getConnection()

Returns the Connection instance

setMigrationsTableName(string $tableName)

Set the migration table name

string
getMigrationsTableName()

Returns the migration table name

setMigrationsColumnName(string $columnName)

Set the migration column name

string
getMigrationsColumnName()

Returns the migration column name

string
getQuotedMigrationsColumnName()

Returns the quoted migration column name

setMigrationsDirectory(string $migrationsDirectory)

Set the new migrations directory where new migration classes are generated

string
getMigrationsDirectory()

Returns the new migrations directory where new migration classes are generated

setMigrationsNamespace(string $migrationsNamespace)

Set the migrations namespace

string
getMigrationsNamespace()

Returns the migrations namespace

string
getCustomTemplate()

Returns the custom template path

setCustomTemplate(string|null $customTemplate)

Set the custom template path

setMigrationsFinder(MigrationFinderInterface $finder)

Set the implementation of the migration finder.

registerMigrationsFromDirectory(string $path)

Register migrations from a given directory. Recursively finds all files with the pattern VersionYYYYMMDDHHMMSS.php as the filename and registers them as migrations.

registerMigration(string $version, string $class)

Register a single migration version to be executed by a AbstractMigration class.

registerMigrations(array $migrations)

Register an array of migrations. Each key of the array is the version and the value is the migration class name.

getMigrations()

Get the array of registered migration versions.

getVersion(string $version)

Returns the Version instance for a given version in the format YYYYMMDDHHMMSS.

boolean
hasVersion(string $version)

Check if a version exists.

boolean
hasVersionMigrated(Version $version)

Check if a version has been migrated or not yet

getMigratedVersions()

Returns all migrated versions from the versions table, in an array.

array
getAvailableVersions()

Returns an array of available migration version numbers.

string
getCurrentVersion()

Returns the current migrated version from the versions table.

string|null
getPrevVersion()

Returns the version prior to the current version.

string|null
getNextVersion()

Returns the version following the current version.

null|string
getRelativeVersion(string $version, string $delta)

Returns the version with the specified offset to the specified version.

null|string
getDeltaVersion(string $delta)

Returns the version with the specified to the current version.

null|string
resolveVersionAlias(string $alias)

Returns the version number from an alias.

integer
getNumberOfExecutedMigrations()

Returns the total number of executed migration versions

integer
getNumberOfAvailableMigrations()

Returns the total number of available migration versions

string
getLatestVersion()

Returns the latest available migration version.

boolean
createMigrationTable()

Create the migration table to track migrations with.

getMigrationsToExecute(string $direction, string $to)

Returns the array of migrations to executed based on the given direction and target version number.

dispatchEvent(string $eventName, EventArgs $args = null)

Use the connection's event manager to emit an event.

array
findMigrations(string $path)

Find all the migrations in a given directory.

setMigrationsAreOrganizedByYear(bool $migrationsAreOrganizedByYear = true)

No description

setMigrationsAreOrganizedByYearAndMonth(bool $migrationsAreOrganizedByYearAndMonth = true)

No description

string
generateVersionNumber(DateTimeInterface $now = null)

Generate a new migration version. A version is (usually) a datetime string.

bool
connect()

Explicitely opens the database connection. This is done to play nice with DBAL's MasterSlaveConnection. Which, in some cases, connects to a follower when fetching the executed migrations. If a follower is lagging significantly behind that means the migrations system may see unexecuted migrations that were actually executed earlier.

getQueryWriter()

No description

setIsDryRun(bool $isDryRun)

No description

setConfiguration(array $config)

No description

load(string $file)

Load the information from the passed configuration file

getDirectoryRelativeToFile($file, $input)

No description

getFile()

No description

doLoad(string $file)

No description

Details

__construct(Connection $connection, OutputWriter $outputWriter = null, MigrationFinderInterface $finder = null, QueryWriter $queryWriter = null)

Construct a migration configuration object.

Parameters

Connection $connection A Connection instance
OutputWriter $outputWriter A OutputWriter instance
MigrationFinderInterface $finder Migration files finder
QueryWriter $queryWriter

bool areMigrationsOrganizedByYear()

Return Value

bool

bool areMigrationsOrganizedByYearAndMonth()

Return Value

bool

validate()

Validation that this instance has all the required properties configured

Exceptions

MigrationException

setName(string $name)

Set the name of this set of migrations

Parameters

string $name The name of this set of migrations

string getName()

Returns the name of this set of migrations

Return Value

string $name The name of this set of migrations

setOutputWriter(OutputWriter $outputWriter)

Sets the output writer.

Parameters

OutputWriter $outputWriter

OutputWriter getOutputWriter()

Returns the OutputWriter instance

Return Value

OutputWriter $outputWriter The OutputWriter instance

string formatVersion(string $version) deprecated

deprecated

Returns a timestamp version as a formatted date

Parameters

string $version

Return Value

string The formatted version

string getDateTime(string $version)

Returns the datetime of a migration

Parameters

string $version

Return Value

string

Connection getConnection()

Returns the Connection instance

Return Value

Connection $connection The Connection instance

setMigrationsTableName(string $tableName)

Set the migration table name

Parameters

string $tableName The migration table name

string getMigrationsTableName()

Returns the migration table name

Return Value

string $migrationsTableName The migration table name

setMigrationsColumnName(string $columnName)

Set the migration column name

Parameters

string $columnName The migration column name

string getMigrationsColumnName()

Returns the migration column name

Return Value

string $migrationsColumnName The migration column name

string getQuotedMigrationsColumnName()

Returns the quoted migration column name

Return Value

string The quouted migration column name

setMigrationsDirectory(string $migrationsDirectory)

Set the new migrations directory where new migration classes are generated

Parameters

string $migrationsDirectory The new migrations directory

string getMigrationsDirectory()

Returns the new migrations directory where new migration classes are generated

Return Value

string $migrationsDirectory The new migrations directory

setMigrationsNamespace(string $migrationsNamespace)

Set the migrations namespace

Parameters

string $migrationsNamespace The migrations namespace

string getMigrationsNamespace()

Returns the migrations namespace

Return Value

string $migrationsNamespace The migrations namespace

string getCustomTemplate()

Returns the custom template path

Return Value

string $customTemplate The custom template path

setCustomTemplate(string|null $customTemplate)

Set the custom template path

Parameters

string|null $customTemplate The custom template path

setMigrationsFinder(MigrationFinderInterface $finder)

Set the implementation of the migration finder.

Parameters

MigrationFinderInterface $finder The new migration finder

Exceptions

MigrationException

Version[] registerMigrationsFromDirectory(string $path)

Register migrations from a given directory. Recursively finds all files with the pattern VersionYYYYMMDDHHMMSS.php as the filename and registers them as migrations.

Parameters

string $path The root directory to where some migration classes live.

Return Value

Version[] The array of migrations registered.

Version registerMigration(string $version, string $class)

Register a single migration version to be executed by a AbstractMigration class.

Parameters

string $version The version of the migration in the format YYYYMMDDHHMMSS.
string $class The migration class to execute for the version.

Return Value

Version

Exceptions

MigrationException

Version[] registerMigrations(array $migrations)

Register an array of migrations. Each key of the array is the version and the value is the migration class name.

Parameters

array $migrations

Return Value

Version[]

Version[] getMigrations()

Get the array of registered migration versions.

Return Value

Version[] $migrations

Version getVersion(string $version)

Returns the Version instance for a given version in the format YYYYMMDDHHMMSS.

Parameters

string $version The version string in the format YYYYMMDDHHMMSS.

Return Value

Version

Exceptions

MigrationException Throws exception if migration version does not exist.

boolean hasVersion(string $version)

Check if a version exists.

Parameters

string $version

Return Value

boolean

boolean hasVersionMigrated(Version $version)

Check if a version has been migrated or not yet

Parameters

Version $version

Return Value

boolean

Version[] getMigratedVersions()

Returns all migrated versions from the versions table, in an array.

Return Value

Version[]

array getAvailableVersions()

Returns an array of available migration version numbers.

Return Value

array

string getCurrentVersion()

Returns the current migrated version from the versions table.

Return Value

string

string|null getPrevVersion()

Returns the version prior to the current version.

Return Value

string|null A version string, or null if the current version is the first.

string|null getNextVersion()

Returns the version following the current version.

Return Value

string|null A version string, or null if the current version is the latest.

null|string getRelativeVersion(string $version, string $delta)

Returns the version with the specified offset to the specified version.

Parameters

string $version
string $delta

Return Value

null|string A version string, or null if the specified version is unknown or the specified delta is not within the list of available versions.

null|string getDeltaVersion(string $delta)

Returns the version with the specified to the current version.

Parameters

string $delta

Return Value

null|string A version string, or null if the specified delta is not within the list of available versions.

null|string resolveVersionAlias(string $alias)

Returns the version number from an alias.

Supported aliases are: - first: The very first version before any migrations have been run. - current: The current version. - prev: The version prior to the current version. - next: The version following the current version. - latest: The latest available version.

If an existing version number is specified, it is returned verbatimly.

Parameters

string $alias

Return Value

null|string A version number, or null if the specified alias does not map to an existing version, e.g. if "next" is passed but the current version is already the latest.

integer getNumberOfExecutedMigrations()

Returns the total number of executed migration versions

Return Value

integer

integer getNumberOfAvailableMigrations()

Returns the total number of available migration versions

Return Value

integer

string getLatestVersion()

Returns the latest available migration version.

Return Value

string The version string in the format YYYYMMDDHHMMSS.

boolean createMigrationTable()

Create the migration table to track migrations with.

Return Value

boolean Whether or not the table was created.

Version[] getMigrationsToExecute(string $direction, string $to)

Returns the array of migrations to executed based on the given direction and target version number.

Parameters

string $direction The direction we are migrating.
string $to The version to migrate to.

Return Value

Version[] $migrations The array of migrations we can execute.

dispatchEvent(string $eventName, EventArgs $args = null)

Use the connection's event manager to emit an event.

Parameters

string $eventName The event to emit.
EventArgs $args The event args instance to emit.

protected array findMigrations(string $path)

Find all the migrations in a given directory.

Parameters

string $path the directory to search.

Return Value

array

setMigrationsAreOrganizedByYear(bool $migrationsAreOrganizedByYear = true)

Parameters

bool $migrationsAreOrganizedByYear

Exceptions

MigrationException

setMigrationsAreOrganizedByYearAndMonth(bool $migrationsAreOrganizedByYearAndMonth = true)

Parameters

bool $migrationsAreOrganizedByYearAndMonth

Exceptions

MigrationException

string generateVersionNumber(DateTimeInterface $now = null)

Generate a new migration version. A version is (usually) a datetime string.

Parameters

DateTimeInterface $now Defaults to the current time in UTC

Return Value

string The newly generated version

protected bool connect()

Explicitely opens the database connection. This is done to play nice with DBAL's MasterSlaveConnection. Which, in some cases, connects to a follower when fetching the executed migrations. If a follower is lagging significantly behind that means the migrations system may see unexecuted migrations that were actually executed earlier.

Return Value

bool The same value returned from the connect method

getQueryWriter()

setIsDryRun(bool $isDryRun)

Parameters

bool $isDryRun

protected setConfiguration(array $config)

Parameters

array $config

load(string $file)

Load the information from the passed configuration file

Parameters

string $file The path to the configuration file

Exceptions

MigrationException Throws exception if configuration file was already loaded

protected getDirectoryRelativeToFile($file, $input)

Parameters

$file
$input

protected doLoad(string $file)

Parameters

string $file The path to a configuration file.