1
0
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:
Toby Zerner
2018-07-21 15:23:37 +09:30
parent c7efbba0da
commit fe73cf3237
32 changed files with 412 additions and 295 deletions

View File

@@ -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);
}
});
}
];