MigrationManager
- Type
- Class
- Namespace
- craft\db
- Inherits
- craft\db\MigrationManager » yii\base\Component (opens new window) » yii\base\BaseObject (opens new window)
- Implements
- yii\base\Configurable (opens new window)
- Since
- 3.0.0
MigrationManager manages a set of migrations.
View source (opens new window)
# Public Properties
Property | Description |
---|---|
behaviors (opens new window) | yii\base\Behavior (opens new window) – List of behaviors attached to this component. |
db | craft\db\Connection, array (opens new window), string (opens new window) – The DB connection object or the application component ID of the DB connection |
migrationHistory | array (opens new window) – The migration history |
migrationNamespace | string (opens new window), null (opens new window) – The namespace that the migration classes are in |
migrationPath | string (opens new window), null (opens new window) – The path to the migrations directory |
migrationTable | string (opens new window) – The migrations table name |
newMigrations | array (opens new window) – The list of new migrations |
track | string (opens new window) – The migration track (e.g. craft , content , plugin:commerce , etc. |
# db
- Type
- craft\db\Connection, array (opens new window), string (opens new window)
- Default value
'db'
The DB connection object or the application component ID of the DB connection
View source (opens new window)
# migrationHistory
- Type
- array (opens new window)
- Default value
null
- Access
- Read-only
The migration history
View source (opens new window)
# migrationNamespace
- Type
- string (opens new window), null (opens new window)
- Default value
null
The namespace that the migration classes are in
View source (opens new window)
# migrationPath
- Type
- string (opens new window), null (opens new window)
- Default value
null
The path to the migrations directory
View source (opens new window)
# migrationTable
- Type
- string (opens new window)
- Default value
\craft\db\Table::MIGRATIONS
The migrations table name
View source (opens new window)
# newMigrations
- Type
- array (opens new window)
- Default value
null
- Access
- Read-only
The list of new migrations
View source (opens new window)
# track
- Type
- string (opens new window)
- Default value
null
- Since
- 3.5.0
The migration track (e.g. craft
, content
, plugin:commerce
, etc.)
View source (opens new window)
# Public Methods
Method | Description |
---|---|
__call() (opens new window) | Calls the named method which is not a class method. |
__clone() (opens new window) | This method is called after the object is created by cloning an existing one. |
__construct() (opens new window) | Constructor. |
__get() (opens new window) | Returns the value of a component property. |
__isset() (opens new window) | Checks if a property is set, i.e. defined and not null. |
__set() (opens new window) | Sets the value of a component property. |
__unset() (opens new window) | Sets a component property to be null. |
addMigrationHistory() | Adds a new migration entry to the history. |
attachBehavior() (opens new window) | Attaches a behavior to this component. |
attachBehaviors() (opens new window) | Attaches a list of behaviors to the component. |
behaviors() (opens new window) | Returns a list of behaviors that this component should behave as. |
canGetProperty() (opens new window) | Returns a value indicating whether a property can be read. |
canSetProperty() (opens new window) | Returns a value indicating whether a property can be set. |
className() (opens new window) | Returns the fully qualified name of this class. |
createMigration() | Creates a new migration instance. |
detachBehavior() (opens new window) | Detaches a behavior from the component. |
detachBehaviors() (opens new window) | Detaches all behaviors from the component. |
down() | Downgrades the application by reverting old migrations. |
ensureBehaviors() (opens new window) | Makes sure that the behaviors declared in behaviors() (opens new window) are attached to this component. |
getBehavior() (opens new window) | Returns the named behavior object. |
getBehaviors() (opens new window) | Returns all behaviors attached to this component. |
getMigrationHistory() | Returns the migration history. |
getNewMigrations() | Returns the migrations that are not applied. |
hasEventHandlers() (opens new window) | Returns a value indicating whether there is any handler attached to the named event. |
hasMethod() (opens new window) | Returns a value indicating whether a method is defined. |
hasProperty() (opens new window) | Returns a value indicating whether a property is defined for this component. |
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() (opens new window) | Detaches an existing event handler from this component. |
on() (opens new window) | Attaches an event handler to an event. |
removeMigrationHistory() | Removes an existing migration from the history. |
trigger() (opens new window) | Triggers an event. |
truncateHistory() | Truncates the migration history. |
up() | Upgrades the application by applying new migrations. |
# addMigrationHistory()
Adds a new migration entry to the history.
View source (opens new window)
Arguments
$name
(string (opens new window)) – The migration name
Throws
# createMigration()
Creates a new migration instance.
View source (opens new window)
Arguments
$name
(string (opens new window)) – The migration name
Returns
yii\db\MigrationInterface (opens new window), yii\db\Migration (opens new window) – The migration instance
Throws
- yii\base\Exception (opens new window)
if the migration folder doesn't exist
# down()
Downgrades the application by reverting old migrations.
View source (opens new window)
Arguments
$limit
(integer (opens new window)) – 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
- craft\errors\MigrationException
on migrate failure
# getMigrationHistory()
Returns the migration history.
View source (opens new window)
Arguments
$limit
(integer (opens new window)) – The maximum number of records in the history to be returned.null
for "no limit".
Returns
array (opens new window) – The migration history
# getNewMigrations()
Returns the migrations that are not applied.
View source (opens new window)
Returns
array (opens new window) – The list of new migrations
# hasRun()
Returns whether a given migration has been applied.
View source (opens new window)
Arguments
$name
(string (opens new window)) – The migration name
Returns
boolean (opens new window) – Whether the migration has been applied
# 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 (opens new window)
Throws
# migrateDown()
Downgrades with the specified migration.
View source (opens new window)
Arguments
$migration
(yii\db\Migration (opens new window), string (opens new window), yii\db\MigrationInterface (opens new window)) – The name of the migration to revert, or the migration itself
Throws
- yii\base\InvalidConfigException (opens new window)
if $migration is invalid - craft\errors\MigrationException
on migrate failure
# migrateUp()
Upgrades with the specified migration.
View source (opens new window)
Arguments
$migration
(yii\db\Migration (opens new window), string (opens new window), yii\db\MigrationInterface (opens new window)) – The name of the migration to apply, or the migration itself
Throws
- yii\base\InvalidConfigException (opens new window)
if $migration is invalid - craft\errors\MigrationException
on migrate failure
# removeMigrationHistory()
Removes an existing migration from the history.
View source (opens new window)
Arguments
$name
(string (opens new window)) – The migration name
# truncateHistory()
- Since
- 3.0.32
Truncates the migration history.
View source (opens new window)
# up()
Upgrades the application by applying new migrations.
View source (opens new window)
Arguments
$limit
(integer (opens new window)) – The number of new migrations to be applied. If 0, it means applying all available new migrations.
Throws
- craft\errors\MigrationException
on migrate failure
# Constants
Constant | Description |
---|---|
BASE_MIGRATION | The name of the dummy migration that marks the beginning of the whole migration history. |
TRACK_CONTENT | |
TRACK_CRAFT |