-
-
Notifications
You must be signed in to change notification settings - Fork 211
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Behaviour of NewAdapterByDB() has a breaking change #78
Comments
@d1ss0nanz I think |
Yes, but that's not the cause. I've checked my old logs and my database initialisation scripts. Please see my note about the use of the Migrator. |
@closetool is it possible to fix this bug? |
@d1ss0nanz What can I do for you? |
@closetool if someone is running our migration code (the following line): return a.db.Migrator().CreateTable(a.getTableInstance()) Will they end up with the wrong table name: |
@hsluoyz In v3.2.0, there will be no casbin_rules default, in spite of that, I changed the |
Ok, so up to at least 3.0.3, in some code paths, the created table is named "casbin_rules". Now, when updating to a more recent version, gorm-adapter is creating a new table "casbin_rule" besides the fact that there already exists a table "casbin_rules". All authorization attempts silently fail, since the group membership data is in the old table. I would suggest that you document the breaking change, so one doesn't have to understand how Gorm derives table names from struct names, to understand what's going on. Optionally, there should be migration code that checks for a table "casbin_rules" and moves the data over when creating "casbin_rule". |
@hsluoyz @closetool Hello, I think it was a new bug with new version gorm. a.db = db.Scopes(a.casbinRuleTable()).Session(&gorm.Session{})
err := a.createTable() It was successful work at least version 1.20.8. |
@closetool But I get the same error, why? |
@00LT00 For me this was caused by using But I've decided to just migrate the data into "casbin_rule" and go with the default. |
It just fix your error, but the bug is there. |
@00LT00 yep |
@00LT00 thanks! I saw Jinzhu has fixed that bug. So updating to Gorm master HEAD will fix the issue. @d1ss0nanz Bug fixed in: https://github.com/casbin/gorm-adapter/releases/tag/v3.2.2 |
Hi,
Just a heads up for other users:
I've updated from gorm-adapter 3.0.3 to 3.2.0 today and found that NewAdapterByDB() is now using "casbin_rule" as table name vs. "casbin_rules" in 3.0.3.
Therefore the user group memberships where missing in the new "casbin_rule" table.
The reason is probably (didn't verify) the use of the Gorm Migrator in 3.0.3:
return a.db.Migrator().CreateTable(a.getTableInstance())
In Gorm "CasbinRule" will result in a table name "casbin_rules".
This fixed if for me:
insert into casbin_rule(ptype,v0,v1) select p_type,v0,v1 from casbin_rules where p_type = 'g';
The text was updated successfully, but these errors were encountered: