MigrateCommand

Type
Class
Namespace
Craft
Inherits
Craft\MigrateCommand » MigrateCommand » CConsoleCommand » CComponent
Since
1.0

MigrateCommand is a command for managing Craft and plugin database migrations.

MigrateCommand supports the following options.

Creates a new migration in your plugins’ migrations/ folder with the given MigrationDescription:

yiic migrate create MigrationDescription PluginHandle

Shows a list of migrations that have already been ran for this plugin:

yiic migrate history PluginHandle

Shows a list of migrations that have not been applied yet, but should be:

yiic migrate new PluginHandle

Runs all new migrations for a plugin:

yiic migrate up PluginHandle

Note that PluginHandle is optional in these examples and if it is not presented, the command will run against Craft.

Craft explicitly disables support for Yii's "down", "redo" and "mark" actions.

This command will exit with the following exit codes:

  • 0 on success
  • 1 on general error
  • 2 on failed migration.

See also http://craftcms.com

View source

Public Properties

PropertyDescription
$connectionIDstring – The application component ID that specifies the database connection for storing migration information.
$defaultActionstring – The default command action.
$interactiveboolean – Whether to execute the migration in an interactive mode.
$migrationPathstring – The directory that stores the migrations.
$migrationTablestring – The name of the table for keeping applied migration information.
$templateFilestring – The path of the template file for generating new migrations.

Public Methods

MethodDescription
__call()Calls the named method which is not a class method.
__construct()Constructor.
__get()Returns a property value, an event handler list or a behavior based on its name.
__isset()Checks if a property value is null.
__set()Sets value of a component property.
__unset()Sets a component property to be null.
actionCreate()Used for creating a new migration, for either Craft or a plugin.
actionDown()Used for stopping "down" actions from occurring.
actionHistory()Used for seeing which migrations haven't already been ran in Craft or a plugin.
actionMark()Used for stopping "Mark" actions from occurring.
actionNew()Used for seeing any new migrations that haven't run yet in Craft or a plugin.
actionRedo()Used for stopping "redo" actions from occurring.
actionTo()Used for stopping "To" actions from occurring.
actionUp()Used for running any new migrations for either Craft or a plugin.
asa()Returns the named behavior object.
attachBehavior()Attaches a behavior to this component.
attachBehaviors()Attaches a list of behaviors to the component.
attachEventHandler()Attaches an event handler to an event.
beforeAction()Used for ensuring a plugin's migration exists if the action is "create".
behaviors()Returns a list of behaviors that this command should behave as.
buildFileList()Builds the file list of a directory.
canGetProperty()Determines whether a property can be read.
canSetProperty()Determines whether a property can be set.
confirm
copyFiles()Copies a list of files from one place to another.
detachBehavior()Detaches a behavior from the component.
detachBehaviors()Detaches all behaviors from the component.
detachEventHandler()Detaches an existing event handler.
disableBehavior()Disables an attached behavior.
disableBehaviors()Disables all behaviors attached to this component.
enableBehavior()Enables an attached behavior.
enableBehaviors()Enables all behaviors attached to this component.
ensureDirectory()Creates all parent directories if they do not exist.
evaluateExpression()Evaluates a PHP expression or callback under the context of this component.
getCommandRunner()
getEventHandlers()Returns the list of attached event handlers for an event.
getHelp
getName()
getOptionHelp()Provides the command option help information.
getTemplate()Gets the migration template used for generating new migrations.
hasEvent()Determines whether an event is defined.
hasEventHandler()Checks whether the named event has attached handlers.
hasProperty()Determines whether a property is defined.
init()Initializes the command object.
onAfterAction()This event is raised after an action finishes execution.
onBeforeAction()This event is raised before an action is to be executed.
pluralize()Converts a word to its plural form.
prompt()Reads input via the readline PHP extension if that's available, or fgets() if readline is not installed.
raiseEvent()Raises an event.
renderFile()Renders a view file.
run()Executes the command.
usageError()Displays a usage error.

actionCreate()

Used for creating a new migration, for either Craft or a plugin. yiic migrate create MigrationDescription PluginHandle

If PluginHandle is omitted, the migration is created for Craft in craft/app/migrations. If it is available, the migration is created in craft/plugins/PluginHandle/migrations.

The migration description can only contain letters, digits and/or underscore characters.

View source

Arguments

  • $args (array) – The arguments passed in.

Returns

integer

Signature

public integer actionCreate ( $args )

actionDown()

Used for stopping "down" actions from occurring.

View source

Arguments

  • $args (array) – The arguments for the action.

Returns

null

Signature

public null actionDown ( $args )

actionHistory()

Used for seeing which migrations haven't already been ran in Craft or a plugin. yiic migrate history PluginHandle

If PluginHandle is omitted, it will display all of Craft's migrations that have already ran. If it is available, it will display all of PluginHandle's migrations that have already ran.

View source

Arguments

  • $args (array) – The arguments passed in.

Returns

integer

Signature

public integer actionHistory ( $args )

actionMark()

Used for stopping "Mark" actions from occurring.

View source

Arguments

Returns

null

Signature

public null actionMark ( $args )

actionNew()

Used for seeing any new migrations that haven't run yet in Craft or a plugin. yiic migrate new PluginHandle

If PluginHandle is omitted, it will display any new Craft migrations that have not run, yet. If it is available, it will display all of PluginHandle's migrations that have not run, yet.

View source

Arguments

  • $args (array) – The arguments passed in.

Returns

integer

Signature

public integer actionNew ( $args )

actionRedo()

Used for stopping "redo" actions from occurring.

View source

Arguments

Returns

null

Signature

public null actionRedo ( $args )

actionTo()

Used for stopping "To" actions from occurring.

View source

Arguments

Returns

null

Signature

public null actionTo ( $args )

actionUp()

Used for running any new migrations for either Craft or a plugin. yiic migrate up PluginHandle

If PluginHandle is omitted, any new migrations that haven't ran yet in craft/app/migrations will be ran. If it is available, any new migrations in craft/plugins/PluginHandle/migrations that haven't ran yet, will run.

View source

Arguments

  • $args (array) – The arguments passed in.

Returns

integer

Signature

public integer actionUp ( $args )

beforeAction()

Used for ensuring a plugin's migration exists if the action is "create". This method is invoked right before an action is to be executed.

View source

Arguments

  • $action (string) – The name of the action to run.
  • $params (array) – The parameters to be passed to the action's method.

Returns

boolean – Whether the action should be executed or not.

Signature

public boolean beforeAction ( $action, $params )

getTemplate()

Gets the migration template used for generating new migrations. Overriding Yii's implementation with Craft specific logic.

View source

Returns

string

Signature

public string getTemplate ( )

Protected Methods

MethodDescription
afterAction()This method is invoked right after an action finishes execution.
createMigrationHistoryTable
getDbConnection
getMigrationHistory()Gets the migration history for either Craft or a plugin.
getNewMigrations()Gets any new migrations for either Craft or a plugin.
instantiateMigration
migrateDown
migrateUp
resolveRequest()Parses the command line arguments and determines which action to perform.

getMigrationHistory()

Gets the migration history for either Craft or a plugin. Overriding Yii's implementation with Craft specific logic.

View source

Arguments

  • $plugin (Craft\BasePlugin, null) – If null, will get Craft's migration history. If a plugin instance, will get the plugin's migration history.

Returns

mixed

Signature

protected mixed getMigrationHistory ( $plugin = null )

getNewMigrations()

Gets any new migrations for either Craft or a plugin. Overriding Yii's implementation with Craft specific logic.

View source

Arguments

  • $plugin (Craft\BasePlugin, null) – If null, will get any new Craft migrations. If a plugin instance, will get new plugin migrations.

Returns

array

Signature

protected array getNewMigrations ( $plugin = null )

Constants

ConstantDescription
BASE_MIGRATION