BaseMigration

Type
Abstract Class
Namespace
Craft
Inherits
Craft\BaseMigration » CDbMigration » CComponent
Since
1.0

Class BaseMigration

See also http://craftcms.com

View source

Public Methods

MethodDescription
__call()Calls the named method which is not a class method.
__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.
addColumn()Builds and executes a SQL statement for adding a new DB column.
addColumnAfter()
addColumnBefore()
addColumnFirst()
addForeignKey()
addPrimaryKey()
alterColumn()
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.
canGetProperty()Determines whether a property can be read.
canSetProperty()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()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.
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()Enables an attached behavior.
enableBehaviors()Enables all behaviors attached to this component.
evaluateExpression()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()Returns the currently active database connection.
getEventHandlers()Returns the list of attached event handlers for an event.
hasEvent()Determines whether an event is defined.
hasEventHandler()Checks whether the named event has attached handlers.
hasProperty()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()Creates and executes an INSERT SQL statement with multiple data.
insertOrUpdate()
raiseEvent()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()This method contains the logic to be executed when applying this migration.
setDbConnection()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

Arguments

  • $table (string) – The table that the new column will be added to. The table name will be properly quoted by the method.
  • $column (string) – The name of the new column. The name will be properly quoted by the method.
  • $type (string) – 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

Signature

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

addColumnAfter()

View source

Arguments

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

Returns

null

Signature

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

addColumnBefore()

View source

Arguments

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

Returns

null

Signature

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

addColumnFirst()

View source

Arguments

  • $table
  • $column
  • $type

Returns

null

Signature

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

addForeignKey()

View source

Arguments

  • $table
  • $columns
  • $refTable
  • $refColumns
  • $delete (null)
  • $update (null)

Returns

null

Signature

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

addPrimaryKey()

View source

Arguments

Returns

null

Signature

public null addPrimaryKey ( $table, $columns )

alterColumn()

View source

Arguments

  • $table
  • $column
  • $type
  • $newName (null)
  • $after (null)

Returns

null

Signature

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

createIndex()

View source

Arguments

Returns

null

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

Arguments

  • $table (string) – The name of the table to be created. The name will be properly quoted by the method.
  • $columns (array) – The columns (name=>definition) in the new table.
  • $options (string) – Additional SQL fragment that will be appended to the generated SQL.
  • $addIdColumn (boolean) – Whether to add an auto-incrementing primary key id column to the table.
  • $addAuditColumns (boolean) – Whether to append auditing columns to the end of the table (dateCreated, dateUpdated, uid)

Returns

null

Signature

public null createTable ( $table, $columns, $options = null, $addIdColumn = true, $addAuditColumns = true )

delete()

Creates and executes a DELETE SQL statement.

View source

Arguments

  • $table (string) – 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) – The parameters to be bound to the query.

Returns

null

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

Arguments

  • $table (string) – The table whose column is to be dropped. The name will be properly quoted by the method.
  • $column (string) – The name of the column to be dropped. The name will be properly quoted by the method.

Returns

null

Signature

public null dropColumn ( $table, $column )

dropForeignKey()

View source

Arguments

Returns

null

Signature

public null dropForeignKey ( $table, $columns )

dropIndex()

View source

Arguments

Returns

null

Signature

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

dropPrimaryKey()

View source

Arguments

Returns

null

Signature

public null dropPrimaryKey ( $table, $columns )

dropTable()

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

View source

Arguments

  • $table (string) – The table to be dropped. The name will be properly quoted by the method.

Returns

null

Signature

public null dropTable ( $table )

dropTableIfExists()

View source

Arguments

  • $table

Returns

null

Signature

public null dropTableIfExists ( $table )

execute()

Executes a SQL statement. This method executes the specified SQL statement using {@link dbConnection}.

View source

Arguments

  • $sql (string) – The SQL statement to be executed.
  • $params (array) – Input parameters (name=>value) for the SQL execution. See {@link \CDbCommand::execute} for more details.

Returns

null

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

Arguments

  • $table (string) – The table that new rows will be inserted into.
  • $columns (array) – The column data (name=>value) to be inserted into the table.
  • $includeAuditColumns (boolean) – Whether to include the data for the audit columns (dateCreated, dateUpdated, uid).

Returns

null

Signature

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

insertAll()

View source

Arguments

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

Returns

null

Signature

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

insertOrUpdate()

View source

Arguments

Returns

null

Signature

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

refreshTableSchema()

Refreshed schema cache for a table

View source

Arguments

  • $table (string) – The name of the table to refresh

Returns

null

Signature

public null refreshTableSchema ( $table )

renameColumn()

Builds and executes a SQL statement for renaming a column.

View source

Arguments

  • $table (string) – The table whose column is to be renamed. The name will be properly quoted by the method.
  • $name (string) – The old name of the column. The name will be properly quoted by the method.
  • $newName (string) – The new name of the column. The name will be properly quoted by the method.

Returns

null

Signature

public null renameColumn ( $table, $name, $newName )

renameTable()

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

View source

Arguments

  • $table (string) – The table to be renamed. The name will be properly quoted by the method.
  • $newName (string) – The new table name. The name will be properly quoted by the method.

Returns

null

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

Arguments

  • $table (string) – The table to be truncated. The name will be properly quoted by the method.

Returns

null

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

Returns

boolean

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

Arguments

  • $table (string) – The table to be updated.
  • $columns (array) – 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) – The parameters to be bound to the query.
  • $includeAuditColumns (boolean) – Whether to include the data for the audit columns (dateCreated, dateUpdated, uid).

Returns

null

Signature

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