summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStan Hu <stanhu@gmail.com>2017-12-27 03:22:46 -0800
committerStan Hu <stanhu@gmail.com>2017-12-27 04:12:18 -0800
commitdfdf22c7d8a9e4776a0e3bfc130ef47aff911022 (patch)
treec8f8a641f2da3a35417a0f147bec1bfcda9e3c68
parent5cacdc4ec1f63338fab923ddb657fdba0a7e6300 (diff)
downloadgitlab-ce-sh-fix-mysql-migration-10-3.tar.gz
Fix PostgreSQL implementation of migrationsh-fix-mysql-migration-10-3
-rw-r--r--changelogs/unreleased/sh-fix-mysql-migration-10-3.yml2
-rw-r--r--db/migrate/20171106151218_issues_moved_to_id_foreign_key.rb4
-rw-r--r--spec/migrations/issues_moved_to_id_foreign_key_spec.rb2
3 files changed, 5 insertions, 3 deletions
diff --git a/changelogs/unreleased/sh-fix-mysql-migration-10-3.yml b/changelogs/unreleased/sh-fix-mysql-migration-10-3.yml
index ac150d2f8ab..d3d1d2f8256 100644
--- a/changelogs/unreleased/sh-fix-mysql-migration-10-3.yml
+++ b/changelogs/unreleased/sh-fix-mysql-migration-10-3.yml
@@ -1,5 +1,5 @@
---
-title: Fix migration for removing orphaned issues.moved_to_id values in MySQL
+title: Fix migration for removing orphaned issues.moved_to_id values in MySQL and PostgreSQL
merge_request:
author:
type: fixed
diff --git a/db/migrate/20171106151218_issues_moved_to_id_foreign_key.rb b/db/migrate/20171106151218_issues_moved_to_id_foreign_key.rb
index 18c2b294c1e..6368e5bd9ce 100644
--- a/db/migrate/20171106151218_issues_moved_to_id_foreign_key.rb
+++ b/db/migrate/20171106151218_issues_moved_to_id_foreign_key.rb
@@ -15,7 +15,9 @@ class IssuesMovedToIdForeignKey < ActiveRecord::Migration
self.table_name = 'issues'
def self.with_orphaned_moved_to_issues
- where('NOT EXISTS (SELECT true FROM issues WHERE issues.id = issues.moved_to_id)')
+ # Be careful to use a second table here for comparison otherwise we'll null
+ # out all rows that don't have id == moved_to_id!
+ where('NOT EXISTS (SELECT true FROM issues b WHERE issues.moved_to_id = b.id)')
.where('moved_to_id IS NOT NULL')
end
end
diff --git a/spec/migrations/issues_moved_to_id_foreign_key_spec.rb b/spec/migrations/issues_moved_to_id_foreign_key_spec.rb
index 009207ef214..d2eef81f396 100644
--- a/spec/migrations/issues_moved_to_id_foreign_key_spec.rb
+++ b/spec/migrations/issues_moved_to_id_foreign_key_spec.rb
@@ -4,7 +4,7 @@ require Rails.root.join('db', 'migrate', '20171106151218_issues_moved_to_id_fore
# The schema version has to be far enough in advance to have the
# only_mirror_protected_branches column in the projects table to create a
# project via FactoryBot.
-describe IssuesMovedToIdForeignKey, :migration, schema: 20171109115718 do
+describe IssuesMovedToIdForeignKey, :migration, schema: 20171114150259 do
let!(:issue_first) { create(:issue, moved_to_id: issue_second.id) }
let!(:issue_second) { create(:issue, moved_to_id: issue_third.id) }
let!(:issue_third) { create(:issue) }