diff options
author | Sean McGivern <sean@mcgivern.me.uk> | 2017-09-29 08:57:52 +0000 |
---|---|---|
committer | Sean McGivern <sean@mcgivern.me.uk> | 2017-09-29 08:57:52 +0000 |
commit | ccfe6860079c6c75ab5a1f831cd62af0e355331e (patch) | |
tree | dbbb542464fbda42ef9bba549f8379ac7e400381 /db | |
parent | 8a7ca539653cc19db242123328bff2b6dd8fcf82 (diff) | |
parent | abcfdd5c17020abbcb3f39eaa976cb49a0917a2a (diff) | |
download | gitlab-ce-ccfe6860079c6c75ab5a1f831cd62af0e355331e.tar.gz |
Merge branch 'add-composite-index-on-merge-requests-merge-commit-sha' into 'master'
Add index for merge_requests.merge_commit_sha
Closes #38507
See merge request gitlab-org/gitlab-ce!14549
Diffstat (limited to 'db')
-rw-r--r-- | db/migrate/20170928100231_add_composite_index_on_merge_requests_merge_commit_sha.rb | 33 | ||||
-rw-r--r-- | db/schema.rb | 3 |
2 files changed, 35 insertions, 1 deletions
diff --git a/db/migrate/20170928100231_add_composite_index_on_merge_requests_merge_commit_sha.rb b/db/migrate/20170928100231_add_composite_index_on_merge_requests_merge_commit_sha.rb new file mode 100644 index 00000000000..9f02daf04c1 --- /dev/null +++ b/db/migrate/20170928100231_add_composite_index_on_merge_requests_merge_commit_sha.rb @@ -0,0 +1,33 @@ +# See http://doc.gitlab.com/ce/development/migration_style_guide.html +# for more information on how to write migrations for GitLab. + +class AddCompositeIndexOnMergeRequestsMergeCommitSha < ActiveRecord::Migration + include Gitlab::Database::MigrationHelpers + + # Set this constant to true if this migration requires downtime. + DOWNTIME = false + + # The default index name is too long for PostgreSQL and would thus be + # truncated. + INDEX_NAME = 'index_merge_requests_on_tp_id_and_merge_commit_sha_and_id' + + COLUMNS = [:target_project_id, :merge_commit_sha, :id] + + disable_ddl_transaction! + + def up + return if index_is_present? + + add_concurrent_index(:merge_requests, COLUMNS, name: INDEX_NAME) + end + + def down + return unless index_is_present? + + remove_concurrent_index(:merge_requests, COLUMNS, name: INDEX_NAME) + end + + def index_is_present? + index_exists?(:merge_requests, COLUMNS, name: INDEX_NAME) + end +end diff --git a/db/schema.rb b/db/schema.rb index d14d4d8b94d..e8e64b9d36b 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: 20170921115009) do +ActiveRecord::Schema.define(version: 20170928100231) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -895,6 +895,7 @@ ActiveRecord::Schema.define(version: 20170921115009) do add_index "merge_requests", ["source_project_id", "source_branch"], name: "index_merge_requests_on_source_project_id_and_source_branch", using: :btree add_index "merge_requests", ["target_branch"], name: "index_merge_requests_on_target_branch", using: :btree add_index "merge_requests", ["target_project_id", "iid"], name: "index_merge_requests_on_target_project_id_and_iid", unique: true, using: :btree + add_index "merge_requests", ["target_project_id", "merge_commit_sha", "id"], name: "index_merge_requests_on_tp_id_and_merge_commit_sha_and_id", using: :btree add_index "merge_requests", ["title"], name: "index_merge_requests_on_title", using: :btree add_index "merge_requests", ["title"], name: "index_merge_requests_on_title_trigram", using: :gin, opclasses: {"title"=>"gin_trgm_ops"} |