diff --git a/db/migrate/20161226122833_remove_dot_git_from_usernames.rb b/db/migrate/20161226122833_remove_dot_git_from_usernames.rb
index 4e59cbd8a7fcdc81ccdc997f68ec5099950f695e..c3a8f2fd91c2291a5a7810dff4669e15a753bf63 100644
--- a/db/migrate/20161226122833_remove_dot_git_from_usernames.rb
+++ b/db/migrate/20161226122833_remove_dot_git_from_usernames.rb
@@ -68,8 +68,10 @@ class RemoveDotGitFromUsernames < ActiveRecord::Migration
   end
 
   def check_routes(base, counter, path)
+    route_exists = route_exists?(path)
+
     Gitlab.config.repositories.storages.each_value do |storage|
-      if route_exists?(path) || path_exists?(path, storage)
+      if route_exists && path_exists?(path, storage)
         counter += 1
         path = "#{base}#{counter}"