mirror of
https://github.com/flarum/core.git
synced 2025-08-16 13:24:11 +02:00
Clean up migrations
* Make filenames and order more consistent * Split foreign keys into their own migrations, add statements to ensure data integrity prior to adding them * Add renameColumns helper, use other helpers where possible
This commit is contained in:
@@ -78,16 +78,28 @@ abstract class Migration
|
||||
* Rename a column.
|
||||
*/
|
||||
public static function renameColumn($tableName, $from, $to)
|
||||
{
|
||||
return static::renameColumns($tableName, [$from => $to]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Rename multiple columns.
|
||||
*/
|
||||
public static function renameColumns($tableName, array $columnNames)
|
||||
{
|
||||
return [
|
||||
'up' => function (Builder $schema) use ($tableName, $from, $to) {
|
||||
$schema->table($tableName, function (Blueprint $table) use ($from, $to) {
|
||||
$table->renameColumn($from, $to);
|
||||
'up' => function (Builder $schema) use ($tableName, $columnNames) {
|
||||
$schema->table($tableName, function (Blueprint $table) use ($columnNames) {
|
||||
foreach ($columnNames as $from => $to) {
|
||||
$table->renameColumn($from, $to);
|
||||
}
|
||||
});
|
||||
},
|
||||
'down' => function (Builder $schema) use ($tableName, $from, $to) {
|
||||
$schema->table($tableName, function (Blueprint $table) use ($from, $to) {
|
||||
$table->renameColumn($to, $from);
|
||||
'down' => function (Builder $schema) use ($tableName, $columnNames) {
|
||||
$schema->table($tableName, function (Blueprint $table) use ($columnNames) {
|
||||
foreach ($columnNames as $to => $from) {
|
||||
$table->renameColumn($from, $to);
|
||||
}
|
||||
});
|
||||
}
|
||||
];
|
||||
|
Reference in New Issue
Block a user