MigrationManager

Type
Class
Namespace
craft\db
Inherits
craft\db\MigrationManager » yii\base\Component » yii\base\BaseObject
Implements
yii\base\Configurable
Since
3.0

MigrationManager manages a set of migrations.

View source

Public Properties

PropertyDescription
$behaviorsyii\base\Behavior – List of behaviors attached to this component
$dbcraft\db\Connection, array, string – The DB connection object or the application component ID of the DB connection
$migrationHistoryarray – The migration history
$migrationNamespacestring, null – The namespace that the migration classes are in
$migrationPathstring, null – The path to the migrations directory
$migrationTablestring – The migrations table name
$newMigrationsarray – The list of new migrations
$pluginIdinteger, null – The plugin ID, if $type is set to 'plugin'.
$typestring, null – The type of migrations we're dealing with here.

$db

Type
craft\db\Connection, array, string

The DB connection object or the application component ID of the DB connection

View source

Signature

public craft\db\Connection, array, string $db = 'db'

$migrationHistory

Type
array
Access
Read-only

The migration history

View source

Signature

public array getMigrationHistory ( \craft\db\int $limit = 0 )

$migrationNamespace

Type
string, null

The namespace that the migration classes are in

View source

Signature

public string, null $migrationNamespace = null

$migrationPath

Type
string, null

The path to the migrations directory

View source

Signature

public string, null $migrationPath = null

$migrationTable

Type
string

The migrations table name

View source

Signature

public string $migrationTable = '{{%migrations}}'

$newMigrations

Type
array
Access
Read-only

The list of new migrations

View source

Signature

public array getNewMigrations ( )

$pluginId

Type
integer, null

The plugin ID, if $type is set to 'plugin'.

View source

Signature

public integer, null $pluginId = null

$type

Type
string, null

The type of migrations we're dealing with here. Can be 'app', 'plugin', or 'content'.

View source

Signature

public string, null $type = null

Public Methods

MethodDescription
__call()Calls the named method which is not a class method.
__clone()This method is called after the object is created by cloning an existing one.
__construct()Constructor.
__get()Returns the value of an object property.
__isset()Checks if a property is set, i.e. defined and not null.
__set()Sets value of an object property.
__unset()Sets an object property to null.
addMigrationHistory()Adds a new migration entry to the history.
attachBehavior()Attaches a behavior to this component.
attachBehaviors()Attaches a list of behaviors to the component.
behaviors()Returns a list of behaviors that this component should behave as.
canGetProperty()Returns a value indicating whether a property can be read.
canSetProperty()Returns a value indicating whether a property can be set.
className()Returns the fully qualified name of this class.
createMigration()Creates a new migration instance.
detachBehavior()Detaches a behavior from the component.
detachBehaviors()Detaches all behaviors from the component.
down()Downgrades the application by reverting old migrations.
ensureBehaviors()Makes sure that the behaviors declared in behaviors() are attached to this component.
getBehavior()Returns the named behavior object.
getBehaviors()Returns all behaviors attached to this component.
getMigrationHistory()Returns the migration history.
getNewMigrations()Returns the migrations that are not applied.
hasEventHandlers()Returns a value indicating whether there is any handler attached to the named event.
hasMethod()Returns a value indicating whether a method is defined.
hasProperty()Returns a value indicating whether a property is defined.
hasRun()Returns whether a given migration has been applied.
init()Initializes the object.
migrateDown()Downgrades with the specified migration.
migrateUp()Upgrades with the specified migration.
off()Detaches an existing event handler from this component.
on()Attaches an event handler to an event.
removeMigrationHistory()Removes an existing migration from the history.
trigger()Triggers an event.
up()Upgrades the application by applying new migrations.

addMigrationHistory()

Adds a new migration entry to the history.

View source

Arguments

  • $name (string) – The migration name

Signature

public void addMigrationHistory ( \craft\db\string $name )

createMigration()

Creates a new migration instance.

View source

Arguments

  • $name (string) – The migration name

Returns

yii\db\MigrationInterface, yii\db\Migration – The migration instance

Throws

Signature

public yii\db\MigrationInterface, yii\db\Migration createMigration ( \craft\db\string $name )

down()

Downgrades the application by reverting old migrations.

View source

Arguments

  • $limit (integer) – The number of migrations to be reverted. Defaults to 1, meaning the last applied migration will be reverted. If set to 0, all migrations will be reverted.

Throws

Signature

public void down ( \craft\db\int $limit = 1 )

getMigrationHistory()

Returns the migration history.

View source

Arguments

  • $limit (integer) – The maximum number of records in the history to be returned. null for "no limit".

Returns

array – The migration history

Signature

public array getMigrationHistory ( \craft\db\int $limit = 0 )

getNewMigrations()

Returns the migrations that are not applied.

View source

Returns

array – The list of new migrations

Signature

public array getNewMigrations ( )

hasRun()

Returns whether a given migration has been applied.

View source

Arguments

  • $name (string) – The migration name

Returns

boolean – Whether the migration has been applied

Signature

public boolean hasRun ( \craft\db\string $name )

init()

Initializes the object.

This method is invoked at the end of the constructor after the object is initialized with the given configuration.

View source

Signature

public void init ( )

migrateDown()

Downgrades with the specified migration.

View source

Arguments

Throws

Signature

public void migrateDown ( $migration )

migrateUp()

Upgrades with the specified migration.

View source

Arguments

Throws

Signature

public void migrateUp ( $migration )

removeMigrationHistory()

Removes an existing migration from the history.

View source

Arguments

  • $name (string) – The migration name

Signature

public void removeMigrationHistory ( \craft\db\string $name )

up()

Upgrades the application by applying new migrations.

View source

Arguments

  • $limit (integer) – The number of new migrations to be applied. If 0, it means applying all available new migrations.

Throws

Signature

public void up ( \craft\db\int $limit = 0 )

Constants

ConstantDescription
BASE_MIGRATIONThe name of the dummy migration that marks the beginning of the whole migration history.
TYPE_APP
TYPE_CONTENT
TYPE_PLUGIN