mirror of
https://github.com/flarum/framework.git
synced 2025-02-09 08:32:01 +08:00
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:
parent
ab5c4b7fea
commit
1c28afce69
|
@ -11,8 +11,7 @@
|
||||||
|
|
||||||
namespace Flarum\Database;
|
namespace Flarum\Database;
|
||||||
|
|
||||||
use Flarum\Settings\SettingsRepositoryInterface;
|
use Flarum\Settings\DatabaseSettingsRepository;
|
||||||
use Illuminate\Database\ConnectionInterface;
|
|
||||||
use Illuminate\Database\Schema\Blueprint;
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
use Illuminate\Database\Schema\Builder;
|
use Illuminate\Database\Schema\Builder;
|
||||||
|
|
||||||
|
@ -100,12 +99,20 @@ abstract class Migration
|
||||||
public static function addSettings(array $defaults)
|
public static function addSettings(array $defaults)
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'up' => function (SettingsRepositoryInterface $settings) use ($defaults) {
|
'up' => function (Builder $schema) use ($defaults) {
|
||||||
|
$settings = new DatabaseSettingsRepository(
|
||||||
|
$schema->getConnection()
|
||||||
|
);
|
||||||
|
|
||||||
foreach ($defaults as $key => $value) {
|
foreach ($defaults as $key => $value) {
|
||||||
$settings->set($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) {
|
foreach (array_keys($defaults) as $key) {
|
||||||
$settings->delete($key);
|
$settings->delete($key);
|
||||||
}
|
}
|
||||||
|
@ -130,7 +137,9 @@ abstract class Migration
|
||||||
}
|
}
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'up' => function (ConnectionInterface $db) use ($keys) {
|
'up' => function (Builder $schema) use ($keys) {
|
||||||
|
$db = $schema->getConnection();
|
||||||
|
|
||||||
foreach ($keys as $key) {
|
foreach ($keys as $key) {
|
||||||
$instance = $db->table('permissions')->where($key)->first();
|
$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) {
|
foreach ($keys as $key) {
|
||||||
$db->table('permissions')->where($key)->delete();
|
$db->table('permissions')->where($key)->delete();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user