summaryrefslogtreecommitdiff
path: root/lib/gitlab/background_migration
diff options
context:
space:
mode:
authorFelipe Artur <felipefac@gmail.com>2019-02-11 15:48:37 -0200
committerFelipe Artur <felipefac@gmail.com>2019-02-11 15:48:40 -0200
commite9b84f50e961ee7c3abfb8192de8f4fc778df041 (patch)
tree7035d6ea15eb0e2ffbda561d4915c9597c6492a1 /lib/gitlab/background_migration
parentef875bd7aa24fd2c68027b8d6c837f33642a606e (diff)
downloadgitlab-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 'lib/gitlab/background_migration')
-rw-r--r--lib/gitlab/background_migration/sync_issuables_state_id.rb29
1 files changed, 29 insertions, 0 deletions
diff --git a/lib/gitlab/background_migration/sync_issuables_state_id.rb b/lib/gitlab/background_migration/sync_issuables_state_id.rb
new file mode 100644
index 00000000000..1ac86b8acf2
--- /dev/null
+++ b/lib/gitlab/background_migration/sync_issuables_state_id.rb
@@ -0,0 +1,29 @@
+# frozen_string_literal: true
+# rubocop:disable Style/Documentation
+
+module Gitlab
+ module BackgroundMigration
+ class SyncIssuablesStateId
+ def perform(start_id, end_id, model_class)
+ populate_new_state_id(start_id, end_id, model_class)
+ end
+
+ def populate_new_state_id(start_id, end_id, model_class)
+ Rails.logger.info("#{model_class.model_name.human} - Populating state_id: #{start_id} - #{end_id}")
+
+ ActiveRecord::Base.connection.execute <<~SQL
+ UPDATE #{model_class.table_name}
+ SET state_id =
+ CASE state
+ WHEN 'opened' THEN 1
+ WHEN 'closed' THEN 2
+ WHEN 'merged' THEN 3
+ WHEN 'locked' THEN 4
+ END
+ WHERE state_id IS NULL
+ AND id BETWEEN #{start_id} AND #{end_id}
+ SQL
+ end
+ end
+ end
+end