class Migrator (View source)

Properties

protected Dispatcher $events

The event dispatcher instance.

protected MigrationRepositoryInterface $repository

The migration repository implementation.

protected Filesystem $files

The filesystem instance.

protected ConnectionResolverInterface $resolver

The connection resolver instance.

protected string $connection

The name of the default connection.

protected array $paths

The paths to all of the migration files.

static protected Migration|null> $requiredPathCache

The paths that have already been required.

protected OutputInterface $output

The output interface implementation.

Methods

void
__construct(MigrationRepositoryInterface $repository, ConnectionResolverInterface $resolver, Filesystem $files, Dispatcher $dispatcher = null)

Create a new migrator instance.

array
run(array|string $paths = [], array $options = [])

Run the pending migrations at a given path.

array
pendingMigrations(array $files, array $ran)

Get the migration files that have not yet run.

void
runPending(array $migrations, array $options = [])

Run an array of migrations.

void
runUp(string $file, int $batch, bool $pretend)

Run "up" a migration instance.

array
rollback(array|string $paths = [], array $options = [])

Rollback the last migration operation.

array
getMigrationsForRollback(array $options)

Get the migrations for a rollback operation.

array
rollbackMigrations(array $migrations, array|string $paths, array $options)

Rollback the given migrations.

array
reset(array|string $paths = [], bool $pretend = false)

Rolls all of the currently applied migrations back.

array
resetMigrations(array $migrations, array $paths, bool $pretend = false)

Reset the given migrations.

void
runDown(string $file, object $migration, bool $pretend)

Run "down" a migration instance.

void
runMigration(object $migration, string $method)

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

void
pretendToRun(object $migration, string $method)

Pretend to run the migrations.

array
getQueries(object $migration, string $method)

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

void
runMethod(Connection $connection, object $migration, string $method)

Run a migration method on the given connection.

object
resolve(string $file)

Resolve a migration instance from a file.

object
resolvePath(string $path)

Resolve a migration instance from a migration path.

string
getMigrationClass(string $migrationName)

Generate a migration class name based on the migration file name.

array
getMigrationFiles(string|array $paths)

Get all of the migration files in a given path.

void
requireFiles(array $files)

Require in all the migration files in a given path.

string
getMigrationName(string $path)

Get the name of the migration.

void
path(string $path)

Register a custom migration path.

array
paths()

Get all of the custom migration paths.

string
getConnection()

Get the default connection name.

mixed
usingConnection(string $name, callable $callback)

Execute the given callback using the given connection as the default connection.

void
setConnection(string $name)

Set the default connection name.

resolveConnection(string $connection)

Resolve the database connection instance.

getSchemaGrammar(Connection $connection)

Get the schema grammar out of a migration connection.

getRepository()

Get the migration repository instance.

bool
repositoryExists()

Determine if the migration repository exists.

bool
hasRunAnyMigrations()

Determine if any migrations have been run.

void
deleteRepository()

Delete the migration repository data store.

getFilesystem()

Get the file system instance.

$this
setOutput(OutputInterface $output)

Set the output implementation that should be used by the console.

void
write(string $component, array<int,string>|string ...$arguments)

Write to the console's output.

void
fireMigrationEvent(MigrationEvent $event)

Fire the given event for the migration.

Details

void __construct(MigrationRepositoryInterface $repository, ConnectionResolverInterface $resolver, Filesystem $files, Dispatcher $dispatcher = null)

Create a new migrator instance.

Parameters

MigrationRepositoryInterface $repository
ConnectionResolverInterface $resolver
Filesystem $files
Dispatcher $dispatcher

Return Value

void

array run(array|string $paths = [], array $options = [])

Run the pending migrations at a given path.

Parameters

array|string $paths
array $options

Return Value

array

protected array pendingMigrations(array $files, array $ran)

Get the migration files that have not yet run.

Parameters

array $files
array $ran

Return Value

array

void runPending(array $migrations, array $options = [])

Run an array of migrations.

Parameters

array $migrations
array $options

Return Value

void

protected void runUp(string $file, int $batch, bool $pretend)

Run "up" a migration instance.

Parameters

string $file
int $batch
bool $pretend

Return Value

void

array rollback(array|string $paths = [], array $options = [])

Rollback the last migration operation.

Parameters

array|string $paths
array $options

Return Value

array

protected array getMigrationsForRollback(array $options)

Get the migrations for a rollback operation.

Parameters

array $options

Return Value

array

protected array rollbackMigrations(array $migrations, array|string $paths, array $options)

Rollback the given migrations.

Parameters

array $migrations
array|string $paths
array $options

Return Value

array

array reset(array|string $paths = [], bool $pretend = false)

Rolls all of the currently applied migrations back.

Parameters

array|string $paths
bool $pretend

Return Value

array

protected array resetMigrations(array $migrations, array $paths, bool $pretend = false)

Reset the given migrations.

Parameters

array $migrations
array $paths
bool $pretend

Return Value

array

protected void runDown(string $file, object $migration, bool $pretend)

Run "down" a migration instance.

Parameters

string $file
object $migration
bool $pretend

Return Value

void

protected void runMigration(object $migration, string $method)

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

Parameters

object $migration
string $method

Return Value

void

protected void pretendToRun(object $migration, string $method)

Pretend to run the migrations.

Parameters

object $migration
string $method

Return Value

void

protected array getQueries(object $migration, string $method)

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

Parameters

object $migration
string $method

Return Value

array

protected void runMethod(Connection $connection, object $migration, string $method)

Run a migration method on the given connection.

Parameters

Connection $connection
object $migration
string $method

Return Value

void

object resolve(string $file)

Resolve a migration instance from a file.

Parameters

string $file

Return Value

object

protected object resolvePath(string $path)

Resolve a migration instance from a migration path.

Parameters

string $path

Return Value

object

protected string getMigrationClass(string $migrationName)

Generate a migration class name based on the migration file name.

Parameters

string $migrationName

Return Value

string

array getMigrationFiles(string|array $paths)

Get all of the migration files in a given path.

Parameters

string|array $paths

Return Value

array

void requireFiles(array $files)

Require in all the migration files in a given path.

Parameters

array $files

Return Value

void

string getMigrationName(string $path)

Get the name of the migration.

Parameters

string $path

Return Value

string

void path(string $path)

Register a custom migration path.

Parameters

string $path

Return Value

void

array paths()

Get all of the custom migration paths.

Return Value

array

string getConnection()

Get the default connection name.

Return Value

string

mixed usingConnection(string $name, callable $callback)

Execute the given callback using the given connection as the default connection.

Parameters

string $name
callable $callback

Return Value

mixed

void setConnection(string $name)

Set the default connection name.

Parameters

string $name

Return Value

void

Connection resolveConnection(string $connection)

Resolve the database connection instance.

Parameters

string $connection

Return Value

Connection

protected Grammar getSchemaGrammar(Connection $connection)

Get the schema grammar out of a migration connection.

Parameters

Connection $connection

Return Value

Grammar

MigrationRepositoryInterface getRepository()

Get the migration repository instance.

bool repositoryExists()

Determine if the migration repository exists.

Return Value

bool

bool hasRunAnyMigrations()

Determine if any migrations have been run.

Return Value

bool

void deleteRepository()

Delete the migration repository data store.

Return Value

void

Filesystem getFilesystem()

Get the file system instance.

Return Value

Filesystem

$this setOutput(OutputInterface $output)

Set the output implementation that should be used by the console.

Parameters

OutputInterface $output

Return Value

$this

protected void write(string $component, array<int,string>|string ...$arguments)

Write to the console's output.

Parameters

string $component
array<int,string>|string ...$arguments

Return Value

void

void fireMigrationEvent(MigrationEvent $event)

Fire the given event for the migration.

Parameters

MigrationEvent $event

Return Value

void