diff options
author | Douwe Maan <douwe@gitlab.com> | 2017-11-23 18:01:30 +0300 |
---|---|---|
committer | Douwe Maan <douwe@gitlab.com> | 2017-11-23 18:01:30 +0300 |
commit | ad70fb7bdc7a95f99267e88335b2241d6c9feff0 (patch) | |
tree | b263071adc3e21aa99c26001c8279115285e04a8 /db | |
parent | 038f5a412d0085f2d9610c77cea37cec75572b27 (diff) | |
parent | 991bf24ec8890eca248a00deb4f33f309c9ffb83 (diff) |
Merge branch 'use-merge-requests-diff-id-column' into 'master'
Use foreign key to get latest MR diff
Closes #37631
See merge request gitlab-org/gitlab-ce!15126
Diffstat (limited to 'db')
-rw-r--r-- | db/migrate/20171115164540_populate_merge_requests_latest_merge_request_diff_id_take_two.rb | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/db/migrate/20171115164540_populate_merge_requests_latest_merge_request_diff_id_take_two.rb b/db/migrate/20171115164540_populate_merge_requests_latest_merge_request_diff_id_take_two.rb new file mode 100644 index 00000000000..27b6b4ebddc --- /dev/null +++ b/db/migrate/20171115164540_populate_merge_requests_latest_merge_request_diff_id_take_two.rb @@ -0,0 +1,30 @@ +# This is identical to the stolen background migration, which already has specs. +class PopulateMergeRequestsLatestMergeRequestDiffIdTakeTwo < ActiveRecord::Migration + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + BATCH_SIZE = 1_000 + + class MergeRequest < ActiveRecord::Base + self.table_name = 'merge_requests' + + include ::EachBatch + end + + disable_ddl_transaction! + + def up + Gitlab::BackgroundMigration.steal('PopulateMergeRequestsLatestMergeRequestDiffId') + + update = ' + latest_merge_request_diff_id = ( + SELECT MAX(id) + FROM merge_request_diffs + WHERE merge_requests.id = merge_request_diffs.merge_request_id + )'.squish + + MergeRequest.where(latest_merge_request_diff_id: nil).each_batch(of: BATCH_SIZE) do |relation| + relation.update_all(update) + end + end +end |