Commit 8fa53ce43dff48a3e282460c9f9f40dbdfee6e12

Authored by Dmitriy Zaporozhets
2 parents 11f20576 5e7e814e

Merge branch 'check_orphaned_users_groups' into 'master'

Check Orphaned Users Groups
Showing 1 changed file with 14 additions and 0 deletions   Show diff stats
lib/tasks/gitlab/check.rake
... ... @@ -17,6 +17,7 @@ namespace :gitlab do
17 17 check_database_config_exists
18 18 check_database_is_not_sqlite
19 19 check_migrations_are_up
  20 + check_orphaned_users_groups
20 21 check_gitlab_config_exists
21 22 check_gitlab_config_not_outdated
22 23 check_log_writable
... ... @@ -181,6 +182,19 @@ namespace :gitlab do
181 182 end
182 183 end
183 184  
  185 + def check_orphaned_users_groups
  186 + print "Database contains orphaned UsersGroups? ... "
  187 + if UsersGroup.where("user_id not in (select id from users)").count > 0
  188 + puts "yes".red
  189 + try_fixing_it(
  190 + "You can delete the orphaned records using something along the lines of:",
  191 + sudo_gitlab("bundle exec rails runner -e production 'UsersGroup.where(\"user_id NOT IN (SELECT id FROM users)\").delete_all'")
  192 + )
  193 + else
  194 + puts "no".green
  195 + end
  196 + end
  197 +
184 198 def check_satellites_exist
185 199 print "Projects have satellites? ... "
186 200  
... ...