diff options
author | Toon Claes <toon@gitlab.com> | 2018-11-05 21:26:40 +0100 |
---|---|---|
committer | Toon Claes <toon@gitlab.com> | 2018-11-06 12:36:41 +0100 |
commit | da66a610c02381acd4f18c2f2f5685a9cd3b945e (patch) | |
tree | 0fac555fbf1b27b2688224413c774eaf7e43c810 | |
parent | b6b4e54c466d4877fa29582afe1a12ee2733a1eb (diff) | |
download | gitlab-ce-tc-index-uploads-file-store.tar.gz |
Add migration to steal FillStoreUploadtc-index-uploads-file-store
-rw-r--r-- | db/post_migrate/20181105201455_steal_fill_store_upload.rb | 31 | ||||
-rw-r--r-- | db/schema.rb | 2 | ||||
-rw-r--r-- | spec/migrations/steal_fill_store_upload_spec.rb | 40 |
3 files changed, 72 insertions, 1 deletions
diff --git a/db/post_migrate/20181105201455_steal_fill_store_upload.rb b/db/post_migrate/20181105201455_steal_fill_store_upload.rb new file mode 100644 index 00000000000..982001fedbe --- /dev/null +++ b/db/post_migrate/20181105201455_steal_fill_store_upload.rb @@ -0,0 +1,31 @@ +# frozen_string_literal: true + +class StealFillStoreUpload < ActiveRecord::Migration + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + BATCH_SIZE = 10_000 + + disable_ddl_transaction! + + class Upload < ActiveRecord::Base + include EachBatch + + self.table_name = 'uploads' + self.inheritance_column = :_type_disabled # Disable STI + end + + def up + Gitlab::BackgroundMigration.steal('FillStoreUpload') + + Upload.where(store: nil).each_batch(of: BATCH_SIZE) do |batch| + range = batch.pluck('MIN(id)', 'MAX(id)').first + + Gitlab::BackgroundMigration::FillStoreUpload.new.perform(*range) + end + end + + def down + # noop + end +end diff --git a/db/schema.rb b/db/schema.rb index 7301ef67c14..944ac37acb1 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20181101144347) do +ActiveRecord::Schema.define(version: 20181105201455) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" diff --git a/spec/migrations/steal_fill_store_upload_spec.rb b/spec/migrations/steal_fill_store_upload_spec.rb new file mode 100644 index 00000000000..ed809baf2b5 --- /dev/null +++ b/spec/migrations/steal_fill_store_upload_spec.rb @@ -0,0 +1,40 @@ +# frozen_string_literal: true + +require 'spec_helper' +require Rails.root.join('db', 'post_migrate', '20181105201455_steal_fill_store_upload.rb') + +describe StealFillStoreUpload, :migration do + let(:uploads) { table(:uploads) } + + describe '#up' do + it 'steals the FillStoreUpload background migration' do + expect(Gitlab::BackgroundMigration).to receive(:steal).with('FillStoreUpload').and_call_original + + migrate! + end + + it 'does not run migration if not needed' do + uploads.create(size: 100.kilobytes, + uploader: 'AvatarUploader', + path: 'uploads/-/system/avatar.jpg', + store: 1) + + expect_any_instance_of(Gitlab::BackgroundMigration::FillStoreUpload).not_to receive(:perform) + + migrate! + end + + it 'ensures all rows are migrated' do + uploads.create(size: 100.kilobytes, + uploader: 'AvatarUploader', + path: 'uploads/-/system/avatar.jpg', + store: nil) + + expect_any_instance_of(Gitlab::BackgroundMigration::FillStoreUpload).to receive(:perform).and_call_original + + expect do + migrate! + end.to change { uploads.where(store: nil).count }.from(1).to(0) + end + end +end |