From 9b1e8c735065a0611495795d33ed9940e614d9e0 Mon Sep 17 00:00:00 2001 From: Cody Cutrer Date: Thu, 10 Jul 2014 10:24:23 -0600 Subject: [PATCH] more fk indexes also fix an old migration that should have ran on all shards Change-Id: Ib4305c4f1b84ba0cfd525d0f552cfc21d365dc24 Reviewed-on: https://gerrit.instructure.com/37492 Tested-by: Jenkins Reviewed-by: Jeremy Stanley Reviewed-by: Brian Palmer Product-Review: Cody Cutrer QA-Review: Cody Cutrer --- ...727145852_add_unique_index_on_notifications.rb} | 2 -- .../20140710153035_add_foreign_key_indexes3.rb | 14 ++++++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) rename db/migrate/{20120727145851_add_unique_index_on_notifications.rb => 20120727145852_add_unique_index_on_notifications.rb} (85%) create mode 100644 db/migrate/20140710153035_add_foreign_key_indexes3.rb diff --git a/db/migrate/20120727145851_add_unique_index_on_notifications.rb b/db/migrate/20120727145852_add_unique_index_on_notifications.rb similarity index 85% rename from db/migrate/20120727145851_add_unique_index_on_notifications.rb rename to db/migrate/20120727145852_add_unique_index_on_notifications.rb index 8865913982d..e4252d0831e 100644 --- a/db/migrate/20120727145851_add_unique_index_on_notifications.rb +++ b/db/migrate/20120727145852_add_unique_index_on_notifications.rb @@ -2,14 +2,12 @@ class AddUniqueIndexOnNotifications < ActiveRecord::Migration tag :postdeploy def self.up - return unless Shard.current.default? # the excess subquery is necessary to avoid error 1093 on mysql Notification.where("id NOT IN (SELECT * FROM (SELECT MIN(id) FROM notifications GROUP BY name) x)").delete_all add_index :notifications, [:name], :unique => true, :name => "index_notifications_unique_on_name" end def self.down - return unless Shard.current.default? remove_index :notifications, :name => "index_notifications_unique_on_name" end end diff --git a/db/migrate/20140710153035_add_foreign_key_indexes3.rb b/db/migrate/20140710153035_add_foreign_key_indexes3.rb new file mode 100644 index 00000000000..ad650162771 --- /dev/null +++ b/db/migrate/20140710153035_add_foreign_key_indexes3.rb @@ -0,0 +1,14 @@ +class AddForeignKeyIndexes3 < ActiveRecord::Migration + tag :postdeploy + disable_ddl_transaction! + + def self.up + add_index :account_reports, :attachment_id, algorithm: :concurrently + add_index :zip_file_imports, :attachment_id, algorithm: :concurrently + end + + def self.down + remove_index :account_reports, :attachment_id + remove_index :zip_file_imports, :attachment_id + end +end