Create missing rails association for database relationships for table Users
Currently there are many foreign keys which have been defined at DB level but are not present at rails level for Users table, we need to add those to the rails model for Users to make sure related deletion happens in case of Users deletion.
I wrote a spec to make sure we do not exclude the tables from the check foreign keys already in database but no association in User model
in case they do have an association.
And final result we have around 95 tables which are falling into criteria with no association User's table but out of those 25 tables are Uploads polymorphic tables like abuse_report_uploads, achievement_uploads
. So we can skip that list and we are left 95-25 = 70 more tables to take care of. Out of these 70 tables, there are few tables which have user_id column basically for audit trailing.
Out of the 70 tables, follow tables are the one which have foreign_keys to users and represent user-owned activities
These tables have foreign keys to Users and represent user-owned data or user activities:
| # | Table Name | Association Type | Reason |
|---|-----------|-----------------|---------|
| 1 | **abuse_report_events** | has_many | Admin actions on abuse reports by this user |
| 2 | **abuse_report_notes** | has_many | Admin notes on abuse reports by this user |
| 3 | **ai_settings** | has_one | User's AI configuration |
| 4 | **ai_user_metrics** | has_many | User's AI usage metrics |
| 5 | **approval_group_rules_users** | has_many | User's approval group rule assignments |
| 6 | **approval_merge_request_rules_approved_approvers** | has_many | MRs this user has approved |
| 7 | **approval_merge_request_rules_users** | has_many | User's MR approval rule assignments |
| 8 | **approval_project_rules_users** | has_many | User's project approval rule assignments |
| 9 | **authentication_events** | has_many | User's authentication history |
| 10 | **board_assignees** | has_many | Board items assigned to user |
| 11 | **board_group_recent_visits** | has_many | User's recent group board visits |
| 12 | **board_project_recent_visits** | has_many | User's recent project board visits |
| 13 | **boards_epic_list_user_preferences** | has_many | User's epic list preferences |
| 14 | **bulk_import_exports** | has_many | User's bulk import/export operations |
| 15 | **csv_issue_imports** | has_many | CSV imports initiated by user |
| 16 | **draft_notes** | has_many | User's draft comments |
| 17 | **group_deletion_schedules** | has_many | Groups scheduled for deletion by user |
| 18 | **group_import_states** | has_many | Group imports initiated by user |
| 19 | **import_failures** | has_many | User's import failures |
| 20 | **import_source_users** | has_many | Import user mappings |
| 21 | **jira_imports** | has_many | Jira imports initiated by user |
| 22 | **list_user_preferences** | has_many | User's board list preferences |
| 23 | **members_deletion_schedules** | has_one | User's account deletion schedule |
| 24 | **merge_requests_approval_rules_approver_users** | has_many | User's MR approver assignments |
| 25 | **project_export_jobs** | has_many | Project exports initiated by user |
| 26 | **security_policy_dismissals** | has_many | Security policies dismissed by user |
| 27 | **service_desk_custom_email_verifications** | has_many | User's verified custom emails |
| 28 | **ssh_signatures** | has_many | User's SSH signatures |
| 29 | **targeted_message_dismissals** | has_many | Messages dismissed by user |
| 30 | **user_namespace_callouts** | has_many | User's namespace callouts |
| 31 | **work_item_type_user_preferences** | has_many | User's work item preferences |
| 32 | **security_orchestration_policy_rule_schedules** | has_many | Who scheduled |
Following tables belong to other entities (projects, groups, system) where the user foreign key is only for audit/tracking: I will assign the issues for these ones and ask other the related team for review whether its ok to add a dependent clause or not.
| # | Table Name | Actual Owner | group name | User FK Purpose |
|---|-----------|--------------|-----------------|
| 1 | **agent_activity_events** | ~"group::organizations" (environments) | Who triggered event |
| 2 | **approval_policy_merge_request_bypass_events** | ~"group::security policies" | Who bypassed policy |
| 3 | **catalog_resource_versions** | catalog_resources | ~"group::pipeline authoring" | Who created version |
| 4 | **cluster_agent_tokens** | cluster_agents | ~"group::organizations" (environments) | Who created token |
| 5 | **cluster_agent_url_configurations** | cluster_agents | ~"group::organizations" (environments) | Who configured |
| 6 | **cluster_agents** | projects | ~"group::organizations" (environments) | Who created agent |
| 7 | **clusters** | projects/groups | ~"group::organizations" (environments) | Who created cluster |
| 8 | **custom_fields** | projects/groups | ~"group::project management" | Who created field |
| 9 | **deploy_tokens** | projects/groups | ~"group::environments" | Who created token |
| 10 | **design_management_versions** | designs | ~"group::product planning" | Who created version |
| 11 | **duo_workflows_workflows** | system | ~"group::ai framework" Who created workflow |
| 12 | **incident_management_timeline_events** | incidents | ~"group::Networking & Incident Management" | Who added event |
| 13 | **lfs_file_locks** | repositories | ~"group::source code" | Who locked file |
| 14 | **lists** | boards | ~"group::project management" | Who created list |
| 15 | **merge_requests_compliance_violations** | merge_requests | ~"group::compliance" |Who caused violation |
| 16 | **merge_requests_merge_data** | merge_requests | ~"group::code review" | Who merged |
| 17 | **merge_trains** | projects | ~"group::pipeline execution" | Who added to train |
| 18 | **ml_candidates** | ml_experiments | ~"group::cells infrastructure" (mlops) | Who created candidate |
| 19 | **ml_experiments** | projects | ~"group::cells infrastructure" (mlops) | Who created experiment |
| 20 | **ml_models** | projects | ~"group::cells infrastructure" (mlops) | Who created model |
| 21 | **packages_composer_packages** | projects | ~"group::package registry" | Who published package |
| 22 | **packages_debian_group_distributions** | groups | ~"group::package registry"| Who configured |
| 23 | **packages_debian_project_distributions** | projects | ~"group::package registry"| Who configured
| 24 | **packages_packages** | projects/groups | ~"group::package registry"| Who published package |
| 25 | **protected_environment_approval_rules** | ~"group::release-and-deploy" (environments) | environments | Who created rule |
| 26 | **protected_environment_deploy_access_levels** | environments |~"group::release-and-deploy (environments)| Access control |
| 27 | **protected_tag_create_access_levels** | protected_tags | ~"group::source code" | Access control |
| 28 | **resource_iteration_events** | various (polymorphic) |Polymorphic to ResourceEvent (project management)| Who made change |
| 29 | **resource_link_events** | various (polymorphic) | Polymorphic to ResourceEvent (project management)| Who made change |
| 30 | **resource_milestone_events** | various (polymorphic) |Polymorphic to ResourceEvent (project management)| Who made change |
| 31 | **resource_weight_events** | various (polymorphic) | Polymorphic to ResourceEvent (project management)| Who made change
| 32 | **terraform_state_versions** | terraform_states | ~"group::organizations" (geo or environments) | Who created version |
| 33 | **terraform_states** | projects | ~"group::organizations" (geo or environments) | Who locked state |
| 34 | **work_item_custom_lifecycles** | projects/groups | ~"group::project management" | Who configured
| 35 | **work_item_custom_statuses** | projects/groups |~"group::project management"| Who configured |