Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/db
diff options
context:
space:
mode:
authorSean McGivern <sean@gitlab.com>2019-04-02 11:39:53 +0300
committerSean McGivern <sean@gitlab.com>2019-04-02 11:39:53 +0300
commitf87b7fe3b386962c45e83486634352da544857fb (patch)
tree4c3fc969e0306e9877d22f787e8064126bfdef75 /db
parent5ddd4f0f0708921ca0c8a9a941cfb4c0fb868b00 (diff)
parentf2b7da4bf507691cffd419d3dd759fcf6311cdd6 (diff)
Merge branch 'issue_51789_part_1' into 'master'
Migrate issuable states to integer patch 1 of 2 Closes #51789 See merge request gitlab-org/gitlab-ce!25107
Diffstat (limited to 'db')
-rw-r--r--db/migrate/20190211131150_add_state_id_to_issuables.rb17
-rw-r--r--db/post_migrate/20190214112022_schedule_sync_issuables_state_id.rb56
-rw-r--r--db/schema.rb2
3 files changed, 75 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..c1173eb4249
--- /dev/null
+++ b/db/migrate/20190211131150_add_state_id_to_issuables.rb
@@ -0,0 +1,17 @@
+# frozen_string_literal: true
+
+class AddStateIdToIssuables < ActiveRecord::Migration[5.0]
+ include Gitlab::Database::MigrationHelpers
+
+ DOWNTIME = false
+
+ def up
+ add_column :issues, :state_id, :integer, limit: 2
+ add_column :merge_requests, :state_id, :integer, limit: 2
+ end
+
+ def down
+ remove_column :issues, :state_id
+ remove_column :merge_requests, :state_id
+ end
+end
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..6edb0bf2d5e
--- /dev/null
+++ b/db/post_migrate/20190214112022_schedule_sync_issuables_state_id.rb
@@ -0,0 +1,56 @@
+class ScheduleSyncIssuablesStateId < ActiveRecord::Migration[5.0]
+ # This migration schedules the sync of state_id for issues and merge requests
+ # which are converting the state column from string to integer.
+ # For more information check: https://gitlab.com/gitlab-org/gitlab-ce/issues/51789
+
+ include Gitlab::Database::MigrationHelpers
+
+ DOWNTIME = false
+
+ # 2019-02-12 gitlab.com issuable numbers
+ # issues count: 13587305
+ # merge requests count: 18925274
+ #
+ # Using 5000 as batch size and 115 seconds interval will give:
+ # 2718 jobs for issues - taking ~86 hours
+ # 3786 jobs for merge requests - taking ~120 hours
+ #
+ BATCH_SIZE = 5000
+ DELAY_INTERVAL = 120.seconds.to_i
+ ISSUES_MIGRATION = 'SyncIssuesStateId'.freeze
+ MERGE_REQUESTS_MIGRATION = 'SyncMergeRequestsStateId'.freeze
+
+ disable_ddl_transaction!
+
+ 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
+ queue_background_migration_jobs_by_range_at_intervals(
+ Issue.all,
+ ISSUES_MIGRATION,
+ DELAY_INTERVAL,
+ batch_size: BATCH_SIZE
+ )
+
+ queue_background_migration_jobs_by_range_at_intervals(
+ MergeRequest.all,
+ MERGE_REQUESTS_MIGRATION,
+ DELAY_INTERVAL,
+ batch_size: BATCH_SIZE
+ )
+ end
+
+ def down
+ # No op
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index 8197e860996..1ca7be9c2af 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -1069,6 +1069,7 @@ ActiveRecord::Schema.define(version: 20190325165127) do
t.boolean "discussion_locked"
t.datetime_with_timezone "closed_at"
t.integer "closed_by_id"
+ t.integer "state_id", limit: 2
t.index ["author_id"], name: "index_issues_on_author_id", using: :btree
t.index ["closed_by_id"], name: "index_issues_on_closed_by_id", using: :btree
t.index ["confidential"], name: "index_issues_on_confidential", using: :btree
@@ -1317,6 +1318,7 @@ ActiveRecord::Schema.define(version: 20190325165127) do
t.string "rebase_commit_sha"
t.boolean "squash", default: false, null: false
t.boolean "allow_maintainer_to_push"
+ t.integer "state_id", limit: 2
t.index ["assignee_id"], name: "index_merge_requests_on_assignee_id", using: :btree
t.index ["author_id"], name: "index_merge_requests_on_author_id", using: :btree
t.index ["created_at"], name: "index_merge_requests_on_created_at", using: :btree