mirror of
https://github.com/flarum/framework.git
synced 2024-12-11 13:05:50 +08:00
added the drop column statement for user.preferences and tested migrations
This commit is contained in:
parent
caa63107ad
commit
6cfc9182f4
|
@ -18,21 +18,21 @@ return [
|
|||
$db = $builder->getConnection();
|
||||
|
||||
$db->table('users')
|
||||
->select(['id', 'preferences'])
|
||||
->whereNotNull('preferences')
|
||||
->orderBy('id')
|
||||
->chunk(50, function (Collection $users) use ($db) {
|
||||
$users->each(function ($user) use ($db) {
|
||||
collect(json_decode(Arr::get($user, 'preferences', '{}')))
|
||||
->each(function ($user) use ($db) {
|
||||
collect(json_decode($user->preferences ?? '{}'))
|
||||
->each(function ($value, $key) use ($user, $db) {
|
||||
if ($key === 'discloses_online') {
|
||||
if ($key === 'discloseOnline') {
|
||||
$db->table('users')
|
||||
->where('id', $user['id'])
|
||||
->update(['discloses_online' => (bool) $value]);
|
||||
->where('id', $user->id)
|
||||
->update(['disclose_online' => (bool) $value]);
|
||||
}
|
||||
if (preg_match('/^notify_(?<type>[^_]+)_(?<channel>.*)$/', $key, $matches)) {
|
||||
$db->table('notification_preferences')
|
||||
->insert([
|
||||
'user_id' => $user['id'],
|
||||
'user_id' => $user->id,
|
||||
'type' => $matches['type'],
|
||||
'channel' => $matches['channel'],
|
||||
'enabled' => (bool) $value
|
||||
|
@ -40,7 +40,6 @@ return [
|
|||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
'down' => function (Builder $builder) {
|
||||
|
|
|
@ -14,13 +14,13 @@ use Illuminate\Database\Schema\Builder;
|
|||
|
||||
return [
|
||||
'up' => function (Builder $schema) {
|
||||
$schema->table('posts', function (Blueprint $table) {
|
||||
$schema->table('users', function (Blueprint $table) {
|
||||
$table->dropColumn('preferences');
|
||||
});
|
||||
},
|
||||
|
||||
'down' => function (Builder $schema) {
|
||||
$schema->table('posts', function (Blueprint $table) {
|
||||
$schema->table('users', function (Blueprint $table) {
|
||||
$table->binary('preferences')->nullable();
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user