UserFrosting API

Migrator

Migrator Class.

Migrator service used to manage and run database migrations

Tags
author

Louis Charette

Table of Contents

$repository MigrationRepositoryInterface
$db Manager
$locator MigrationLocatorInterface
$connection string
$notes array
__construct() Constructor. mixed
run() Run all the specified migrations up. Check that dependencies are met before running. array
pendingMigrations() Get the migration classes that have not yet run. array
runPending() Run an array of migrations. mixed
runUp() Run "up" a migration class. mixed
rollback() Rollback the last migration operation. array
rollbackMigration() Rollback a specific migration. array
getMigrationsForRollback() Get the migrations for a rollback operation. array
rollbackMigrations() Rollback the given migrations. array
checkRollbackDependencies() Check if migrations can be rolledback. mixed
reset() Rolls all of the currently applied migrations back. array
runDown() Run "down" a migration instance. mixed
runMigration() Run a migration inside a transaction if the database supports it. mixed
pretendToRun() Pretend to run the migrations. mixed
getQueries() Get all of the queries that would be run for a migration. array
resolve() Resolve a migration instance from it's class name. MigrationInterface
getAvailableMigrations() Get all of the migration files in a given path. array
getRanMigrations() Get a list of all ran migrations. array
getPendingMigrations() Get a list of pending migrations. array
getRepository() Get the migration repository instance. MigrationRepositoryInterface
setRepository() Set the migration repository instance. mixed
repositoryExists() Determine if the migration repository exists. bool
getLocator() Get the migration locator instance. MigrationLocatorInterface
setLocator() Set the migration locator instance. mixed
getSchemaBuilder() Get the schema builder. Builder
getConnection() Return the connection instance. Connection
setConnection() Define which connection to use. mixed
getSchemaGrammar() Get instance of Grammar. Grammar
note() Raise a note event for the migrator. mixed
getNotes() Get the notes for the last operation. array

Properties

$connection

protected string $connection

Methods

run()

Run all the specified migrations up. Check that dependencies are met before running.

public run( [ $options : array = [] ] ) : array
Parameters
$options : array = []

Options for the current operations [step, pretend]

Return values
array

The list of ran migrations

pendingMigrations()

Get the migration classes that have not yet run.

protected pendingMigrations( $available : array , $ran : array ) : array
Parameters
$available : array

The available migrations returned by the migration locator

$ran : array

The list of already ran migrations returned by the migration repository

Return values
array

The list of pending migrations, ie the available migrations not ran yet

runPending()

Run an array of migrations.

protected runPending( $migrations : array [, $options : array = [] ] ) : mixed
Parameters
$migrations : array

An array of migrations classes names to be run (unsorted, unvalidated)

$options : array = []

The options for the current operation [step, pretend]

Return values
mixed

runUp()

Run "up" a migration class.

protected runUp( $migrationClassName : string , $batch : int , $pretend : bool ) : mixed
Parameters
$migrationClassName : string

The migration class name

$batch : int

The current bacth number

$pretend : bool

If this operation should be pretended / faked

Return values
mixed

rollback()

Rollback the last migration operation.

public rollback( [ $options : array = [] ] ) : array
Parameters
$options : array = []

The options for the current operation [steps, pretend]

Return values
array

The list of rolledback migration classes

rollbackMigration()

Rollback a specific migration.

public rollbackMigration( $migrationClassName : string [, $options : array = [] ] ) : array
Parameters
$migrationClassName : string

The Migration to rollback

$options : array = []
Return values
array

The list of rolledback migration classes

getMigrationsForRollback()

Get the migrations for a rollback operation.

protected getMigrationsForRollback( $options : array ) : array
Parameters
$options : array

The options for the current operation

Return values
array

An ordered array of migrations to rollback

rollbackMigrations()

Rollback the given migrations.

protected rollbackMigrations( $migrations : array , $options : array ) : array
Parameters
$migrations : array

An array of migrations to rollback formated as an eloquent collection

$options : array

The options for the current operation

Return values
array

The list of rolledback migration classes

checkRollbackDependencies()

Check if migrations can be rolledback.

protected checkRollbackDependencies( $migrations : array ) : mixed
Parameters
$migrations : array

The migrations classes to rollback

Tags
throws
Exception

If rollback can't be performed

Return values
mixed

reset()

Rolls all of the currently applied migrations back.

public reset( [ $pretend : bool = false ] ) : array
Parameters
$pretend : bool = false

Should this operation be pretended

Return values
array

An array of all the rolledback migration classes

runDown()

Run "down" a migration instance.

protected runDown( $migrationClassName : string , $pretend : bool ) : mixed
Parameters
$migrationClassName : string

The migration class name

$pretend : bool

Is the operation should be pretended

Return values
mixed

runMigration()

Run a migration inside a transaction if the database supports it.

protected runMigration( $migration : MigrationInterface , $method : string ) : mixed

Note : As of Laravel 5.4, only PostgresGrammar supports it.

Parameters
$migration : MigrationInterface

The migration instance

$method : string

The method used [up, down]

Return values
mixed

pretendToRun()

Pretend to run the migrations.

protected pretendToRun( $migration : MigrationInterface , $method : string ) : mixed
Parameters
$migration : MigrationInterface

The migration instance

$method : string

The method used [up, down]

Return values
mixed

getQueries()

Get all of the queries that would be run for a migration.

protected getQueries( $migration : MigrationInterface , $method : string ) : array
Parameters
$migration : MigrationInterface

The migration instance

$method : string

The method used [up, down]

Return values
array

The queries executed by the processed schema

resolve()

Resolve a migration instance from it's class name.

public resolve( $migrationClassName : string ) : MigrationInterface
Parameters
$migrationClassName : string

The class name

Return values
MigrationInterface

The migration class instance

getAvailableMigrations()

Get all of the migration files in a given path.

public getAvailableMigrations( ) : array
Return values
array

The list of migration classes found in the filesystem

getRanMigrations()

Get a list of all ran migrations.

public getRanMigrations( [ $steps : int = -1 ] [, $order : string = 'asc' ] ) : array
Parameters
$steps : int = -1

Number of batch to return

$order : string = 'asc'

asc|desc

Return values
array

getPendingMigrations()

Get a list of pending migrations.

public getPendingMigrations( ) : array
Return values
array

getRepository()

Get the migration repository instance.

public getRepository( ) : MigrationRepositoryInterface
Return values
MigrationRepositoryInterface

repositoryExists()

Determine if the migration repository exists.

public repositoryExists( ) : bool
Return values
bool

If the repository exist

getSchemaBuilder()

Get the schema builder.

public getSchemaBuilder( ) : Builder
Return values
Builder

getConnection()

Return the connection instance.

public getConnection( ) : Connection
Return values
Connection

setConnection()

Define which connection to use.

public setConnection( $name : string ) : mixed
Parameters
$name : string

The connection name

Return values
mixed

getSchemaGrammar()

Get instance of Grammar.

protected getSchemaGrammar( ) : Grammar
Return values
Grammar

note()

Raise a note event for the migrator.

protected note( $message : string ) : mixed
Parameters
$message : string

The message

Return values
mixed

getNotes()

Get the notes for the last operation.

public getNotes( ) : array
Return values
array

An array of notes

Search results