mirror of
https://github.com/flarum/framework.git
synced 2024-12-03 07:33:36 +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->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 ($value, $key) use ($user, $db) {
|
||||
if ($key === 'discloses_online') {
|
||||
$db->table('users')
|
||||
->where('id', $user['id'])
|
||||
->update(['discloses_online' => (bool) $value]);
|
||||
}
|
||||
if (preg_match('/^notify_(?<type>[^_]+)_(?<channel>.*)$/', $key, $matches)) {
|
||||
$db->table('notification_preferences')
|
||||
->insert([
|
||||
'user_id' => $user['id'],
|
||||
'type' => $matches['type'],
|
||||
'channel' => $matches['channel'],
|
||||
'enabled' => (bool) $value
|
||||
]);
|
||||
}
|
||||
});
|
||||
});
|
||||
->each(function ($user) use ($db) {
|
||||
collect(json_decode($user->preferences ?? '{}'))
|
||||
->each(function ($value, $key) use ($user, $db) {
|
||||
if ($key === 'discloseOnline') {
|
||||
$db->table('users')
|
||||
->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,
|
||||
'type' => $matches['type'],
|
||||
'channel' => $matches['channel'],
|
||||
'enabled' => (bool) $value
|
||||
]);
|
||||
}
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
|
|
|
@ -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