Commit 4125de5e authored by skv-headless's avatar skv-headless

Fix merge_request_diffs migrations for postgresql

parent 5221dbfe
class MigrateMrDiffs < ActiveRecord::Migration class MigrateMrDiffs < ActiveRecord::Migration
def self.up def self.up
execute "INSERT INTO merge_request_diffs ( merge_request_id ) SELECT id FROM merge_requests" execute "INSERT INTO merge_request_diffs ( merge_request_id, st_commits, st_diffs ) SELECT id, st_commits, st_diffs FROM merge_requests"
execute "UPDATE merge_requests mr, merge_request_diffs md SET md.st_commits = mr.st_commits WHERE md.merge_request_id = mr.id"
execute "UPDATE merge_requests mr, merge_request_diffs md SET md.st_diffs = mr.st_diffs WHERE md.merge_request_id = mr.id"
end end
def self.down def self.down
......
...@@ -7,7 +7,15 @@ class RemoveMRdiffFields < ActiveRecord::Migration ...@@ -7,7 +7,15 @@ class RemoveMRdiffFields < ActiveRecord::Migration
def down def down
add_column :merge_requests, :st_commits, :text, null: true, limit: 2147483647 add_column :merge_requests, :st_commits, :text, null: true, limit: 2147483647
add_column :merge_requests, :st_diffs, :text, null: true, limit: 2147483647 add_column :merge_requests, :st_diffs, :text, null: true, limit: 2147483647
if ActiveRecord::Base.connection.adapter_name == 'PostgreSQL'
execute "UPDATE merge_requests mr
SET (st_commits, st_diffs) = (md.st_commits, md.st_diffs)
FROM merge_request_diffs md
WHERE md.merge_request_id = mr.id"
else
execute "UPDATE merge_requests mr, merge_request_diffs md SET mr.st_commits = md.st_commits WHERE md.merge_request_id = mr.id" execute "UPDATE merge_requests mr, merge_request_diffs md SET mr.st_commits = md.st_commits WHERE md.merge_request_id = mr.id"
execute "UPDATE merge_requests mr, merge_request_diffs md SET mr.st_diffs = md.st_diffs WHERE md.merge_request_id = mr.id" execute "UPDATE merge_requests mr, merge_request_diffs md SET mr.st_diffs = md.st_diffs WHERE md.merge_request_id = mr.id"
end end
end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment