MigrateCommand
- Type
- Class
- Namespace
- Craft
- Inherits
- Craft\MigrateCommand »
MigrateCommand
» CConsoleCommand (opens new window) » CComponent (opens new window) - 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 success1
on general error2
on failed migration.
See also http://craftcms.com
View source (opens new window)
# Public Properties
Property | Description |
---|---|
$connectionID | string (opens new window) – The application component ID that specifies the database connection for storing migration information. |
$defaultAction | string (opens new window) – The default command action. |
$interactive | boolean (opens new window) – Whether to execute the migration in an interactive mode. |
$migrationPath | string (opens new window) – The directory that stores the migrations. |
$migrationTable | string (opens new window) – The name of the table for keeping applied migration information. |
$templateFile | string (opens new window) – The path of the template file for generating new migrations. |
# Public Methods
Method | Description |
---|---|
__call() (opens new window) | Calls the named method which is not a class method. |
__construct() (opens new window) | Constructor. |
__get() (opens new window) | Returns a property value, an event handler list or a behavior based on its name. |
__isset() (opens new window) | Checks if a property value is null. |
__set() (opens new window) | Sets value of a component property. |
__unset() (opens new window) | 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() (opens new window) | Returns the named behavior object. |
attachBehavior() (opens new window) | Attaches a behavior to this component. |
attachBehaviors() (opens new window) | Attaches a list of behaviors to the component. |
attachEventHandler() (opens new window) | Attaches an event handler to an event. |
beforeAction() | Used for ensuring a plugin's migration exists if the action is "create". |
behaviors() (opens new window) | Returns a list of behaviors that this command should behave as. |
buildFileList() (opens new window) | Builds the file list of a directory. |
canGetProperty() (opens new window) | Determines whether a property can be read. |
canSetProperty() (opens new window) | Determines whether a property can be set. |
confirm | |
copyFiles() (opens new window) | Copies a list of files from one place to another. |
detachBehavior() (opens new window) | Detaches a behavior from the component. |
detachBehaviors() (opens new window) | Detaches all behaviors from the component. |
detachEventHandler() (opens new window) | Detaches an existing event handler. |
disableBehavior() (opens new window) | Disables an attached behavior. |
disableBehaviors() (opens new window) | Disables all behaviors attached to this component. |
enableBehavior() (opens new window) | Enables an attached behavior. |
enableBehaviors() (opens new window) | Enables all behaviors attached to this component. |
ensureDirectory() (opens new window) | Creates all parent directories if they do not exist. |
evaluateExpression() (opens new window) | Evaluates a PHP expression or callback under the context of this component. |
getCommandRunner() (opens new window) | |
getEventHandlers() (opens new window) | Returns the list of attached event handlers for an event. |
getHelp | |
getName() (opens new window) | |
getOptionHelp() (opens new window) | Provides the command option help information. |
getTemplate() | Gets the migration template used for generating new migrations. |
hasEvent() (opens new window) | Determines whether an event is defined. |
hasEventHandler() (opens new window) | Checks whether the named event has attached handlers. |
hasProperty() (opens new window) | Determines whether a property is defined. |
init() (opens new window) | Initializes the command object. |
onAfterAction() (opens new window) | This event is raised after an action finishes execution. |
onBeforeAction() (opens new window) | This event is raised before an action is to be executed. |
pluralize() (opens new window) | Converts a word to its plural form. |
prompt() (opens new window) | Reads input via the readline PHP extension if that's available, or fgets() if readline is not installed. |
raiseEvent() (opens new window) | Raises an event. |
renderFile() (opens new window) | Renders a view file. |
run() (opens new window) | Executes the command. |
usageError() (opens new window) | 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 (opens new window)
Arguments
$args
(array (opens new window)) – The arguments passed in.
Returns
Signature
public integer actionCreate ( $args )
# actionDown()
Used for stopping "down" actions from occurring.
View source (opens new window)
Arguments
$args
(array (opens new window)) – The arguments for the action.
Returns
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 (opens new window)
Arguments
$args
(array (opens new window)) – The arguments passed in.
Returns
Signature
public integer actionHistory ( $args )
# actionMark()
Used for stopping "Mark" actions from occurring.
View source (opens new window)
Arguments
$args
(array (opens new window))
Returns
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 (opens new window)
Arguments
$args
(array (opens new window)) – The arguments passed in.
Returns
Signature
public integer actionNew ( $args )
# actionRedo()
Used for stopping "redo" actions from occurring.
View source (opens new window)
Arguments
$args
(array (opens new window))
Returns
Signature
public null actionRedo ( $args )
# actionTo()
Used for stopping "To" actions from occurring.
View source (opens new window)
Arguments
$args
(array (opens new window))
Returns
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 (opens new window)
Arguments
$args
(array (opens new window)) – The arguments passed in.
Returns
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 (opens new window)
Arguments
$action
(string (opens new window)) – The name of the action to run.$params
(array (opens new window)) – The parameters to be passed to the action's method.
Returns
boolean (opens new window) – 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 (opens new window)
Returns
Signature
public string getTemplate ( )
# Protected Methods
Method | Description |
---|---|
afterAction() (opens new window) | 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() (opens new window) | 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 (opens new window)
Arguments
$plugin
(Craft\BasePlugin, null (opens new window)) – 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 (opens new window)
Arguments
$plugin
(Craft\BasePlugin, null (opens new window)) – If null, will get any new Craft migrations. If a plugin instance, will get new plugin migrations.
Returns
Signature
protected array getNewMigrations ( $plugin = null )
# Constants
Constant | Description |
---|---|
BASE_MIGRATION |