Craft 3 Class Reference

Class craft\helpers\MigrationHelper

Inheritance
craft\helpers\MigrationHelper
Available since version
3.0
Source Code
https://github.com/craftcms/cms/blob/master/src/helpers/MigrationHelper.php

Migration utility methods.

Public Methods
Method Description Defined By
doesForeignKeyExist() Returns whether a foreign key exists. craft\helpers\MigrationHelper
doesIndexExist() Returns whether an index exists. craft\helpers\MigrationHelper
dropAllForeignKeysOnTable() Drops all the foreign keys on a table. craft\helpers\MigrationHelper
dropAllForeignKeysToTable() Drops all the foreign keys that reference a table. craft\helpers\MigrationHelper
dropAllIndexesOnTable() Drops all the indexes on a table. craft\helpers\MigrationHelper
dropAllUniqueIndexesOnTable() Drops all the unique indexes on a table. craft\helpers\MigrationHelper
dropForeignKey() Drops a foreign key. craft\helpers\MigrationHelper
dropForeignKeyIfExists() Drops a foreign key if it exists. craft\helpers\MigrationHelper
dropIndex() Drops an index. craft\helpers\MigrationHelper
dropIndexIfExists() Drops an index if it exists. craft\helpers\MigrationHelper
dropTable() Drops a table, its own foreign keys, and any foreign keys referencing it. craft\helpers\MigrationHelper
findForeignKeysTo() Returns a list of all the foreign keys that point to a given table/column. craft\helpers\MigrationHelper
renameColumn() Renames a column, while also updating any index and FK names that use the column. craft\helpers\MigrationHelper
renameTable() Renames a table, while also updating its sequence, index, and FK names, as well as any other FK names pointing to the table. craft\helpers\MigrationHelper
restoreForeignKey() Restores a foreign key. craft\helpers\MigrationHelper
restoreIndex() Restores an index. craft\helpers\MigrationHelper

Method Details

doesForeignKeyExist() public static method #

Returns whether a foreign key exists.

public static boolean doesForeignKeyExist ( \craft\helpers\string $tableName, $columns )
$tableName string
$columns string, string[]

doesIndexExist() public static method #

Returns whether an index exists.

public static boolean doesIndexExist ( \craft\helpers\string $tableName, $columns, \craft\helpers\bool $unique false, \craft\helpers\bool $foreignKey false )
$tableName string
$columns string, string[]
$unique boolean
$foreignKey boolean

dropAllForeignKeysOnTable() public static method #

Drops all the foreign keys on a table.

public static array dropAllForeignKeysOnTable ( \craft\helpers\string $tableName, craft\db\Migration $migration null )
$tableName string
$migration craft\db\Migration, null
return array An array of the foreign keys that were just dropped.

dropAllForeignKeysToTable() public static method #

Drops all the foreign keys that reference a table.

public static void dropAllForeignKeysToTable ( \craft\helpers\string $tableName, craft\db\Migration $migration null )
$tableName string
$migration craft\db\Migration, null

dropAllIndexesOnTable() public static method #

Drops all the indexes on a table.

public static array dropAllIndexesOnTable ( \craft\helpers\string $tableName, craft\db\Migration $migration null )
$tableName string
$migration craft\db\Migration, null
return array An array of the indexes that were just dropped.

dropAllUniqueIndexesOnTable() public static method #

Drops all the unique indexes on a table.

public static void dropAllUniqueIndexesOnTable ( \craft\helpers\string $tableName, craft\db\Migration $migration null )
$tableName string
$migration craft\db\Migration, null

dropForeignKey() public static method #

Drops a foreign key.

public static void dropForeignKey ( \craft\helpers\string $tableName, $columns, craft\db\Migration $migration null )
$tableName string
$columns string, string[]
$migration craft\db\Migration, null

dropForeignKeyIfExists() public static method #

Drops a foreign key if it exists.

public static void dropForeignKeyIfExists ( \craft\helpers\string $tableName, $columns, craft\db\Migration $migration null )
$tableName string
$columns string, string[]
$migration craft\db\Migration, null

dropIndex() public static method #

Drops an index.

public static void dropIndex ( \craft\helpers\string $tableName, $columns, \craft\helpers\bool $unique false, craft\db\Migration $migration null )
$tableName string
$columns string, string[]
$unique boolean
$migration craft\db\Migration, null

dropIndexIfExists() public static method #

Drops an index if it exists.

public static void dropIndexIfExists ( \craft\helpers\string $tableName, $columns, \craft\helpers\bool $unique false, craft\db\Migration $migration null )
$tableName string
$columns string, string[]
$unique boolean
$migration craft\db\Migration, null

dropTable() public static method #

Drops a table, its own foreign keys, and any foreign keys referencing it.

public static void dropTable ( \craft\helpers\string $tableName, craft\db\Migration $migration null )
$tableName string
$migration craft\db\Migration, null

findForeignKeysTo() public static method #

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

public static array findForeignKeysTo ( \craft\helpers\string $tableName, \craft\helpers\string $column 'id' )
$tableName string The table the foreign keys should point to.
$column string The column the foreign keys should point to. Defaults to 'id'.
return array A list of the foreign keys pointing to that table/column.

renameColumn() public static method #

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

public static void renameColumn ( \craft\helpers\string $tableName, \craft\helpers\string $oldName, \craft\helpers\string $newName, craft\db\Migration $migration null )
$tableName string
$oldName string
$newName string
$migration craft\db\Migration, null

renameTable() public static method #

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

public static void renameTable ( \craft\helpers\string $oldName, \craft\helpers\string $newName, craft\db\Migration $migration null )
$oldName string
$newName string
$migration craft\db\Migration, null

restoreForeignKey() public static method #

Restores a foreign key.

public static void restoreForeignKey ( \craft\helpers\string $tableName, $columns, \craft\helpers\string $refTable, $refColumns, \craft\helpers\string $onUpdate, \craft\helpers\string $onDelete, craft\db\Migration $migration null )
$tableName string
$columns string, string[]
$refTable string
$refColumns array
$onUpdate string
$onDelete string
$migration craft\db\Migration, null

restoreIndex() public static method #

Restores an index.

public static void restoreIndex ( \craft\helpers\string $tableName, $columns, \craft\helpers\bool $unique false, craft\db\Migration $migration null )
$tableName string
$columns string, string[]
$unique boolean
$migration craft\db\Migration, null