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

null (opens new window)

Signature

public null addColumn ( $table, $column, $type )

# addColumnAfter()

View source (opens new window)

Arguments

  • $table
  • $column
  • $type
  • $after

Returns

null (opens new window)

Signature

public null addColumnAfter ( $table, $column, $type, $after )

# addColumnBefore()

View source (opens new window)

Arguments

  • $table
  • $column
  • $type
  • $before

Returns

null (opens new window)

Signature

public null addColumnBefore ( $table, $column, $type, $before )

# addColumnFirst()

View source (opens new window)

Arguments

  • $table
  • $column
  • $type

Returns

null (opens new window)

Signature

public null addColumnFirst ( $table, $column, $type )

# addForeignKey()

View source (opens new window)

Arguments

Returns

null (opens new window)

Signature

public null addForeignKey ( $table, $columns, $refTable, $refColumns, $delete = null, $update = null )

# addPrimaryKey()

Signature

public null addPrimaryKey ( $table, $columns )

# alterColumn()

Signature

public null alterColumn ( $table, $column, $type, $newName = null, $after = null )

# createIndex()

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

Returns

null (opens new window)

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

null (opens new window)

Signature

public null delete ( $table, $conditions = '', $params = [] )

# 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

null (opens new window)

Signature

public null dropColumn ( $table, $column )

# dropForeignKey()

Signature

public null dropForeignKey ( $table, $columns )

# dropIndex()

Signature

public null dropIndex ( $table, $columns, $unique = false )

# dropPrimaryKey()

Signature

public null dropPrimaryKey ( $table, $columns )

# dropTable()

Builds and executes a SQL statement for dropping a DB table.

View source (opens new window)

Arguments

Returns

null (opens new window)

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

Returns

null (opens new window)

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

Returns

null (opens new window)

Signature

public null insert ( $table, $columns, $includeAuditColumns = true )

# insertAll()

View source (opens new window)

Arguments

  • $table
  • $columns
  • $vals
  • $includeAuditColumns

Returns

null (opens new window)

Signature

public null insertAll ( $table, $columns, $vals, $includeAuditColumns = true )

# insertOrUpdate()

Signature

public null insertOrUpdate ( $table, $keyColumns, $updateColumns, $includeAuditColumns = true )

# refreshTableSchema()

Refreshed schema cache for a table

View source (opens new window)

Arguments

Returns

null (opens new window)

Signature

public null refreshTableSchema ( $table )

# renameColumn()

Builds and executes a SQL statement for renaming a column.

View source (opens new window)

Arguments

Returns

null (opens new window)

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

Returns

null (opens new window)

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

Returns

null (opens new window)

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

boolean (opens new window)

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

null (opens new window)

Signature

public null update ( $table, $columns, $conditions = '', $params = [], $includeAuditColumns = true )