diff options
author | Brett Walker <bwalker@gitlab.com> | 2018-09-25 11:32:04 -0500 |
---|---|---|
committer | Brett Walker <bwalker@gitlab.com> | 2018-10-05 11:42:40 -0500 |
commit | f5abc2e8f99e67aaca8d5c5268f3aadb8302085d (patch) | |
tree | ebc79d609969c0f8af76a88fb5801b8c3dfe4f0d /db | |
parent | 059da9bc8eb9355a760031ef8e73b0aa6285012f (diff) | |
download | gitlab-ce-f5abc2e8f99e67aaca8d5c5268f3aadb8302085d.tar.gz |
Use a CTE to remove the query timeout
Diffstat (limited to 'db')
-rw-r--r-- | db/migrate/20181002172433_remove_restricted_todos_with_cte.rb | 32 | ||||
-rw-r--r-- | db/schema.rb | 2 |
2 files changed, 33 insertions, 1 deletions
diff --git a/db/migrate/20181002172433_remove_restricted_todos_with_cte.rb b/db/migrate/20181002172433_remove_restricted_todos_with_cte.rb new file mode 100644 index 00000000000..0a8f4a12266 --- /dev/null +++ b/db/migrate/20181002172433_remove_restricted_todos_with_cte.rb @@ -0,0 +1,32 @@ +# 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. + +# rescheduling of the revised RemoveRestrictedTodos background migration +class RemoveRestrictedTodosWithCte < ActiveRecord::Migration + DOWNTIME = false + disable_ddl_transaction! + + MIGRATION = 'RemoveRestrictedTodos'.freeze + BATCH_SIZE = 1000 + DELAY_INTERVAL = 5.minutes.to_i + + class Project < ActiveRecord::Base + include EachBatch + + self.table_name = 'projects' + end + + def up + Project.where('EXISTS (SELECT 1 FROM todos WHERE todos.project_id = projects.id)') + .each_batch(of: BATCH_SIZE) do |batch, index| + range = batch.pluck('MIN(id)', 'MAX(id)').first + + BackgroundMigrationWorker.perform_in(index * DELAY_INTERVAL, MIGRATION, range) + end + end + + def down + # nothing to do + end +end diff --git a/db/schema.rb b/db/schema.rb index 773bfb96b93..4ff0272428a 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20180924201039) do +ActiveRecord::Schema.define(version: 20181002172433) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" |