-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Fix: Make team_foreign_key nullable in pivot tables (#2888)
#2894
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
base: main
Are you sure you want to change the base?
Fix: Make team_foreign_key nullable in pivot tables (#2888)
#2894
Conversation
…s_permissions and model_has_roles tables and relevent tests to proof
runofthemill
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks @imhayatunnabi for this fix! I ran into an issue, noted a possible fix below
| $table->primary([$pivotPermission, $columnNames['model_morph_key'], 'model_type'], | ||
| 'model_has_permissions_permission_model_type_primary'); | ||
| $table->unique([$columnNames['team_foreign_key'], $pivotPermission, $columnNames['model_morph_key'], 'model_type'], | ||
| 'model_has_permissions_team_foreign_key_permission_model_type_unique'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
noting this identifier is too long for MySQL; char limit is 64, and this is 67; possible fix:
| 'model_has_permissions_team_foreign_key_permission_model_type_unique'); | |
| 'model_has_permissions_team_fk_permission_model_type_unique'); |
| $table->primary([$columnNames['team_foreign_key'], $pivotPermission, $columnNames['model_morph_key'], 'model_type'], | ||
| 'model_has_permissions_permission_model_type_primary'); | ||
| $table->unique([$columnNames['team_foreign_key'], $pivotPermission, $columnNames['model_morph_key'], 'model_type'], | ||
| 'model_has_permissions_team_foreign_key_permission_model_type_unique'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same as above;
| 'model_has_permissions_team_foreign_key_permission_model_type_unique'); | |
| 'model_has_permissions_team_fk_permission_model_type_unique'); |
|
@runofthemill the suggestion and reviews has been updated. can you please check again ? |
Github Issue: #2888
The
team_foreign_keycolumn was nullable in therolestable but not inmodel_has_permissions&model_has_rolespivot tables. This caused errors when assigning global roles (withteam_foreign_key = null) to users, as the pivot tables rejected NULL values.Added test coverage to verify the fix and prevent regressions:
it_can_assign_global_role_with_null_team_foreign_key_to_user()- Core scenario from issueit_can_assign_global_role_to_multiple_users_across_different_teams()- Unique constraint with NULLit_can_query_global_roles_correctly_across_different_teams()- Query logic with NULLit_allows_direct_database_insertion_with_null_team_foreign_key()- Direct schema testit_handles_mixed_team_and_global_roles_correctly()- Edge casesit_allows_direct_database_insertion_with_null_team_foreign_key_for_permissions()- Permissions table