classRemovePeriodsAtEndsOfUsernames<ActiveRecord::MigrationclassNamespace<ActiveRecord::Baseclass<<selfdefby_path(path)where('lower(path) = :value',value: path.downcase).firstenddefclean_path(path)path.gsub!(/@.*\z/,"")path.gsub!(/\.git\z/,"")path.gsub!(/\A-/,"")path.gsub!(/.\z/,"")path.gsub!(/[^a-zA-Z0-9_\-\.]/,"")counter=0base=pathwhileNamespace.by_path(path).present?counter+=1path="#{base}#{counter}"endpathendendenddefupselect_all("SELECT id, username FROM users WHERE username LIKE '%.'").eachdo|user|username=quote_string(Namespace.clean_path(user["username"]))execute"UPDATE users SET username = '#{username}' WHERE id = #{user["id"]}"execute"UPDATE namespaces SET path = '#{username}', name = '#{username}' WHERE type = NULL AND owner_id = #{user["id"]}"endselect_all("SELECT id, path FROM namespaces WHERE type = 'Group' AND path LIKE '%.'").eachdo|group|path=quote_string(Namespace.clean_path(group["path"]))execute"UPDATE namespaces SET path = '#{path}' WHERE id = #{group["id"]}"endendend