summaryrefslogtreecommitdiff
path: root/db
diff options
context:
space:
mode:
authorDouwe Maan <douwe@gitlab.com>2015-04-17 12:03:54 +0200
committerDouwe Maan <douwe@gitlab.com>2015-04-17 12:03:54 +0200
commit46524ecb3329f4563552e46d7164385639933d9e (patch)
tree0d375ff06a9ae2b6c1be93791a1e6b22517078b1 /db
parent5456b00f27d631fb58e230a75cfe84c7daf4e207 (diff)
downloadgitlab-ce-46524ecb3329f4563552e46d7164385639933d9e.tar.gz
Fix username period migration to preserve uniqueness of names and paths.
Diffstat (limited to 'db')
-rw-r--r--db/migrate/20150324133047_remove_periods_at_ends_of_usernames.rb10
1 files changed, 5 insertions, 5 deletions
diff --git a/db/migrate/20150324133047_remove_periods_at_ends_of_usernames.rb b/db/migrate/20150324133047_remove_periods_at_ends_of_usernames.rb
index 7ce53c2a0d6..dc38b0eceb7 100644
--- a/db/migrate/20150324133047_remove_periods_at_ends_of_usernames.rb
+++ b/db/migrate/20150324133047_remove_periods_at_ends_of_usernames.rb
@@ -3,21 +3,21 @@ class RemovePeriodsAtEndsOfUsernames < ActiveRecord::Migration
class Namespace < ActiveRecord::Base
class << self
- def by_path(path)
- where('lower(path) = :value', value: path.downcase).first
+ def find_by_path_or_name(path)
+ find_by("lower(path) = :path OR lower(name) = :path", path: path.downcase)
end
def clean_path(path)
path = path.dup
path.gsub!(/@.*\z/, "")
path.gsub!(/\.git\z/, "")
- path.gsub!(/\A-/, "")
- path.gsub!(/.\z/, "")
+ path.gsub!(/\A-+/, "")
+ path.gsub!(/\.+\z/, "")
path.gsub!(/[^a-zA-Z0-9_\-\.]/, "")
counter = 0
base = path
- while Namespace.by_path(path).present?
+ while Namespace.find_by_path_or_name(path)
counter += 1
path = "#{base}#{counter}"
end