I built an auditing behavior that creates an audit trail whenever records are inserted/updated/deleted. It works great on models that have an auto-increment ID as a primary key. However, the various auth tables (specifically auth_item) are keyed on a name. My app allows users to create roles, just giving that role a name.
The issue I am finding is that since auth_item is keyed on the name, when a user changes the name of a role things start to get problematic. For example, if I change the name of the role "Guest" to "Everyone" then the primary key of that auth_item changes. I have a new audit that shows the old and new data values (stored in the audit model) and a "restore" button that will execute an update statement setting the record back to the old values. However, a record does not exist with the "Guest" name so the update will fail.
There are other examples of issues but the general problem is that the Primary Key can be updated. I am hoping someone with much more Yii2 RBAC knowledge can help me with the following:
How much effort would it take to change auth_item to be keyed on a new auto-increment ID?
Would I just be better off adding a "Display Name" column to auth_item model and allowing that to be changed by user while forcing Name to be left as-is once a record is created (sort of like a slug)?
I greatly appreciate any advice anyone can give.