diff options
author | Valery Sizov <vsv2711@gmail.com> | 2015-03-06 21:09:14 +0200 |
---|---|---|
committer | Valery Sizov <vsv2711@gmail.com> | 2015-03-10 20:09:34 +0200 |
commit | 02ed61c4db6fd6c20e3a23e525ccc3aef174a874 (patch) | |
tree | 75943d7ff3c9dac803a45a2f9866c00731a8c4b7 /db | |
parent | ed4c7190ed47f0311ba5f5a140b2c71a694b05db (diff) | |
download | gitlab-ce-02ed61c4db6fd6c20e3a23e525ccc3aef174a874.tar.gz |
remove duplication
Diffstat (limited to 'db')
-rw-r--r-- | db/migrate/20150306023106_fix_namespace_duplication.rb | 21 | ||||
-rw-r--r-- | db/migrate/20150306023112_add_unique_index_to_namespace.rb | 4 |
2 files changed, 23 insertions, 2 deletions
diff --git a/db/migrate/20150306023106_fix_namespace_duplication.rb b/db/migrate/20150306023106_fix_namespace_duplication.rb new file mode 100644 index 00000000000..334e5574559 --- /dev/null +++ b/db/migrate/20150306023106_fix_namespace_duplication.rb @@ -0,0 +1,21 @@ +class FixNamespaceDuplication < ActiveRecord::Migration + def up + #fixes path duplication + select_all('SELECT MAX(id) max, COUNT(id) cnt, path FROM namespaces GROUP BY path HAVING COUNT(id) > 1').each do |nms| + bad_nms_ids = select_all("SELECT id FROM namespaces WHERE path = '#{nms['path']}' AND id <> #{nms['max']}").map{|x| x["id"]} + execute("UPDATE projects SET namespace_id = #{nms["max"]} WHERE namespace_id IN(#{bad_nms_ids.join(', ')})") + execute("DELETE FROM namespaces WHERE id IN(#{bad_nms_ids.join(', ')})") + end + + #fixes name duplication + select_all('SELECT MAX(id) max, COUNT(id) cnt, name FROM namespaces GROUP BY name HAVING COUNT(id) > 1').each do |nms| + bad_nms_ids = select_all("SELECT id FROM namespaces WHERE name = '#{nms['name']}' AND id <> #{nms['max']}").map{|x| x["id"]} + execute("UPDATE projects SET namespace_id = #{nms["max"]} WHERE namespace_id IN(#{bad_nms_ids.join(', ')})") + execute("DELETE FROM namespaces WHERE id IN(#{bad_nms_ids.join(', ')})") + end + end + + def down + # not implemented + end +end diff --git a/db/migrate/20150306023112_add_unique_index_to_namespace.rb b/db/migrate/20150306023112_add_unique_index_to_namespace.rb index b1f7822b4dc..6472138e3ef 100644 --- a/db/migrate/20150306023112_add_unique_index_to_namespace.rb +++ b/db/migrate/20150306023112_add_unique_index_to_namespace.rb @@ -1,7 +1,7 @@ class AddUniqueIndexToNamespace < ActiveRecord::Migration def change - remove_index :namespaces, :name - remove_index :namespaces, :path + remove_index :namespaces, column: :name if index_exists?(:namespaces, :name) + remove_index :namespaces, column: :path if index_exists?(:namespaces, :path) add_index :namespaces, :name, unique: true add_index :namespaces, :path, unique: true |