MigrationHelper

Type
Class
Namespace
craft\helpers
Inherits
craft\helpers\MigrationHelper
Since
3.0

Migration utility methods.

View source

Public Methods

MethodDescription
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

Arguments

Returns

boolean

Signature

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

doesIndexExist()

Returns whether an index exists.

View source

Arguments

Returns

boolean

Signature

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

dropAllForeignKeysOnTable()

Drops all the foreign keys on a table.

View source

Arguments

Returns

array – An array of the foreign keys that were just dropped.

Signature

public static array dropAllForeignKeysOnTable ( \craft\helpers\string $tableName, craft\db\Migration $migration = null )

dropAllForeignKeysToTable()

Drops all the foreign keys that reference a table.

View source

Arguments

Signature

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

dropAllIndexesOnTable()

Drops all the indexes on a table.

View source

Arguments

Returns

array – An array of the indexes that were just dropped.

Signature

public static array dropAllIndexesOnTable ( \craft\helpers\string $tableName, craft\db\Migration $migration = null )

dropAllUniqueIndexesOnTable()

Drops all the unique indexes on a table.

View source

Arguments

Signature

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

dropForeignKey()

Drops a foreign key.

View source

Arguments

Signature

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

dropForeignKeyIfExists()

Drops a foreign key if it exists.

View source

Arguments

Signature

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

dropIndex()

Drops an index.

View source

Arguments

Signature

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

dropIndexIfExists()

Drops an index if it exists.

View source

Arguments

Signature

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

dropTable()

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

View source

Arguments

Signature

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

findForeignKey()

Returns whether a foreign key exists.

View source

Arguments

Returns

string, null – The foreign key name, or null if it doesn't exist

Signature

public static string, null findForeignKey ( \craft\helpers\string $tableName, $columns )

findForeignKeysTo()

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

View source

Arguments

  • $tableName (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 ( \craft\helpers\string $tableName, \craft\helpers\string $column = 'id' )

renameColumn()

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

View source

Arguments

Signature

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

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

Arguments

Signature

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

restoreForeignKey()

Restores a foreign key.

View source

Arguments

Signature

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 )

restoreIndex()

Restores an index.

View source

Arguments

Signature

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