Fix username period migration to preserve uniqueness of names and paths.
This commit is contained in:
parent
5456b00f27
commit
46524ecb33
2 changed files with 6 additions and 5 deletions
|
@ -59,6 +59,7 @@ class Namespace < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
def clean_path(path)
|
def clean_path(path)
|
||||||
|
path = path.dup
|
||||||
path.gsub!(/@.*\z/, "")
|
path.gsub!(/@.*\z/, "")
|
||||||
path.gsub!(/\.git\z/, "")
|
path.gsub!(/\.git\z/, "")
|
||||||
path.gsub!(/\A-+/, "")
|
path.gsub!(/\A-+/, "")
|
||||||
|
|
|
@ -3,21 +3,21 @@ class RemovePeriodsAtEndsOfUsernames < ActiveRecord::Migration
|
||||||
|
|
||||||
class Namespace < ActiveRecord::Base
|
class Namespace < ActiveRecord::Base
|
||||||
class << self
|
class << self
|
||||||
def by_path(path)
|
def find_by_path_or_name(path)
|
||||||
where('lower(path) = :value', value: path.downcase).first
|
find_by("lower(path) = :path OR lower(name) = :path", path: path.downcase)
|
||||||
end
|
end
|
||||||
|
|
||||||
def clean_path(path)
|
def clean_path(path)
|
||||||
path = path.dup
|
path = path.dup
|
||||||
path.gsub!(/@.*\z/, "")
|
path.gsub!(/@.*\z/, "")
|
||||||
path.gsub!(/\.git\z/, "")
|
path.gsub!(/\.git\z/, "")
|
||||||
path.gsub!(/\A-/, "")
|
path.gsub!(/\A-+/, "")
|
||||||
path.gsub!(/.\z/, "")
|
path.gsub!(/\.+\z/, "")
|
||||||
path.gsub!(/[^a-zA-Z0-9_\-\.]/, "")
|
path.gsub!(/[^a-zA-Z0-9_\-\.]/, "")
|
||||||
|
|
||||||
counter = 0
|
counter = 0
|
||||||
base = path
|
base = path
|
||||||
while Namespace.by_path(path).present?
|
while Namespace.find_by_path_or_name(path)
|
||||||
counter += 1
|
counter += 1
|
||||||
path = "#{base}#{counter}"
|
path = "#{base}#{counter}"
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue