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