diff options
Diffstat (limited to 'db/post_migrate/20210311093723_add_partial_index_on_ci_pipelines_by_cancelable_status_and_users.rb')
-rw-r--r-- | db/post_migrate/20210311093723_add_partial_index_on_ci_pipelines_by_cancelable_status_and_users.rb | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/db/post_migrate/20210311093723_add_partial_index_on_ci_pipelines_by_cancelable_status_and_users.rb b/db/post_migrate/20210311093723_add_partial_index_on_ci_pipelines_by_cancelable_status_and_users.rb new file mode 100644 index 00000000000..176548be6e6 --- /dev/null +++ b/db/post_migrate/20210311093723_add_partial_index_on_ci_pipelines_by_cancelable_status_and_users.rb @@ -0,0 +1,30 @@ +# frozen_string_literal: true + +class AddPartialIndexOnCiPipelinesByCancelableStatusAndUsers < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + INDEX_NAME = 'index_ci_pipelines_on_user_id_and_id_and_cancelable_status' + INDEX_FILTER_CONDITION = <<~SQL + ((status)::text = ANY ( + ARRAY[ + ('running'::character varying)::text, + ('waiting_for_resource'::character varying)::text, + ('preparing'::character varying)::text, + ('pending'::character varying)::text, + ('created'::character varying)::text, + ('scheduled'::character varying)::text + ] + )) + SQL + + disable_ddl_transaction! + + def up + add_concurrent_index :ci_pipelines, [:user_id, :id], where: INDEX_FILTER_CONDITION, name: INDEX_NAME + end + + def down + remove_concurrent_index_by_name :ci_pipelines, INDEX_NAME + end +end |