diff options
author | Felipe Artur <felipefac@gmail.com> | 2019-02-14 11:48:20 -0200 |
---|---|---|
committer | Felipe Artur <felipefac@gmail.com> | 2019-02-14 11:48:20 -0200 |
commit | 37741c59a4daf1b0d6d9f7a6a51337e9d8effb66 (patch) | |
tree | 4a4bc367617a4ad4e106ddeffeecf1cb013ad5e4 /db | |
parent | 26f40aefb09b96538fa99f74d46542ad39bb1679 (diff) | |
download | gitlab-ce-37741c59a4daf1b0d6d9f7a6a51337e9d8effb66.tar.gz |
Split background migration for issues and merge requests
Diffstat (limited to 'db')
-rw-r--r-- | db/migrate/20190211131150_add_state_id_to_issuables.rb | 30 | ||||
-rw-r--r-- | db/post_migrate/20190214112022_schedule_sync_issuables_state_id.rb | 43 | ||||
-rw-r--r-- | db/schema.rb | 2 |
3 files changed, 44 insertions, 31 deletions
diff --git a/db/migrate/20190211131150_add_state_id_to_issuables.rb b/db/migrate/20190211131150_add_state_id_to_issuables.rb index 440f577e1a3..cf3f7671a67 100644 --- a/db/migrate/20190211131150_add_state_id_to_issuables.rb +++ b/db/migrate/20190211131150_add_state_id_to_issuables.rb @@ -1,41 +1,11 @@ class AddStateIdToIssuables < ActiveRecord::Migration[5.0] include Gitlab::Database::MigrationHelpers - #include AfterCommitQueue DOWNTIME = false - MIGRATION = 'SyncIssuablesStateId'.freeze - - # 2019-02-12 Gitlab.com issuable numbers - # issues count: 13587305 - # merge requests count: 18925274 - # Using this 25000 as batch size should take around 26 hours - # to migrate both issues and merge requests - BATCH_SIZE = 25000 - DELAY_INTERVAL = 5.minutes.to_i - - class Issue < ActiveRecord::Base - include EachBatch - - self.table_name = 'issues' - end - - class MergeRequest < ActiveRecord::Base - include EachBatch - - self.table_name = 'merge_requests' - end def up add_column :issues, :state_id, :integer, limit: 2 add_column :merge_requests, :state_id, :integer, limit: 2 - - # Is this safe? - # Added to avoid an warning about jobs running inside transactions. - # Since we only add a column this should be ok - Sidekiq::Worker.skipping_transaction_check do - queue_background_migration_jobs_by_range_at_intervals(Issue.where(state_id: nil), MIGRATION, DELAY_INTERVAL, batch_size: BATCH_SIZE) - queue_background_migration_jobs_by_range_at_intervals(MergeRequest.where(state_id: nil), MIGRATION, DELAY_INTERVAL, batch_size: BATCH_SIZE) - end end def down diff --git a/db/post_migrate/20190214112022_schedule_sync_issuables_state_id.rb b/db/post_migrate/20190214112022_schedule_sync_issuables_state_id.rb new file mode 100644 index 00000000000..d9b77d2f02c --- /dev/null +++ b/db/post_migrate/20190214112022_schedule_sync_issuables_state_id.rb @@ -0,0 +1,43 @@ +# frozen_string_literal: true + +# See http://doc.gitlab.com/ce/development/migration_style_guide.html +# for more information on how to write migrations for GitLab. + +class ScheduleSyncIssuablesStateId < ActiveRecord::Migration[5.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + # 2019-02-12 Gitlab.com issuable numbers + # issues count: 13587305 + # merge requests count: 18925274 + # Using this 25000 as batch size should take around 26 hours + # to migrate both issues and merge requests + BATCH_SIZE = 25000 + DELAY_INTERVAL = 5.minutes.to_i + ISSUE_MIGRATION = 'SyncIssuesStateId'.freeze + MERGE_REQUEST_MIGRATION = 'SyncMergeRequestsStateId'.freeze + + class Issue < ActiveRecord::Base + include EachBatch + + self.table_name = 'issues' + end + + class MergeRequest < ActiveRecord::Base + include EachBatch + + self.table_name = 'merge_requests' + end + + def up + Sidekiq::Worker.skipping_transaction_check do + queue_background_migration_jobs_by_range_at_intervals(Issue.where(state_id: nil), ISSUE_MIGRATION, DELAY_INTERVAL, batch_size: BATCH_SIZE) + queue_background_migration_jobs_by_range_at_intervals(MergeRequest.where(state_id: nil), MERGE_REQUEST_MIGRATION, DELAY_INTERVAL, batch_size: BATCH_SIZE) + end + end + + def down + # No op + end +end diff --git a/db/schema.rb b/db/schema.rb index 0fb31ce2ef2..4a347e7289b 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20190211131150) do +ActiveRecord::Schema.define(version: 20190214112022) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" |