added the drop column statement for user.preferences and tested migrations

This commit is contained in:
Daniël Klabbers 2019-07-09 21:41:57 +02:00
parent caa63107ad
commit 6cfc9182f4
2 changed files with 21 additions and 22 deletions

View File

@ -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 ]);
]); }
} });
});
});
}); });
}, },

View File

@ -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();
}); });
} }