summaryrefslogtreecommitdiff
path: root/db
diff options
context:
space:
mode:
Diffstat (limited to 'db')
-rw-r--r--db/migrate/20190211131150_add_state_id_to_issuables.rb37
-rw-r--r--db/schema.rb4
2 files changed, 40 insertions, 1 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
diff --git a/db/schema.rb b/db/schema.rb
index 023eee5f33e..0fb31ce2ef2 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: 20190204115450) do
+ActiveRecord::Schema.define(version: 20190211131150) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@@ -1046,6 +1046,7 @@ ActiveRecord::Schema.define(version: 20190204115450) 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
@@ -1283,6 +1284,7 @@ ActiveRecord::Schema.define(version: 20190204115450) 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