MigrationHelper
- Type
- Class
- Namespace
- craft\helpers
- Inherits
- craft\helpers\MigrationHelper
- Since
- 3.0.0
- Deprecated in
- in 4.0.0. Use [[Db]] instead.
Migration utility methods.
View source (opens new window)
# Public Methods
Method | Description |
---|---|
doesForeignKeyExist() | Returns whether a foreign key exists. |
doesIndexExist() | Returns whether an index exists. |
dropAllForeignKeysOnTable() | Drops all the foreign keys on a table. |
dropAllForeignKeysToTable() | Drops all the foreign keys that reference 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. |
dropTable() | Drops a table, its own foreign keys, and any foreign keys referencing it. |
findForeignKey() | Returns whether a foreign key exists. |
findForeignKeysTo() | Returns a list of all the foreign keys that point to a given table/column. |
renameColumn() | Renames a column, while also updating any index and FK names that use the column. |
renameTable() | Renames a table, while also updating its sequence, index, and FK names, as well as any other FK names pointing to the table. |
restoreForeignKey() | Restores a foreign key. |
restoreIndex() | Restores an index. |
# doesForeignKeyExist()
Returns whether a foreign key exists.
View source (opens new window)
Arguments
$tableName
(string (opens new window))$columns
(string (opens new window), string (opens new window)[])
Returns
# doesIndexExist()
Returns whether an index exists.
View source (opens new window)
Arguments
$tableName
(string (opens new window))$columns
(string (opens new window), string (opens new window)[])$unique
(boolean (opens new window))$db
(craft\db\Connection, null (opens new window))
Returns
# dropAllForeignKeysOnTable()
Drops all the foreign keys on a table.
View source (opens new window)
Arguments
$tableName
(string (opens new window))$migration
(craft\db\Migration, null (opens new window))
Returns
array (opens new window) – An array of the foreign keys that were just dropped.
# dropAllForeignKeysToTable()
Drops all the foreign keys that reference a table.
View source (opens new window)
Arguments
$tableName
(string (opens new window))$migration
(craft\db\Migration, null (opens new window))
# dropAllIndexesOnTable()
Drops all the indexes on a table.
View source (opens new window)
Arguments
$tableName
(string (opens new window))$migration
(craft\db\Migration, null (opens new window))
# dropAllUniqueIndexesOnTable()
Drops all the unique indexes on a table.
View source (opens new window)
Arguments
$tableName
(string (opens new window))$migration
(craft\db\Migration, null (opens new window))
# dropForeignKey()
Drops a foreign key.
View source (opens new window)
Arguments
$tableName
(string (opens new window))$columns
(string (opens new window), string (opens new window)[])$migration
(craft\db\Migration, null (opens new window))
# dropForeignKeyIfExists()
Drops a foreign key if it exists.
View source (opens new window)
Arguments
$tableName
(string (opens new window))$columns
(string (opens new window), string (opens new window)[])$migration
(craft\db\Migration, null (opens new window))
# dropIndex()
Drops an index.
View source (opens new window)
Arguments
$tableName
(string (opens new window))$columns
(string (opens new window), string (opens new window)[])$unique
(boolean (opens new window))$migration
(craft\db\Migration, null (opens new window))
# dropIndexIfExists()
Drops an index if it exists.
View source (opens new window)
Arguments
$tableName
(string (opens new window))$columns
(string (opens new window), string (opens new window)[])$unique
(boolean (opens new window))$migration
(craft\db\Migration, null (opens new window))
# dropTable()
Drops a table, its own foreign keys, and any foreign keys referencing it.
View source (opens new window)
Arguments
$tableName
(string (opens new window))$migration
(craft\db\Migration, null (opens new window))
# findForeignKey()
- Since
- 3.0.27
Returns whether a foreign key exists.
View source (opens new window)
Arguments
$tableName
(string (opens new window))$columns
(string (opens new window), string (opens new window)[])
Returns
string (opens new window), null (opens new window) – The foreign key name, or null if it doesn't exist
# findForeignKeysTo()
Returns a list of all the foreign keys that point to a given table/column.
View source (opens new window)
Arguments
$tableName
(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.
# 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))$migration
(craft\db\Migration, null (opens new window))
# renameTable()
Renames a table, while also updating its sequence, 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))$migration
(craft\db\Migration, null (opens new window))
# restoreForeignKey()
Restores a foreign key.
View source (opens new window)
Arguments
$tableName
(string (opens new window))$columns
(string (opens new window), string (opens new window)[])$refTable
(string (opens new window))$refColumns
(array (opens new window))$onUpdate
(string (opens new window))$onDelete
(string (opens new window))$migration
(craft\db\Migration, null (opens new window))
# restoreIndex()
Restores an index.
View source (opens new window)
Arguments
$tableName
(string (opens new window))$columns
(string (opens new window), string (opens new window)[])$unique
(boolean (opens new window))$migration
(craft\db\Migration, null (opens new window))