MigrationHelper

Type
Class
Namespace
Craft
Inherits
Craft\MigrationHelper
Since
1.1

Migration utility methods.

See also http://craftcms.com

View source

Public Methods

MethodDescription
dropAllForeignKeysOnTable()Drops all the foreign keys on a table.
dropAllIndexesOnTable()Drops all the indexes on a table.
dropAllUniqueIndexesOnTable()Drops all the unique indexes on a table.
dropForeignKey()Drops a foreign key.
dropForeignKeyIfExists()Drops a foreign key if it exists.
dropIndex()Drops an index.
dropIndexIfExists()Drops an index if it exists.
findForeignKeysTo()Returns a list of all the foreign keys that point to a given table/column.
getTable()Returns info about a given table.
getTables()Returns info about all of the tables.
makeElemental()Creates elements for all rows in a given table, swaps its 'id' PK for 'elementId', and updates the names of any FK's in other tables.
refresh()Refreshes our record of everything.
renameColumn()Renames a column, while also updating any index and FK names that use the column.
renameTable()Renames a table, while also updating its index and FK names, as well as any other FK names pointing to the table.
restoreAllForeignKeysOnTable()Restores all the foreign keys on a table.
restoreAllIndexesOnTable()Restores all the indexes on a table.
restoreAllUniqueIndexesOnTable()Restores all the unique indexes on a table.
restoreForeignKey()Restores a foreign key.
restoreIndex()Restores an index.

dropAllForeignKeysOnTable()

Drops all the foreign keys on a table.

View source

Arguments

Returns

null

Signature

public static null dropAllForeignKeysOnTable ( $table )

dropAllIndexesOnTable()

Drops all the indexes on a table.

View source

Arguments

Returns

null

Signature

public static null dropAllIndexesOnTable ( $table )

dropAllUniqueIndexesOnTable()

Drops all the unique indexes on a table.

View source

Arguments

Returns

null

Signature

public static null dropAllUniqueIndexesOnTable ( $table )

dropForeignKey()

Drops a foreign key.

View source

Arguments

Returns

null

Signature

public static null dropForeignKey ( $fk )

dropForeignKeyIfExists()

Drops a foreign key if it exists.

View source

Arguments

Returns

null

Signature

public static null dropForeignKeyIfExists ( $tableName, $columns )

dropIndex()

Drops an index.

View source

Arguments

Returns

null

Signature

public static null dropIndex ( $index )

dropIndexIfExists()

Drops an index if it exists.

View source

Arguments

Returns

false

Signature

public static false dropIndexIfExists ( $tableName, $columns, $unique = false )

findForeignKeysTo()

Returns a list of all the foreign keys that point to a given table/column.

View source

Arguments

  • $table (string) – The table the foreign keys should point to.
  • $column (string) – The column the foreign keys should point to. Defaults to 'id'.

Returns

array – A list of the foreign keys pointing to that table/column.

Signature

public static array findForeignKeysTo ( $table, $column = 'id' )

getTable()

Returns info about a given table.

View source

Arguments

Returns

object, null

Signature

public static object, null getTable ( $table )

getTables()

Returns info about all of the tables.

View source

Returns

array

Signature

public static array getTables ( )

makeElemental()

Creates elements for all rows in a given table, swaps its 'id' PK for 'elementId', and updates the names of any FK's in other tables.

View source

Arguments

  • $table (string) – The existing table name used to store records of this element.
  • $elementType (string) – The element type handle (e.g. "Entry", "Asset", etc.).
  • $hasContent (boolean) – Whether this element type has content.
  • $isLocalized (boolean) – Whether this element type stores data in multiple locales.
  • $locales (array, null) – Which locales the elements should store content in. Defaults to the primary site locale if the element type is not localized, otherwise all locales.

Returns

null

Signature

public static null makeElemental ( $table, $elementType, $hasContent = false, $isLocalized = false, $locales = null )

refresh()

Refreshes our record of everything.

View source

Returns

null

Signature

public static null refresh ( )

renameColumn()

Renames a column, while also updating any index and FK names that use the column.

View source

Arguments

Returns

null

Signature

public static null renameColumn ( $tableName, $oldName, $newName )

renameTable()

Renames a table, while also updating its index and FK names, as well as any other FK names pointing to the table.

View source

Arguments

Returns

false

Signature

public static false renameTable ( $oldName, $newName )

restoreAllForeignKeysOnTable()

Restores all the foreign keys on a table.

View source

Arguments

Returns

null

Signature

public static null restoreAllForeignKeysOnTable ( $table )

restoreAllIndexesOnTable()

Restores all the indexes on a table.

View source

Arguments

Returns

null

Signature

public static null restoreAllIndexesOnTable ( $table )

restoreAllUniqueIndexesOnTable()

Restores all the unique indexes on a table.

View source

Arguments

Returns

null

Signature

public static null restoreAllUniqueIndexesOnTable ( $table )

restoreForeignKey()

Restores a foreign key.

View source

Arguments

Returns

null

Signature

public static null restoreForeignKey ( $fk )

restoreIndex()

Restores an index.

View source

Arguments

Returns

null

Signature

public static null restoreIndex ( $index )