summaryrefslogtreecommitdiff
path: root/db
diff options
context:
space:
mode:
authorAsh McKenzie <amckenzie@gitlab.com>2019-06-17 01:19:47 +0000
committerAsh McKenzie <amckenzie@gitlab.com>2019-06-18 09:26:07 +1000
commita8ae921d99cb187226edfec4b075b0c01e83330a (patch)
tree481036c18b15e7ba3b82c9eb0fff71d3c38515e7 /db
parent30bddd546f117043f2b7389ad06ba5257184c148 (diff)
downloadgitlab-ce-a8ae921d99cb187226edfec4b075b0c01e83330a.tar.gz
Add index to events and audit_events tablesashmckenzie/add-created-at-index-to-events
Index on created_at, author_id
Diffstat (limited to 'db')
-rw-r--r--db/post_migrate/20190611161642_add_index_to_events_and_audit_events_created_at_author_id.rb25
-rw-r--r--db/schema.rb2
2 files changed, 27 insertions, 0 deletions
diff --git a/db/post_migrate/20190611161642_add_index_to_events_and_audit_events_created_at_author_id.rb b/db/post_migrate/20190611161642_add_index_to_events_and_audit_events_created_at_author_id.rb
new file mode 100644
index 00000000000..342e83d6322
--- /dev/null
+++ b/db/post_migrate/20190611161642_add_index_to_events_and_audit_events_created_at_author_id.rb
@@ -0,0 +1,25 @@
+# frozen_string_literal: true
+
+# See http://doc.gitlab.com/ce/development/migration_style_guide.html
+# for more information on how to write migrations for GitLab.
+
+class AddIndexToEventsAndAuditEventsCreatedAtAuthorId < ActiveRecord::Migration[5.1]
+ include Gitlab::Database::MigrationHelpers
+
+ DOWNTIME = false
+ INDEX_NAME = 'analytics_index_%s_on_created_at_and_author_id'.freeze
+ EVENTS_INDEX_NAME = (INDEX_NAME % 'events').freeze
+ AUDIT_EVENTS_INDEX_NAME = (INDEX_NAME % 'audit_events').freeze
+
+ disable_ddl_transaction!
+
+ def up
+ add_concurrent_index :events, [:created_at, :author_id], name: EVENTS_INDEX_NAME
+ add_concurrent_index :audit_events, [:created_at, :author_id], name: AUDIT_EVENTS_INDEX_NAME
+ end
+
+ def down
+ remove_concurrent_index_by_name :events, EVENTS_INDEX_NAME
+ remove_concurrent_index_by_name :audit_events, AUDIT_EVENTS_INDEX_NAME
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index c6186c52699..d1c13f44ab2 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -335,6 +335,7 @@ ActiveRecord::Schema.define(version: 20190613030606) do
t.text "details"
t.datetime "created_at"
t.datetime "updated_at"
+ t.index ["created_at", "author_id"], name: "analytics_index_audit_events_on_created_at_and_author_id", using: :btree
t.index ["entity_id", "entity_type"], name: "index_audit_events_on_entity_id_and_entity_type", using: :btree
end
@@ -1219,6 +1220,7 @@ ActiveRecord::Schema.define(version: 20190613030606) do
t.string "target_type"
t.index ["action"], name: "index_events_on_action", using: :btree
t.index ["author_id", "project_id"], name: "index_events_on_author_id_and_project_id", using: :btree
+ t.index ["created_at", "author_id"], name: "analytics_index_events_on_created_at_and_author_id", using: :btree
t.index ["project_id", "created_at"], name: "index_events_on_project_id_and_created_at", using: :btree
t.index ["project_id", "id"], name: "index_events_on_project_id_and_id", using: :btree
t.index ["target_type", "target_id"], name: "index_events_on_target_type_and_target_id", using: :btree