Craft 3 Class Reference

Class craft\db\MigrationManager

Inheritance
craft\db\MigrationManager » yii\base\Component » yii\base\BaseObject
Implements
yii\base\Configurable
Available since version
3.0
Source Code
https://github.com/craftcms/cms/blob/master/src/db/MigrationManager.php

MigrationManager manages a set of migrations.

Public Properties
Property Type Description Defined By
$db craft\db\Connection, array, string The DB connection object or the application component ID of the DB connection craft\db\MigrationManager
$migrationNamespace string, null The namespace that the migration classes are in craft\db\MigrationManager
$migrationPath string, null The path to the migrations directory craft\db\MigrationManager
$migrationTable string The migrations table name craft\db\MigrationManager
$pluginId integer, null The plugin ID, if $type is set to 'plugin'. craft\db\MigrationManager
$type string, null The type of migrations we're dealing with here. craft\db\MigrationManager
Public Methods
Method Description Defined By
__call() Calls the named method which is not a class method. yii\base\BaseObject
__clone() This method is called after the object is created by cloning an existing one. yii\base\Component
__construct() Constructor. yii\base\BaseObject
__get() Returns the value of an object property. yii\base\BaseObject
__isset() Checks if a property is set, i.e. defined and not null. yii\base\BaseObject
__set() Sets value of an object property. yii\base\BaseObject
__unset() Sets an object property to null. yii\base\BaseObject
addMigrationHistory() Adds a new migration entry to the history. craft\db\MigrationManager
attachBehavior() Attaches a behavior to this component. yii\base\Component
attachBehaviors() Attaches a list of behaviors to the component. yii\base\Component
behaviors() Returns a list of behaviors that this component should behave as. yii\base\Component
canGetProperty() Returns a value indicating whether a property can be read. yii\base\BaseObject
canSetProperty() Returns a value indicating whether a property can be set. yii\base\BaseObject
className() Returns the fully qualified name of this class. yii\base\BaseObject
createMigration() Creates a new migration instance. craft\db\MigrationManager
detachBehavior() Detaches a behavior from the component. yii\base\Component
detachBehaviors() Detaches all behaviors from the component. yii\base\Component
down() Downgrades the application by reverting old migrations. craft\db\MigrationManager
ensureBehaviors() Makes sure that the behaviors declared in behaviors() are attached to this component. yii\base\Component
getBehavior() Returns the named behavior object. yii\base\Component
getBehaviors() Returns all behaviors attached to this component. yii\base\Component
getMigrationHistory() Returns the migration history. craft\db\MigrationManager
getNewMigrations() Returns the migrations that are not applied. craft\db\MigrationManager
hasEventHandlers() Returns a value indicating whether there is any handler attached to the named event. yii\base\Component
hasMethod() Returns a value indicating whether a method is defined. yii\base\BaseObject
hasProperty() Returns a value indicating whether a property is defined. yii\base\BaseObject
hasRun() Returns whether a given migration has been applied. craft\db\MigrationManager
init() Initializes the object. craft\db\MigrationManager
migrateDown() Downgrades with the specified migration. craft\db\MigrationManager
migrateUp() Upgrades with the specified migration. craft\db\MigrationManager
off() Detaches an existing event handler from this component. yii\base\Component
on() Attaches an event handler to an event. yii\base\Component
removeMigrationHistory() Removes an existing migration from the history. craft\db\MigrationManager
trigger() Triggers an event. yii\base\Component
up() Upgrades the application by applying new migrations. craft\db\MigrationManager
Constants
Constant Value Description Defined By
BASE_MIGRATION 'm000000_000000_base' The name of the dummy migration that marks the beginning of the whole migration history. craft\db\MigrationManager
TYPE_APP 'app' craft\db\MigrationManager
TYPE_CONTENT 'content' craft\db\MigrationManager
TYPE_PLUGIN 'plugin' craft\db\MigrationManager

Property Details

$db public property #

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

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

$migrationNamespace public property #

The namespace that the migration classes are in

public string, null $migrationNamespace null

$migrationPath public property #

The path to the migrations directory

public string, null $migrationPath null

$migrationTable public property #

The migrations table name

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

$pluginId public property #

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

public integer, null $pluginId null

$type public property #

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

public string, null $type null

Method Details

addMigrationHistory() public method #

Adds a new migration entry to the history.

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

createMigration() public method #

Creates a new migration instance.

public yii\db\MigrationInterface, yii\db\Migration createMigration ( \craft\db\string $name )
$name string The migration name
return yii\db\MigrationInterface, yii\db\Migration The migration instance
throws yii\base\Exception if the migration folder doesn't exist

down() public method #

Downgrades the application by reverting old migrations.

public void down ( \craft\db\int $limit 1 )
$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() public method #

Returns the migration history.

public array getMigrationHistory ( \craft\db\int $limit 0 )
$limit integer The maximum number of records in the history to be returned. null for "no limit".
return array The migration history

getNewMigrations() public method #

Returns the migrations that are not applied.

public array getNewMigrations ( )
return array The list of new migrations

hasRun() public method #

Returns whether a given migration has been applied.

public boolean hasRun ( \craft\db\string $name )
$name string The migration name
return boolean Whether the migration has been applied

init() public method #

Initializes the object.

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

public void init ( )

migrateDown() public method #

Downgrades with the specified migration.

public void migrateDown ( $migration )
$migration string, yii\db\MigrationInterface, yii\db\Migration The name of the migration to revert, or the migration itself
throws yii\base\InvalidConfigException if $migration is invalid
throws craft\errors\MigrationException on migrate failure

migrateUp() public method #

Upgrades with the specified migration.

public void migrateUp ( $migration )
$migration string, yii\db\MigrationInterface, yii\db\Migration The name of the migration to apply, or the migration itself
throws yii\base\InvalidConfigException if $migration is invalid
throws craft\errors\MigrationException on migrate failure

removeMigrationHistory() public method #

Removes an existing migration from the history.

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

up() public method #

Upgrades the application by applying new migrations.

public void up ( \craft\db\int $limit 0 )
$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