Migrations: always pass a schema builder

This removes the funky auto-injection capability from migration
closures. While technically removing a feature, this means we do
not need a fully-wired IoC container e.g. during installation.

Instead, all migration closures simply receive a schema builder
object (which is what most of them were already doing anyway).
This commit is contained in:
Franz Liedke 2018-04-24 23:48:37 +02:00
parent 3ec32f8430
commit a1c3da9f8f
No known key found for this signature in database
GPG Key ID: 9A0231A879B055F4

View File

@ -11,8 +11,7 @@
namespace Flarum\Database;
use Flarum\Settings\SettingsRepositoryInterface;
use Illuminate\Database\ConnectionInterface;
use Flarum\Settings\DatabaseSettingsRepository;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Schema\Builder;
@ -100,12 +99,20 @@ abstract class Migration
public static function addSettings(array $defaults)
{
return [
'up' => function (SettingsRepositoryInterface $settings) use ($defaults) {
'up' => function (Builder $schema) use ($defaults) {
$settings = new DatabaseSettingsRepository(
$schema->getConnection()
);
foreach ($defaults as $key => $value) {
$settings->set($key, $value);
}
},
'down' => function (SettingsRepositoryInterface $settings) use ($defaults) {
'down' => function (Builder $schema) use ($defaults) {
$settings = new DatabaseSettingsRepository(
$schema->getConnection()
);
foreach (array_keys($defaults) as $key) {
$settings->delete($key);
}
@ -130,7 +137,9 @@ abstract class Migration
}
return [
'up' => function (ConnectionInterface $db) use ($keys) {
'up' => function (Builder $schema) use ($keys) {
$db = $schema->getConnection();
foreach ($keys as $key) {
$instance = $db->table('permissions')->where($key)->first();
@ -140,7 +149,9 @@ abstract class Migration
}
},
'down' => function (ConnectionInterface $db) use ($keys) {
'down' => function (Builder $schema) use ($keys) {
$db = $schema->getConnection();
foreach ($keys as $key) {
$db->table('permissions')->where($key)->delete();
}