summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Brandl <abrandl@gitlab.com>2018-08-22 18:55:46 +0200
committerAndreas Brandl <abrandl@gitlab.com>2018-08-22 18:55:46 +0200
commit6462f094daeb6a6bc43bb478d5d9d0bfb30bebf8 (patch)
treea2ec4746796b8012d8da8dca455fb815400674f5
parent1231d788471287eecd9590a851e93b39ce8135a6 (diff)
downloadgitlab-ce-ab-api-protected-tags.tar.gz
Fix migration for mysql.ab-api-protected-tags
-rw-r--r--db/migrate/20180711103851_drop_duplicate_protected_tags.rb16
1 files changed, 7 insertions, 9 deletions
diff --git a/db/migrate/20180711103851_drop_duplicate_protected_tags.rb b/db/migrate/20180711103851_drop_duplicate_protected_tags.rb
index fd87ba0d86e..8fa2137551e 100644
--- a/db/migrate/20180711103851_drop_duplicate_protected_tags.rb
+++ b/db/migrate/20180711103851_drop_duplicate_protected_tags.rb
@@ -25,17 +25,15 @@ class DropDuplicateProtectedTags < ActiveRecord::Migration
.group(:name, :project_id)
.select('max(id)')
+ tags = ProtectedTag
+ .where(project_id: projects)
+ .where.not(id: ids)
+
if Gitlab::Database.postgresql?
- ProtectedTag
- .where(project_id: projects)
- .where.not(id: ids)
- .delete_all
+ tags.delete_all
else
- sql = ProtectedTag
- .select(:id)
- .where(project_id: projects)
- .where.not(id: ids)
- .to_sql
+ # Workaround needed for MySQL
+ sql = "SELECT id FROM (#{tags.to_sql}) protected_tags"
ProtectedTag.where("id IN (#{sql})").delete_all # rubocop:disable GitlabSecurity/SqlInjection
end