MigrationHelper
- Type
- Class
- Namespace
- Craft
- Inherits
- Craft\MigrationHelper
- Since
- 1.1
Migration utility methods.
See also http://craftcms.com
View source (opens new window)
# Public Methods
Method | Description |
---|---|
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 (opens new window)
Arguments
$table
(object (opens new window))
Returns
Signature
public static null dropAllForeignKeysOnTable ( $table )
# dropAllIndexesOnTable()
Drops all the indexes on a table.
View source (opens new window)
Arguments
$table
(object (opens new window))
Returns
Signature
public static null dropAllIndexesOnTable ( $table )
# dropAllUniqueIndexesOnTable()
Drops all the unique indexes on a table.
View source (opens new window)
Arguments
$table
(object (opens new window))
Returns
Signature
public static null dropAllUniqueIndexesOnTable ( $table )
# dropForeignKey()
Signature
public static null dropForeignKey ( $fk )
# dropForeignKeyIfExists()
Drops a foreign key if it exists.
View source (opens new window)
Arguments
$tableName
(string (opens new window))$columns
(array (opens new window))
Returns
Signature
public static null dropForeignKeyIfExists ( $tableName, $columns )
# dropIndex()
Signature
public static null dropIndex ( $index )
# dropIndexIfExists()
Drops an index if it exists.
View source (opens new window)
Arguments
$tableName
(string (opens new window))$columns
(array (opens new window))$unique
(boolean (opens new window))
Returns
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 (opens new window)
Arguments
$table
(string (opens new window)) – The table the foreign keys should point to.$column
(string (opens new window)) – The column the foreign keys should point to. Defaults to 'id'.
Returns
array (opens new window) – 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 (opens new window)
Arguments
$table
(string (opens new window))
Returns
Signature
public static object, null getTable ( $table )
# getTables()
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 (opens new window)
Arguments
$table
(string (opens new window)) – The existing table name used to store records of this element.$elementType
(string (opens new window)) – The element type handle (e.g. "Entry", "Asset", etc.).$hasContent
(boolean (opens new window)) – Whether this element type has content.$isLocalized
(boolean (opens new window)) – Whether this element type stores data in multiple locales.$locales
(array (opens new window), null (opens new window)) – 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
Signature
public static null makeElemental ( $table, $elementType, $hasContent = false, $isLocalized = false, $locales = null )
# refresh()
Signature
public static null refresh ( )
# renameColumn()
Renames a column, while also updating any index and FK names that use the column.
View source (opens new window)
Arguments
$tableName
(string (opens new window))$oldName
(string (opens new window))$newName
(string (opens new window))
Returns
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 (opens new window)
Arguments
$oldName
(string (opens new window))$newName
(string (opens new window))
Returns
Signature
public static false renameTable ( $oldName, $newName )
# restoreAllForeignKeysOnTable()
Restores all the foreign keys on a table.
View source (opens new window)
Arguments
$table
(object (opens new window))
Returns
Signature
public static null restoreAllForeignKeysOnTable ( $table )
# restoreAllIndexesOnTable()
Restores all the indexes on a table.
View source (opens new window)
Arguments
$table
(object (opens new window))
Returns
Signature
public static null restoreAllIndexesOnTable ( $table )
# restoreAllUniqueIndexesOnTable()
Restores all the unique indexes on a table.
View source (opens new window)
Arguments
$table
(object (opens new window))
Returns
Signature
public static null restoreAllUniqueIndexesOnTable ( $table )
# restoreForeignKey()
Signature
public static null restoreForeignKey ( $fk )
# restoreIndex()
Restores an index.
View source (opens new window)
Arguments
$index
(object (opens new window))
Returns
Signature
public static null restoreIndex ( $index )