summaryrefslogtreecommitdiff
path: root/db/migrate/20181119132520_add_indexes_to_ci_builds_and_pipelines.rb
diff options
context:
space:
mode:
authorAndreas Brandl <abrandl@gitlab.com>2018-11-19 17:09:20 +0100
committerAndreas Brandl <abrandl@gitlab.com>2019-01-03 17:00:09 +0100
commit00b5026a9fe2e38f6baaef13a2d2450112cffca3 (patch)
treea4acaf37a3771078e53dc4bf56487a704136a5b7 /db/migrate/20181119132520_add_indexes_to_ci_builds_and_pipelines.rb
parent50f9817afb3d6cc599c499abf1536215eada5600 (diff)
downloadgitlab-ce-00b5026a9fe2e38f6baaef13a2d2450112cffca3.tar.gz
Add specific index namesab-50763-persist-index
This is useful to distinguish any other indexes on the same columns but with different conditions and/or sorting.
Diffstat (limited to 'db/migrate/20181119132520_add_indexes_to_ci_builds_and_pipelines.rb')
-rw-r--r--db/migrate/20181119132520_add_indexes_to_ci_builds_and_pipelines.rb33
1 files changed, 29 insertions, 4 deletions
diff --git a/db/migrate/20181119132520_add_indexes_to_ci_builds_and_pipelines.rb b/db/migrate/20181119132520_add_indexes_to_ci_builds_and_pipelines.rb
index 2134131b28f..adbc3928b26 100644
--- a/db/migrate/20181119132520_add_indexes_to_ci_builds_and_pipelines.rb
+++ b/db/migrate/20181119132520_add_indexes_to_ci_builds_and_pipelines.rb
@@ -8,12 +8,37 @@ class AddIndexesToCiBuildsAndPipelines < ActiveRecord::Migration
disable_ddl_transaction!
def up
- add_concurrent_index :ci_pipelines, [:project_id, :ref, :id], order: { id: :desc }
- add_concurrent_index :ci_builds, [:commit_id, :artifacts_expire_at, :id], where: "type = 'Ci::Build' AND (retried = false OR retried IS NULL) AND name IN ('sast', 'dependency_scanning', 'sast:container', 'container_scanning', 'dast')"
+ indexes.each do |index|
+ add_concurrent_index(*index)
+ end
end
def down
- remove_concurrent_index :ci_pipelines, [:project_id, :ref, :id], order: { id: :desc }
- remove_concurrent_index :ci_builds, [:commit_id, :artifacts_expire_at, :id], where: "type = 'Ci::Build' AND (retried = false OR retried IS NULL) AND name IN ('sast', 'dependency_scanning', 'sast:container', 'container_scanning', 'dast')"
+ indexes.each do |index|
+ remove_concurrent_index(*index)
+ end
+ end
+
+ private
+
+ def indexes
+ [
+ [
+ :ci_pipelines,
+ [:project_id, :ref, :id],
+ {
+ order: { id: :desc },
+ name: 'index_ci_pipelines_on_project_idandrefandiddesc'
+ }
+ ],
+ [
+ :ci_builds,
+ [:commit_id, :artifacts_expire_at, :id],
+ {
+ where: "type::text = 'Ci::Build'::text AND (retried = false OR retried IS NULL) AND (name::text = ANY (ARRAY['sast'::character varying, 'dependency_scanning'::character varying, 'sast:container'::character varying, 'container_scanning'::character varying, 'dast'::character varying]::text[]))",
+ name: 'index_ci_builds_on_commit_id_and_artifacts_expireatandidpartial'
+ }
+ ]
+ ]
end
end