BaseMigration
- Type
- Abstract Class
- Namespace
- Craft
- Inherits
- Craft\BaseMigration » CDbMigration (opens new window) » CComponent (opens new window)
- Since
- 1.0
Class BaseMigration
See also http://craftcms.com
View source (opens new window)
# Public Methods
Method | Description |
---|---|
__call() (opens new window) | Calls the named method which is not a class method. |
__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. |
addColumn() | Builds and executes a SQL statement for adding a new DB column. |
addColumnAfter() | |
addColumnBefore() | |
addColumnFirst() | |
addForeignKey() | |
addPrimaryKey() | |
alterColumn() | |
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. |
canGetProperty() (opens new window) | Determines whether a property can be read. |
canSetProperty() (opens new window) | Determines whether a property can be set. |
createIndex() | |
createTable() | Builds and executes a SQL statement for creating a new DB table. |
delete() | Creates and executes a DELETE SQL statement. |
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. |
down() | |
dropColumn() | Builds and executes a SQL statement for dropping a DB column. |
dropForeignKey() | |
dropIndex() | |
dropPrimaryKey() | |
dropTable() | Builds and executes a SQL statement for dropping a DB table. |
dropTableIfExists() | |
enableBehavior() (opens new window) | Enables an attached behavior. |
enableBehaviors() (opens new window) | Enables all behaviors attached to this component. |
evaluateExpression() (opens new window) | Evaluates a PHP expression or callback under the context of this component. |
execute() | Executes a SQL statement. This method executes the specified SQL statement using {@link dbConnection}. |
getDbConnection() (opens new window) | Returns the currently active database connection. |
getEventHandlers() (opens new window) | Returns the list of attached event handlers for an event. |
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. |
insert() | Creates and executes an INSERT SQL statement. The method will properly escape the column names, and bind the values to be inserted. |
insertAll() | |
insertMultiple() (opens new window) | Creates and executes an INSERT SQL statement with multiple data. |
insertOrUpdate() | |
raiseEvent() (opens new window) | Raises an event. |
refreshTableSchema() | Refreshed schema cache for a table |
renameColumn() | Builds and executes a SQL statement for renaming a column. |
renameTable() | Builds and executes a SQL statement for renaming a DB table. |
safeDown() | |
safeUp() (opens new window) | This method contains the logic to be executed when applying this migration. |
setDbConnection() (opens new window) | Sets the currently active database connection. |
truncateTable() | Builds and executes a SQL statement for truncating a DB table. |
up() | This method contains the logic to be executed when applying this migration. Child classes may implement this method to provide actual migration logic. |
update() | Creates and executes an UPDATE SQL statement. The method will properly escape the column names and bind the values to be updated. |
# addColumn()
Builds and executes a SQL statement for adding a new DB column.
View source (opens new window)
Arguments
$table
(string (opens new window)) – The table that the new column will be added to. The table name will be properly quoted by the method.$column
(string (opens new window)) – The name of the new column. The name will be properly quoted by the method.$type
(string (opens new window)) – The column type. The {@link getColumnType} method will be invoked to convert abstract column type (if any) into the physical one. Anything that is not recognized as abstract type will be kept in the generated SQL. For example, 'string' will be turned into 'varchar(255)', while 'string not null' will become 'varchar(255) not null'.
Returns
Signature
public null addColumn ( $table, $column, $type )
# addColumnAfter()
Signature
public null addColumnAfter ( $table, $column, $type, $after )
# addColumnBefore()
Signature
public null addColumnBefore ( $table, $column, $type, $before )
# addColumnFirst()
Signature
public null addColumnFirst ( $table, $column, $type )
# addForeignKey()
View source (opens new window)
Arguments
$table
$columns
$refTable
$refColumns
$delete
(null (opens new window))$update
(null (opens new window))
Returns
Signature
public null addForeignKey ( $table, $columns, $refTable, $refColumns, $delete = null, $update = null )
# addPrimaryKey()
View source (opens new window)
Arguments
$table
(string (opens new window))$columns
(string (opens new window))
Returns
Signature
public null addPrimaryKey ( $table, $columns )
# alterColumn()
View source (opens new window)
Arguments
$table
$column
$type
$newName
(null (opens new window))$after
(null (opens new window))
Returns
Signature
public null alterColumn ( $table, $column, $type, $newName = null, $after = null )
# createIndex()
View source (opens new window)
Arguments
$table
$columns
$unique
(boolean (opens new window))
Returns
Signature
public null createIndex ( $table, $columns, $unique = false )
# createTable()
Builds and executes a SQL statement for creating a new DB table. The columns in the new table should be specified as name-definition pairs (e.g. 'name'=>'string'), where name stands for a column name which will be properly quoted by the method, and definition stands for the column type which can contain an abstract DB type. The {@link getColumnType} method will be invoked to convert any abstract type into a physical one.
If a column is specified with definition only (e.g. 'PRIMARY KEY (name, type)'), it will be directly inserted into the generated SQL.
View source (opens new window)
Arguments
$table
(string (opens new window)) – The name of the table to be created. The name will be properly quoted by the method.$columns
(array (opens new window)) – The columns (name=>definition) in the new table.$options
(string (opens new window)) – Additional SQL fragment that will be appended to the generated SQL.$addIdColumn
(boolean (opens new window)) – Whether to add an auto-incrementing primary key id column to the table.$addAuditColumns
(boolean (opens new window)) – Whether to append auditing columns to the end of the table (dateCreated, dateUpdated, uid)
Returns
Signature
public null createTable ( $table, $columns, $options = null, $addIdColumn = true, $addAuditColumns = true )
# delete()
Creates and executes a DELETE SQL statement.
View source (opens new window)
Arguments
$table
(string (opens new window)) – The table where the data will be deleted from.$conditions
(mixed
) – The conditions that will be put in the WHERE part. Please refer to {@link \CDbCommand::where} on how to specify conditions.$params
(array (opens new window)) – The parameters to be bound to the query.
Returns
Signature
public null delete ( $table, $conditions = '', $params = [] )
# down()
Signature
public boolean, null down ( )
# dropColumn()
Builds and executes a SQL statement for dropping a DB column.
View source (opens new window)
Arguments
$table
(string (opens new window)) – The table whose column is to be dropped. The name will be properly quoted by the method.$column
(string (opens new window)) – The name of the column to be dropped. The name will be properly quoted by the method.
Returns
Signature
public null dropColumn ( $table, $column )
# dropForeignKey()
View source (opens new window)
Arguments
$table
(string (opens new window))$columns
(string (opens new window))
Returns
Signature
public null dropForeignKey ( $table, $columns )
# dropIndex()
View source (opens new window)
Arguments
$table
(string (opens new window))$columns
(string (opens new window))$unique
(boolean (opens new window))
Returns
Signature
public null dropIndex ( $table, $columns, $unique = false )
# dropPrimaryKey()
View source (opens new window)
Arguments
$table
(string (opens new window))$columns
(string (opens new window))
Returns
Signature
public null dropPrimaryKey ( $table, $columns )
# dropTable()
Builds and executes a SQL statement for dropping a DB table.
View source (opens new window)
Arguments
$table
(string (opens new window)) – The table to be dropped. The name will be properly quoted by the method.
Returns
Signature
public null dropTable ( $table )
# dropTableIfExists()
Signature
public null dropTableIfExists ( $table )
# execute()
Executes a SQL statement. This method executes the specified SQL statement using {@link dbConnection}.
View source (opens new window)
Arguments
$sql
(string (opens new window)) – The SQL statement to be executed.$params
(array (opens new window)) – Input parameters (name=>value) for the SQL execution. See {@link \CDbCommand::execute} for more details.
Returns
Signature
public null execute ( $sql, $params = [] )
# insert()
Creates and executes an INSERT SQL statement. The method will properly escape the column names, and bind the values to be inserted.
View source (opens new window)
Arguments
$table
(string (opens new window)) – The table that new rows will be inserted into.$columns
(array (opens new window)) – The column data (name=>value) to be inserted into the table.$includeAuditColumns
(boolean (opens new window)) – Whether to include the data for the audit columns (dateCreated, dateUpdated, uid).
Returns
Signature
public null insert ( $table, $columns, $includeAuditColumns = true )
# insertAll()
Signature
public null insertAll ( $table, $columns, $vals, $includeAuditColumns = true )
# insertOrUpdate()
View source (opens new window)
Arguments
$table
(string (opens new window))$keyColumns
(array (opens new window))$updateColumns
(array (opens new window))$includeAuditColumns
(boolean (opens new window))
Returns
Signature
public null insertOrUpdate ( $table, $keyColumns, $updateColumns, $includeAuditColumns = true )
# refreshTableSchema()
Refreshed schema cache for a table
View source (opens new window)
Arguments
$table
(string (opens new window)) – The name of the table to refresh
Returns
Signature
public null refreshTableSchema ( $table )
# renameColumn()
Builds and executes a SQL statement for renaming a column.
View source (opens new window)
Arguments
$table
(string (opens new window)) – The table whose column is to be renamed. The name will be properly quoted by the method.$name
(string (opens new window)) – The old name of the column. The name will be properly quoted by the method.$newName
(string (opens new window)) – The new name of the column. The name will be properly quoted by the method.
Returns
Signature
public null renameColumn ( $table, $name, $newName )
# renameTable()
Builds and executes a SQL statement for renaming a DB table.
View source (opens new window)
Arguments
$table
(string (opens new window)) – The table to be renamed. The name will be properly quoted by the method.$newName
(string (opens new window)) – The new table name. The name will be properly quoted by the method.
Returns
Signature
public null renameTable ( $table, $newName )
# safeDown()
Signature
public boolean, null safeDown ( )
# truncateTable()
Builds and executes a SQL statement for truncating a DB table.
View source (opens new window)
Arguments
$table
(string (opens new window)) – The table to be truncated. The name will be properly quoted by the method.
Returns
Signature
public null truncateTable ( $table )
# up()
This method contains the logic to be executed when applying this migration. Child classes may implement this method to provide actual migration logic.
View source (opens new window)
Returns
Signature
public boolean up ( )
# update()
Creates and executes an UPDATE SQL statement. The method will properly escape the column names and bind the values to be updated.
View source (opens new window)
Arguments
$table
(string (opens new window)) – The table to be updated.$columns
(array (opens new window)) – The column data (name=>value) to be updated.$conditions
(mixed
) – The conditions that will be put in the WHERE part. Please refer to {@link \CDbCommand::where} on how to specify conditions.$params
(array (opens new window)) – The parameters to be bound to the query.$includeAuditColumns
(boolean (opens new window)) – Whether to include the data for the audit columns (dateCreated, dateUpdated, uid).
Returns
Signature
public null update ( $table, $columns, $conditions = '', $params = [], $includeAuditColumns = true )