diff options
author | James Lopez <james@jameslopez.es> | 2016-01-29 18:52:49 +0100 |
---|---|---|
committer | James Lopez <james@jameslopez.es> | 2016-01-29 18:52:49 +0100 |
commit | 7dffec2c43116fa339f967b1005f23442752ce0d (patch) | |
tree | 7246ed468b7fdbf4758ddb5d4904cb98fe60ed07 /db | |
parent | eb51a4ac1b7702873ecb9de7ddafdb989370437c (diff) | |
download | gitlab-ce-7dffec2c43116fa339f967b1005f23442752ce0d.tar.gz |
WIP - add migration
Diffstat (limited to 'db')
-rw-r--r-- | db/migrate/20160129135155_remove_dot_atom_path_ending_of_projects.rb | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/db/migrate/20160129135155_remove_dot_atom_path_ending_of_projects.rb b/db/migrate/20160129135155_remove_dot_atom_path_ending_of_projects.rb new file mode 100644 index 00000000000..c7b986aca91 --- /dev/null +++ b/db/migrate/20160129135155_remove_dot_atom_path_ending_of_projects.rb @@ -0,0 +1,54 @@ +class RemoveDotAtomPathEndingOfProjects < ActiveRecord::Migration + + class ProjectPath + def initilize(old_path) + @old_path = old_path + end + + def clean_path + @_clean_path ||= PathCleaner.clean(@old_path) + end + end + + module PathCleaner + def initialize(path) + @path = path + end + + def self.clean(*args) + new(*args).clean + end + + def clean + path = cleaned_path + count = 0 + while path_exists?(path) + path = "#{cleaned_path}#{count}" + count += 1 + end + path + end + + def cleaned_path + @_cleaned_path ||= path.gsub(/\.atom\z/, '-atom') + end + + def path_exists?(path) + Project.find_by_path(path) + end + end + + def up + projects_with_dot_atom.each do |project| + remove_dot(project) + end + end + + private + + def remove_dot(project) + #TODO + end + + +end |