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,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) {

View File

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