spatie/laravel-permission

Problem upgrading with existing data permissions/roles

mplt-aleks opened this issue · 1 comments

Describe the bug
With Laravel 11 released we were prompt to upgrade spatie/laravel-permission from v5 to v6 as well. As the standard thing to do we do check your documentation on how to upgrade from v5 to v6 as we've encountered this error during our PEST testing

Access to undeclared static property Spatie\Permission\PermissionRegistrar::$pivotPermission

And upon checking from more clearer instruction to upgrade our migration we stumbled upon with this solution:

#2577 (comment)

Probably best to:

  • make sure composer.json mentions ^6.0 for this package, and double-check using composer outdated
  • delete the old migration for permissions/roles tables
  • re-publish the migration using php artisan vendor:publish
  • re-migrate

So we deleted config/permission.php and the migration file(_create_permission_tables.php) then republish. But the problem with this is we have existing data for the tables such as permissions, roles, model_has_*, role_has_ and the new migration file creates them causing this error during the php artisan migrate:

SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'permissions' already exists (Connection: mysql, SQL: create table `permissions` (`id` bigint unsigned not null auto_increment primary key, `name` varchar(255) not null, `guard_name` varchar(255) not null, `created_at` timestamp null, `updated_at` timestamp null) default character set utf8mb4 collate 'utf8mb4_unicode_ci')

The only solution I can see is to manually backup these tables(probably renaming them) then delete these tables in order for the _create_permission_tables.php able to run then restore the data to these newly created table, but I have worries about messing up with the relationship and primary key autoincrementation.

We wanted to know if there's simpler way to upgrade from v5 to v6 with existing data of permissions/roles.

Thank you guys! Cheers!

Versions

  • spatie/laravel-permission package version: v6.x
  • laravel/framework package v11.x

PHP version: 8.2

Database version: 10.11.4-MariaDB-1:10.11.4+maria~ubu2204

To Reproduce
Steps to reproduce the behavior:

  • Upgrade from Laravel 10 to 11
  • Upgrade spatie/laravel-permission from v5 to v6
  • delete config/permission.php and permission migration file
  • re-publish
  • re-migrate