From 4aa3ce75342f26be3c87ac8c84f24658b9ef22a4 Mon Sep 17 00:00:00 2001 From: Jacob Vosmaer Date: Fri, 14 Mar 2014 17:25:11 +0100 Subject: Add check for orphaned UsersGroups --- lib/tasks/gitlab/check.rake | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lib/tasks/gitlab/check.rake b/lib/tasks/gitlab/check.rake index 2b158fe14ee..467a91fbe86 100644 --- a/lib/tasks/gitlab/check.rake +++ b/lib/tasks/gitlab/check.rake @@ -17,6 +17,7 @@ namespace :gitlab do check_database_config_exists check_database_is_not_sqlite check_migrations_are_up + check_orphaned_users_groups check_gitlab_config_exists check_gitlab_config_not_outdated check_log_writable @@ -181,6 +182,15 @@ namespace :gitlab do end end + def check_orphaned_users_groups + print "Database contains orphaned UsersGroups? ... " + if UsersGroup.where("user_id not in (select id from users)").count > 0 + puts "yes".red + else + puts "no".green + end + end + def check_satellites_exist print "Projects have satellites? ... " -- cgit v1.2.1 From 5e7e814e813da0ab9dcadd0c223a3aff6e89dfdd Mon Sep 17 00:00:00 2001 From: Jacob Vosmaer Date: Mon, 17 Mar 2014 11:16:55 +0100 Subject: Drop UsersGroup orphans using `rails runner` --- lib/tasks/gitlab/check.rake | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/tasks/gitlab/check.rake b/lib/tasks/gitlab/check.rake index 467a91fbe86..78b154cbdd9 100644 --- a/lib/tasks/gitlab/check.rake +++ b/lib/tasks/gitlab/check.rake @@ -186,6 +186,10 @@ namespace :gitlab do print "Database contains orphaned UsersGroups? ... " if UsersGroup.where("user_id not in (select id from users)").count > 0 puts "yes".red + try_fixing_it( + "You can delete the orphaned records using something along the lines of:", + sudo_gitlab("bundle exec rails runner -e production 'UsersGroup.where(\"user_id NOT IN (SELECT id FROM users)\").delete_all'") + ) else puts "no".green end -- cgit v1.2.1