diff --git a/migrations/2020_08_25_000000_update_tag_permission_names.php b/migrations/2020_08_25_000000_update_tag_permission_names.php new file mode 100644 index 0000000..e0cbffc --- /dev/null +++ b/migrations/2020_08_25_000000_update_tag_permission_names.php @@ -0,0 +1,49 @@ + function (Builder $schema) { + Permission::query() + ->where('permission', 'like', '%.discussion.vote') + ->orderBy('permission') + ->each(function (Permission $item) use ($schema) { + $schema->getConnection()->transaction(function () use ($item) { + $item->delete(); + + $item->permission = $item->permission . 'Posts'; + + if (!Permission::query()->where($item->getAttributes())->exists()) { + $item->save(); + } + }); + }); + }, + 'down' => function (Builder $schema) { + Permission::query() + ->where('permission', 'like', '%.discussion.votePosts') + ->orderBy('permission') + ->each(function (Permission $item) use ($schema) { + $schema->getConnection()->transaction(function () use ($item) { + $item->delete(); + + $item->permission = Str::replaceLast('votePosts', 'vote', $item->permission); + + if (!Permission::query()->where($item->getAttributes())->exists()) { + $item->save(); + } + }); + }); + }, +];