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.

View source

# 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

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

View source

# migrationHistory

Type
array
Access
Read-only

The migration history

View source

# migrationNamespace

Type
string, null

The namespace that the migration classes are in

View source

# migrationPath

Type
string, null

The path to the migrations directory

View source

# migrationTable

Type
string

The migrations table name

View source

# newMigrations

Type
array
Access
Read-only

The list of new migrations

View source

# track

Type
string
Since
3.5.0

The migration track (e.g. craft, content, plugin:commerce, etc.)

View source

# 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 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.
truncateHistory() Truncates the migration history.
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

Throws

# 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

# 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

# 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

# getNewMigrations()

Returns the migrations that are not applied.

View source

Returns

array – The list of new migrations

# 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

# 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

Throws

# migrateDown()

Downgrades with the specified migration.

View source

Arguments

Throws

# migrateUp()

Upgrades with the specified migration.

View source

Arguments

Throws

# removeMigrationHistory()

Removes an existing migration from the history.

View source

Arguments

  • $name (string) – The migration name

# truncateHistory()

Since
3.0.32

Truncates the migration history.

View source

# 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

# Constants

Constant Description
BASE_MIGRATION The name of the dummy migration that marks the beginning of the whole migration history.
TRACK_CONTENT
TRACK_CRAFT