summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames Lopez <james@jameslopez.es>2016-01-29 18:52:49 +0100
committerJames Lopez <james@jameslopez.es>2016-01-29 18:52:49 +0100
commit7dffec2c43116fa339f967b1005f23442752ce0d (patch)
tree7246ed468b7fdbf4758ddb5d4904cb98fe60ed07
parenteb51a4ac1b7702873ecb9de7ddafdb989370437c (diff)
downloadgitlab-ce-7dffec2c43116fa339f967b1005f23442752ce0d.tar.gz
WIP - add migration
-rw-r--r--db/migrate/20160129135155_remove_dot_atom_path_ending_of_projects.rb54
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