diff options
author | Lin Jen-Shin <godfat@godfat.org> | 2017-03-13 15:36:17 +0300 |
---|---|---|
committer | Lin Jen-Shin <godfat@godfat.org> | 2017-03-13 21:12:55 +0300 |
commit | 67729cecc12a56591160d04ea5d79614b1102dc6 (patch) | |
tree | 75bc08a351defa415c12de009d2bb3203e96a469 /db/migrate/20170124174637_add_foreign_keys_to_timelogs.rb | |
parent | 32da7602686f2b8161175d82b121deb9e01b2db5 (diff) |
Add a test which would rollback db and migrate again
Closes #29106
Diffstat (limited to 'db/migrate/20170124174637_add_foreign_keys_to_timelogs.rb')
-rw-r--r-- | db/migrate/20170124174637_add_foreign_keys_to_timelogs.rb | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/db/migrate/20170124174637_add_foreign_keys_to_timelogs.rb b/db/migrate/20170124174637_add_foreign_keys_to_timelogs.rb index 69bfa2d3fc4..676e18cddd3 100644 --- a/db/migrate/20170124174637_add_foreign_keys_to_timelogs.rb +++ b/db/migrate/20170124174637_add_foreign_keys_to_timelogs.rb @@ -49,6 +49,16 @@ class AddForeignKeysToTimelogs < ActiveRecord::Migration Timelog.where('issue_id IS NOT NULL').update_all("trackable_id = issue_id, trackable_type = 'Issue'") Timelog.where('merge_request_id IS NOT NULL').update_all("trackable_id = merge_request_id, trackable_type = 'MergeRequest'") + constraint = + if Gitlab::Database.postgresql? + 'CONSTRAINT' + else + 'FOREIGN KEY' + end + + execute "ALTER TABLE timelogs DROP #{constraint} fk_timelogs_issues_issue_id" + execute "ALTER TABLE timelogs DROP #{constraint} fk_timelogs_merge_requests_merge_request_id" + remove_columns :timelogs, :issue_id, :merge_request_id end end |