summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStan Hu <stanhu@gmail.com>2016-10-20 21:43:24 -0700
committerStan Hu <stanhu@gmail.com>2016-10-20 21:43:24 -0700
commitf12cf0035c7c2a32eab9c75a9ce926d39f5bd7bc (patch)
tree9585ba21463e740d9a7e61164fdbbeba959bd4bf
parentb7170277c65fb76b5d0d732ab598eb475b0d823c (diff)
downloadgitlab-ce-sh-fix-label-uniquness-migration.tar.gz
Fix broken label uniqueness label migrationsh-fix-label-uniquness-migration
The previous implementation of the migration failed on staging because the migration was attempted to remove labels from projects that did not actually have duplicates. This occurred because the SQL query did not account for the project ID when selecting the labels. To replicate the problem: 1. Disable the uniqueness validation in app/models/label.rb. 2. Create a duplicate label "bug" in project A. 3. Create the same label in project B with label "bug". The migration will attempt to remove the label in B even if there are no duplicates. Closes #23609
-rw-r--r--db/migrate/20161017125927_add_unique_index_to_labels.rb4
1 files changed, 2 insertions, 2 deletions
diff --git a/db/migrate/20161017125927_add_unique_index_to_labels.rb b/db/migrate/20161017125927_add_unique_index_to_labels.rb
index 16ae38612de..f2b56ebfb7b 100644
--- a/db/migrate/20161017125927_add_unique_index_to_labels.rb
+++ b/db/migrate/20161017125927_add_unique_index_to_labels.rb
@@ -7,9 +7,9 @@ class AddUniqueIndexToLabels < ActiveRecord::Migration
disable_ddl_transaction!
def up
- select_all('SELECT title, COUNT(id) as cnt FROM labels GROUP BY project_id, title HAVING COUNT(id) > 1').each do |label|
+ select_all('SELECT title, project_id, COUNT(id) as cnt FROM labels GROUP BY project_id, title HAVING COUNT(id) > 1').each do |label|
label_title = quote_string(label['title'])
- duplicated_ids = select_all("SELECT id FROM labels WHERE title = '#{label_title}' ORDER BY id ASC").map{ |label| label['id'] }
+ duplicated_ids = select_all("SELECT id FROM labels WHERE project_id = #{label['project_id']} AND title = '#{label_title}' ORDER BY id ASC").map{ |label| label['id'] }
label_id = duplicated_ids.first
duplicated_ids.delete(label_id)