MigrationManager ​
- Type
- Class
- Namespace
- craft\db
- Inherits
- craft\db\MigrationManager » yii\base\Component » yii\base\BaseObject
- Implements
- yii\base\Configurable
- Since
- 3.0.0
MigrationManager manages a set of migrations.
Public Properties ​
Property | Description |
---|---|
behaviors | yii\base\Behavior – List of behaviors attached to this component. |
db | craft\db\Connection, array, string – The DB connection object or the application component ID of the DB connection |
migrationHistory | array – The migration history |
migrationNamespace | string, null – The namespace that the migration classes are in |
migrationPath | string, null – The path to the migrations directory |
migrationTable | string – The migrations table name |
newMigrations | array – The list of new migrations |
track | string – The migration track (e.g. craft , content , plugin:commerce , etc.) |
db
​
- Type
- craft\db\Connection, array, string
- Default value
'db'
The DB connection object or the application component ID of the DB connection
migrationHistory
​
- Type
- array
- Default value
null
- Access
- Read-only
The migration history
migrationNamespace
​
The namespace that the migration classes are in
migrationPath
​
The path to the migrations directory
migrationTable
​
- Type
- string
- Default value
\craft\db\Table::MIGRATIONS
The migrations table name
newMigrations
​
- Type
- array
- Default value
null
- Access
- Read-only
The list of new migrations
track
​
- Type
- string
- Default value
null
- Since
- 3.5.0
The migration track (e.g. craft
, content
, plugin:commerce
, etc.)
Public Methods ​
Method | Description |
---|---|
__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 a component property. |
__isset() | Checks if a property is set, i.e. defined and not null. |
__set() | Sets the value of a component property. |
__unset() | Sets a component property to be 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 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() | 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. |
truncateHistory() | Truncates the migration history. |
up() | Upgrades the application by applying new migrations. |
addMigrationHistory()
​
Adds a new migration entry to the history.
Arguments ​
$name
(string) – The migration name
Throws ​
createMigration()
​
Creates a new migration instance.
Arguments ​
$name
(string) – The migration name
Returns ​
yii\db\MigrationInterface, yii\db\Migration – The migration instance
Throws ​
- yii\base\Exception
if the migration folder doesn't exist
down()
​
Downgrades the application by reverting old migrations.
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 ​
- craft\errors\MigrationException
on migrate failure
getMigrationHistory()
​
Returns the migration history.
Arguments ​
$limit
(integer) – The maximum number of records in the history to be returned.null
for "no limit".
Returns ​
array – The migration history
getNewMigrations()
​
Returns the migrations that are not applied.
Returns ​
array – The list of new migrations
hasRun()
​
Returns whether a given migration has been applied.
Arguments ​
$name
(string) – The migration name
Returns ​
boolean – 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.
Throws ​
migrateDown()
​
Downgrades with the specified migration.
Arguments ​
$migration
(yii\db\Migration, string, yii\db\MigrationInterface) – The name of the migration to revert, or the migration itself
Throws ​
- yii\base\InvalidConfigException
if $migration is invalid - craft\errors\MigrationException
on migrate failure
migrateUp()
​
Upgrades with the specified migration.
Arguments ​
$migration
(yii\db\Migration, string, yii\db\MigrationInterface) – The name of the migration to apply, or the migration itself
Throws ​
- yii\base\InvalidConfigException
if $migration is invalid - craft\errors\MigrationException
on migrate failure
removeMigrationHistory()
​
Removes an existing migration from the history.
Arguments ​
$name
(string) – The migration name
truncateHistory()
​
- Since
- 3.0.32
Truncates the migration history.
up()
​
Upgrades the application by applying new migrations.
Arguments ​
$limit
(integer) – 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 |