MigrationRunner
in package
Class MigrationRunner
Table of Contents
- $cliMessages : array<string|int, mixed>
- used to return messages for CLI.
- $db : BaseConnection
- The main database connection. Used to store migration information in.
- $enabled : bool
- Whether or not migrations are allowed to run.
- $group : string
- The database Group to migrate.
- $groupFilter : string|null
- The database Group filter.
- $groupSkip : bool
- Used to skip current migration.
- $name : string
- The migration name.
- $namespace : string|null
- The Namespace where migrations can be found.
- $path : string
- The full path to locate migration files.
- $regex : string
- The pattern used to locate migration file versions.
- $silent : bool
- If true, will continue instead of throwing exceptions.
- $table : string
- Name of table to store meta information
- $tableChecked : bool
- Tracks whether we have already ensured the table exists or not.
- __construct() : mixed
- Constructor.
- clearCliMessages() : MigrationRunner
- Clears any CLI messages.
- clearHistory() : void
- Truncates the history table.
- ensureTable() : mixed
- Ensures that we have created our migrations table in the database.
- findMigrations() : array<string|int, mixed>
- Retrieves list of available migration scripts
- findNamespaceMigrations() : array<string|int, mixed>
- Retrieves a list of available migration scripts for one namespace
- force() : mixed
- Migrate a single file regardless of order or batches.
- getBatchEnd() : string
- Returns the version number of the last migration for a batch.
- getBatches() : array<string|int, mixed>
- Returns all the batches from the database history in order
- getBatchHistory() : array<string|int, mixed>
- Returns the migration history for a single batch.
- getBatchStart() : string
- Returns the version number of the first migration for a batch.
- getCliMessages() : array<string|int, mixed>
- Retrieves messages formatted for CLI output
- getHistory() : array<string|int, mixed>
- Grabs the full migration history from the database for a group
- getLastBatch() : int
- Returns the value of the last batch in the database.
- getObjectUid() : string
- Uses the non-repeatable portions of a migration or history to create a sortable unique key
- latest() : bool
- Locate and run all new migrations
- regress() : mixed
- Migrate down to a previous batch
- setGroup() : MigrationRunner
- Set database Group.
- setName() : MigrationRunner
- Set migration Name.
- setNamespace() : MigrationRunner
- Set namespace.
- setSilent() : MigrationRunner
- If $silent == true, then will not throw exceptions and will attempt to continue gracefully.
- addHistory() : void
- Add a history to the table.
- getMigrationName() : string
- Extracts the migration class name from a filename
- getMigrationNumber() : string
- Extracts the migration number from a filename
- migrate() : bool
- Handles the actual running of a migration.
- migrationFromFile() : object|false
- Create a migration object from a file path.
- removeHistory() : void
- Removes a single history
Properties
$cliMessages
used to return messages for CLI.
protected
array<string|int, mixed>
$cliMessages
= []
$db
The main database connection. Used to store migration information in.
protected
BaseConnection
$db
$enabled
Whether or not migrations are allowed to run.
protected
bool
$enabled
= false
$group
The database Group to migrate.
protected
string
$group
$groupFilter
The database Group filter.
protected
string|null
$groupFilter
$groupSkip
Used to skip current migration.
protected
bool
$groupSkip
= false
$name
The migration name.
protected
string
$name
$namespace
The Namespace where migrations can be found.
protected
string|null
$namespace
$path
The full path to locate migration files.
protected
string
$path
$regex
The pattern used to locate migration file versions.
protected
string
$regex
= '/^\d{4}[_-]?\d{2}[_-]?\d{2}[_-]?\d{6}_(\w+)$/'
$silent
If true, will continue instead of throwing exceptions.
protected
bool
$silent
= false
$table
Name of table to store meta information
protected
string
$table
$tableChecked
Tracks whether we have already ensured the table exists or not.
protected
bool
$tableChecked
= false
Methods
__construct()
Constructor.
public
__construct(Migrations $config[, ConnectionInterface|array<string|int, mixed>|string|null $db = null ]) : mixed
When passing in $db, you may pass any of the following to connect:
- group name
- existing connection instance
- array of database configuration values
Parameters
- $config : Migrations
- $db : ConnectionInterface|array<string|int, mixed>|string|null = null
Tags
Return values
mixed —clearCliMessages()
Clears any CLI messages.
public
clearCliMessages() : MigrationRunner
Return values
MigrationRunner —clearHistory()
Truncates the history table.
public
clearHistory() : void
Return values
void —ensureTable()
Ensures that we have created our migrations table in the database.
public
ensureTable() : mixed
Return values
mixed —findMigrations()
Retrieves list of available migration scripts
public
findMigrations() : array<string|int, mixed>
Return values
array<string|int, mixed> —List of all located migrations by their UID
findNamespaceMigrations()
Retrieves a list of available migration scripts for one namespace
public
findNamespaceMigrations(string $namespace) : array<string|int, mixed>
Parameters
- $namespace : string
-
The namespace to search for migrations
Return values
array<string|int, mixed> —List of unsorted migrations from the namespace
force()
Migrate a single file regardless of order or batches.
public
force(string $path, string $namespace[, string|null $group = null ]) : mixed
Method "up" or "down" determined by presence in history. NOTE: This is not recommended and provided mostly for testing.
Parameters
- $path : string
-
Namespace of the target migration
- $namespace : string
- $group : string|null = null
Return values
mixed —getBatchEnd()
Returns the version number of the last migration for a batch.
public
getBatchEnd(int $batch) : string
Mostly just for tests.
Parameters
- $batch : int
Return values
string —getBatches()
Returns all the batches from the database history in order
public
getBatches() : array<string|int, mixed>
Return values
array<string|int, mixed> —getBatchHistory()
Returns the migration history for a single batch.
public
getBatchHistory(int $batch[, mixed $order = 'asc' ]) : array<string|int, mixed>
Parameters
- $batch : int
- $order : mixed = 'asc'
Return values
array<string|int, mixed> —getBatchStart()
Returns the version number of the first migration for a batch.
public
getBatchStart(int $batch) : string
Mostly just for tests.
Parameters
- $batch : int
Return values
string —getCliMessages()
Retrieves messages formatted for CLI output
public
getCliMessages() : array<string|int, mixed>
Return values
array<string|int, mixed> —Current migration version
getHistory()
Grabs the full migration history from the database for a group
public
getHistory([string $group = 'default' ]) : array<string|int, mixed>
Parameters
- $group : string = 'default'
Return values
array<string|int, mixed> —getLastBatch()
Returns the value of the last batch in the database.
public
getLastBatch() : int
Return values
int —getObjectUid()
Uses the non-repeatable portions of a migration or history to create a sortable unique key
public
getObjectUid(object $object) : string
Parameters
- $object : object
-
migration or $history
Return values
string —latest()
Locate and run all new migrations
public
latest([string|null $group = null ]) : bool
Parameters
- $group : string|null = null
Tags
Return values
bool —regress()
Migrate down to a previous batch
public
regress(int $targetBatch[, string|null $group = null ]) : mixed
Calls each migration step required to get to the provided batch
Parameters
- $targetBatch : int
-
Target batch number, or negative for a relative batch, 0 for all
- $group : string|null = null
Tags
Return values
mixed —Current batch number on success, FALSE on failure or no migrations are found
setGroup()
Set database Group.
public
setGroup(string $group) : MigrationRunner
Allows other scripts to modify on the fly as needed.
Parameters
- $group : string
Return values
MigrationRunner —setName()
Set migration Name.
public
setName(string $name) : MigrationRunner
Parameters
- $name : string
Return values
MigrationRunner —setNamespace()
Set namespace.
public
setNamespace(string $namespace) : MigrationRunner
Allows other scripts to modify on the fly as needed.
Parameters
- $namespace : string
-
or null for "all"
Return values
MigrationRunner —setSilent()
If $silent == true, then will not throw exceptions and will attempt to continue gracefully.
public
setSilent(bool $silent) : MigrationRunner
Parameters
- $silent : bool
Return values
MigrationRunner —addHistory()
Add a history to the table.
protected
addHistory(object $migration, int $batch) : void
Parameters
- $migration : object
- $batch : int
Return values
void —getMigrationName()
Extracts the migration class name from a filename
protected
getMigrationName(string $migration) : string
Parameters
- $migration : string
Return values
string —text portion of a migration filename
getMigrationNumber()
Extracts the migration number from a filename
protected
getMigrationNumber(string $migration) : string
Parameters
- $migration : string
Return values
string —Numeric portion of a migration filename
migrate()
Handles the actual running of a migration.
protected
migrate(string $direction, object $migration) : bool
Parameters
- $direction : string
-
"up" or "down"
- $migration : object
-
The migration to run
Return values
bool —migrationFromFile()
Create a migration object from a file path.
protected
migrationFromFile(string $path, string $namespace) : object|false
Parameters
- $path : string
-
The namespace of the target migration
- $namespace : string
Return values
object|false —Returns the migration object, or false on failure
removeHistory()
Removes a single history
protected
removeHistory(object $history) : void
Parameters
- $history : object