diff options
author | Felipe Artur <felipefac@gmail.com> | 2019-02-11 15:48:37 -0200 |
---|---|---|
committer | Felipe Artur <felipefac@gmail.com> | 2019-02-11 15:48:40 -0200 |
commit | e9b84f50e961ee7c3abfb8192de8f4fc778df041 (patch) | |
tree | 7035d6ea15eb0e2ffbda561d4915c9597c6492a1 /db/migrate | |
parent | ef875bd7aa24fd2c68027b8d6c837f33642a606e (diff) | |
download | gitlab-ce-e9b84f50e961ee7c3abfb8192de8f4fc778df041.tar.gz |
Migrate issuable states to integer patch 1
Patch 1 that migrates issues/merge requests states from integer to string.
On this commit we are only adding the state_id column and syncing it with a backgroud migration.
On Patch 2 the code to use the new integer column will be deployed and the old column will be
removed.
Diffstat (limited to 'db/migrate')
-rw-r--r-- | db/migrate/20190211131150_add_state_id_to_issuables.rb | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/db/migrate/20190211131150_add_state_id_to_issuables.rb b/db/migrate/20190211131150_add_state_id_to_issuables.rb new file mode 100644 index 00000000000..af02aa84afd --- /dev/null +++ b/db/migrate/20190211131150_add_state_id_to_issuables.rb @@ -0,0 +1,37 @@ +class AddStateIdToIssuables < ActiveRecord::Migration[5.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + MIGRATION = 'SyncIssuablesStateId'.freeze + + # TODO - find out how many issues and merge requests in production + # to adapt the batch size and delay interval + # Keep in mind that the migration will be scheduled for issues and merge requests. + BATCH_SIZE = 5000 + 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: 1 + add_column :merge_requests, :state_id, :integer, limit: 1 + + 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 + + def down + remove_column :issues, :state_id + remove_column :merge_requests, :state_id + end +end |