CodeIgniter v4.5 API

MigrationRunner
in package

Class MigrationRunner

Table of Contents

Properties

$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.

Methods

__construct()  : mixed
The migration can manage multiple databases. So it should always use the default DB group so that it creates the `migrations` table in the default DB group. Therefore, passing $db is for testing purposes only.
clearCliMessages()  : MigrationRunner
Clears any CLI messages.
clearHistory()  : mixed
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()  : bool
Migrate down to a previous batch
setGroup()  : MigrationRunner
Allows other scripts to modify on the fly as needed.
setName()  : MigrationRunner
setNamespace()  : MigrationRunner
Allows other scripts to modify on the fly as needed.
setSilent()  : MigrationRunner
If $silent == true, then will not throw exceptions and will attempt to continue gracefully.
addHistory()  : mixed
Add a history to the table.
getMigrationName()  : string
Extracts the migration name from a filename
getMigrationNumber()  : string
Extracts the migration number from a filename
migrate()  : bool
Handles the actual running of a migration.
migrationFromFile()  : false|object
Create a migration object from a file path.
removeHistory()  : mixed
Removes a single history

Properties

$cliMessages

used to return messages for CLI.

protected array<string|int, mixed> $cliMessages = []

$enabled

Whether or not migrations are allowed to run.

protected bool $enabled = false

$groupFilter

The database Group filter.

protected string|null $groupFilter

$groupSkip

Used to skip current migration.

protected bool $groupSkip = false

$namespace

The Namespace where migrations can be found.

protected string|null $namespace

null is all namespaces.

$path

The full path to locate migration files.

protected string $path

$regex

The pattern used to locate migration file versions.

protected string $regex = '/\A(\d{4}[_-]?\d{2}[_-]?\d{2}[_-]?\d{6})_(\w+)\z/'

$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()

The migration can manage multiple databases. So it should always use the default DB group so that it creates the `migrations` table in the default DB group. Therefore, passing $db is for testing purposes only.

public __construct(Migrations $config[, array<string|int, mixed>|ConnectionInterface|string|null $db = null ]) : mixed
Parameters
$config : Migrations
$db : array<string|int, mixed>|ConnectionInterface|string|null = null

DB group. For testing purposes only.

Tags
throws
ConfigException

clearHistory()

Truncates the history table.

public clearHistory() : mixed

ensureTable()

Ensures that we have created our migrations table in the database.

public ensureTable() : 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
Return values
array<string|int, mixed>

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

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[, string $order = 'asc' ]) : array<string|int, mixed>
Parameters
$batch : int
$order : string = '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>

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
throws
ConfigException
throws
RuntimeException
Return values
bool

regress()

Migrate down to a previous batch

public regress([int $targetBatch = 0 ][, string|null $group = null ]) : bool

Calls each migration step required to get to the provided batch

Parameters
$targetBatch : int = 0

Target batch number, or negative for a relative batch, 0 for all

$group : string|null = null

Deprecated. The designation has no effect.

Tags
throws
ConfigException
throws
RuntimeException
Return values
bool

True on success, FALSE on failure or no migrations are found

addHistory()

Add a history to the table.

protected addHistory(object $migration, int $batch) : mixed
Parameters
$migration : object
$batch : int

getMigrationName()

Extracts the migration name from a filename

protected getMigrationName(string $migration) : string

Note: The migration name should be the classname, but maybe they are different.

Parameters
$migration : string

A migration filename w/o path.

Return values
string

getMigrationNumber()

Extracts the migration number from a filename

protected getMigrationNumber(string $migration) : string
Parameters
$migration : string

A migration filename w/o path.

Return values
string

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) : false|object
Parameters
$path : string

Full path to a valid migration file.

$namespace : string
Return values
false|object

Returns the migration object, or false on failure

removeHistory()

Removes a single history

protected removeHistory(object $history) : mixed
Parameters
$history : object

        
On this page

Search results