Separate adding and removing index from stages migration

This commit is contained in:
Grzegorz Bizon 2018-02-20 13:53:54 +01:00
parent 2d027056f9
commit 2f3f9a6bb0
4 changed files with 29 additions and 6 deletions

View File

@ -0,0 +1,14 @@
class AddTmpPartialNullIndexToBuilds < ActiveRecord::Migration
include Gitlab::Database::MigrationHelpers
disable_ddl_transaction!
def up
add_concurrent_index(:ci_builds, :stage_id, where: 'stage_id IS NULL',
name: 'tmp_stage_id_partial_null_index')
end
def down
remove_concurrent_index_by_name(:ci_builds, 'tmp_stage_id_partial_null_index')
end
end

View File

@ -15,17 +15,12 @@ class ScheduleBuildStageMigration < ActiveRecord::Migration
def up
disable_statement_timeout
add_concurrent_index(:ci_builds, :stage_id, where: 'stage_id IS NULL',
name: 'tmp_stage_id_partial_null_index')
Build.where('stage_id IS NULL').tap do |relation|
queue_background_migration_jobs_by_range_at_intervals(relation,
MIGRATION,
5.minutes,
batch_size: BATCH_SIZE)
end
remove_concurrent_index_by_name(:ci_builds, 'tmp_stage_id_partial_null_index')
end
def down

View File

@ -0,0 +1,14 @@
class RemoveTmpPartialNullIndexFromBuilds < ActiveRecord::Migration
include Gitlab::Database::MigrationHelpers
disable_ddl_transaction!
def up
remove_concurrent_index_by_name(:ci_builds, 'tmp_stage_id_partial_null_index')
end
def down
add_concurrent_index(:ci_builds, :stage_id, where: 'stage_id IS NULL',
name: 'tmp_stage_id_partial_null_index')
end
end

View File

@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20180212101928) do
ActiveRecord::Schema.define(version: 20180212102028) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"