summaryrefslogtreecommitdiff
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
parent50f9817afb3d6cc599c499abf1536215eada5600 (diff)
downloadgitlab-ce-ab-50763-persist-index.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.
-rw-r--r--db/migrate/20181119132520_add_indexes_to_ci_builds_and_pipelines.rb33
-rw-r--r--db/schema.rb4
2 files changed, 31 insertions, 6 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
diff --git a/db/schema.rb b/db/schema.rb
index e6be4b20c86..dbc0242172c 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -349,7 +349,7 @@ ActiveRecord::Schema.define(version: 20181219145520) do
t.string "token_encrypted"
t.index ["artifacts_expire_at"], name: "index_ci_builds_on_artifacts_expire_at", where: "(artifacts_file <> ''::text)", using: :btree
t.index ["auto_canceled_by_id"], name: "index_ci_builds_on_auto_canceled_by_id", using: :btree
- t.index ["commit_id", "artifacts_expire_at", "id"], name: "index_ci_builds_on_commit_id_and_artifacts_expire_at_and_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[])))", using: :btree
+ t.index ["commit_id", "artifacts_expire_at", "id"], name: "index_ci_builds_on_commit_id_and_artifacts_expireatandidpartial", where: "(((type)::text = 'Ci::Build'::text) AND ((retried = false) OR (retried IS NULL)) AND ((name)::text = ANY (ARRAY[('sast'::character varying)::text, ('dependency_scanning'::character varying)::text, ('sast:container'::character varying)::text, ('container_scanning'::character varying)::text, ('dast'::character varying)::text])))", using: :btree
t.index ["commit_id", "stage_idx", "created_at"], name: "index_ci_builds_on_commit_id_and_stage_idx_and_created_at", using: :btree
t.index ["commit_id", "status", "type"], name: "index_ci_builds_on_commit_id_and_status_and_type", using: :btree
t.index ["commit_id", "type", "name", "ref"], name: "index_ci_builds_on_commit_id_and_type_and_name_and_ref", using: :btree
@@ -484,7 +484,7 @@ ActiveRecord::Schema.define(version: 20181219145520) do
t.index ["merge_request_id"], name: "index_ci_pipelines_on_merge_request_id", where: "(merge_request_id IS NOT NULL)", using: :btree
t.index ["pipeline_schedule_id"], name: "index_ci_pipelines_on_pipeline_schedule_id", using: :btree
t.index ["project_id", "iid"], name: "index_ci_pipelines_on_project_id_and_iid", unique: true, where: "(iid IS NOT NULL)", using: :btree
- t.index ["project_id", "ref", "id"], name: "index_ci_pipelines_on_project_id_and_ref_and_id", order: { id: :desc }, using: :btree
+ t.index ["project_id", "ref", "id"], name: "index_ci_pipelines_on_project_idandrefandiddesc", order: { id: :desc }, using: :btree
t.index ["project_id", "ref", "status", "id"], name: "index_ci_pipelines_on_project_id_and_ref_and_status_and_id", using: :btree
t.index ["project_id", "sha"], name: "index_ci_pipelines_on_project_id_and_sha", using: :btree
t.index ["project_id", "source"], name: "index_ci_pipelines_on_project_id_and_source", using: :btree