Permalink
Browse files

Improve indexes on sent_emails, better column ordering, removed dupli…

…cates.
  • Loading branch information...
1 parent 9337d90 commit 70a36d3c2483718a1687451a54a49b0de0d7173a Mark Steckel committed Aug 20, 2013
Showing with 20 additions and 0 deletions.
  1. +20 −0 db/migrate/20130820193236_update_sent_emails_indexes.rb
@@ -0,0 +1,20 @@
+class UpdateSentEmailsIndexes < ActiveRecord::Migration
+ def up
+ add_index :sent_emails, [:created_at, :type], algorithm: :concurrently
+
+ # Using raw sql for 'IF EXISTS'
+ execute 'DROP INDEX IF EXISTS index_sent_emails_on_type_and_created_at'
+ execute 'DROP INDEX IF EXISTS index_sent_emails_on_created_at'
+
+ # These indexes exist on production and duplicate other indexes
+ execute 'DROP INDEX IF EXISTS sent_emails_member_id_idx'
+ execute 'DROP INDEX IF EXISTS sent_emails_created_idx'
+ end
+
+ def down
+ add_index :sent_emails, [:type, :created_at], algorithm: :concurrently
+ add_index :sent_emails, [:created_at], algorithm: :concurrently
+ # Using raw sql for 'IF EXISTS'
+ execute 'DROP INDEX IF EXISTS index_sent_emails_on_created_at_and_type'
+ end
+end

0 comments on commit 70a36d3

Please sign in to comment.