EnumMigrationHelper
class EnumMigrationHelper
Methods
Helper to migrate certain tables with "static" values (roles, media_types, ...) to enums:
- Removes all given foreign key constraints
- Changes DB values to the enum values supplied by $map
- Drops the specified table
- Removes the _id suffix from the column name
- Adds a validation constraint for each renamed column, checking that values are within enum [min, max] (only for new rows, existing rows are guaranteed to be valid, see below)
No description
No description
No description
No description
Takes a map mapping old to new values and creates a SQL expression for an atomic update.
Creates foreign keys from a list and renames existing columns by adding an _id suffix. This assumes
that the _id suffix was previously removed with replaceStaticTableWithEnum
Details
at line 37
static void
replaceStaticTableWithEnum(array $map, string $tableName, array $foreignKeys, int $validationMin, int $validationMax)
Helper to migrate certain tables with "static" values (roles, media_types, ...) to enums:
- Removes all given foreign key constraints
- Changes DB values to the enum values supplied by $map
- Drops the specified table
- Removes the _id suffix from the column name
- Adds a validation constraint for each renamed column, checking that values are within enum [min, max] (only for new rows, existing rows are guaranteed to be valid, see below)
To update all values atomically, an SQL query like this is built:
SET column_name = (CASE column_name
WHEN old1 THEN new1
WHEN old2 THEN new2
...
END) <-- part in parenthesis is built
WHERE column_name IN (old1, old2, ...);```
at line 53
static
addRangeValidationCheck(string $table, string $newColumn, int $validationMin, int $validationMax)
No description
at line 64
static string
renameEnumColumn(string $table, string $column)
No description
at line 78
static void
mapValues(array $map, string $table, string $column)
No description
at line 91
static void
assertCompleteMap(array $map, string $tableName)
No description
at line 111
static private array
buildCaseMapping(array $map)
Takes a map mapping old to new values and creates a SQL expression for an atomic update.
Returns [$cases, $ids]: $cases contains the sql query as a string, $ids contains the old values of the _id column (like role_id, ...)
at line 133
static void
createForeignKeys(array $foreignKeys, string $tableName)
Creates foreign keys from a list and renames existing columns by adding an _id suffix. This assumes
that the _id suffix was previously removed with replaceStaticTableWithEnum