use rename_index method instead of writing SQL

Change-Id: I0e0bb97273908794ca81a60592be7ac871fa46d6
Reviewed-on: https://gerrit.instructure.com/26681
Tested-by: Jenkins <jenkins@instructure.com>
Reviewed-by: Rob Orton <rob@instructure.com>
QA-Review: Cody Cutrer <cody@instructure.com>
Product-Review: Cody Cutrer <cody@instructure.com>
This commit is contained in:
Cody Cutrer 2013-11-25 13:40:09 -07:00
parent 7a077d32bb
commit a7c4a85064
4 changed files with 7 additions and 17 deletions

View File

@ -15,7 +15,7 @@ class FixSubmissionVersionsIndex < ActiveRecord::Migration
:where => { :context_type => 'Course' },
:unique => true
connection.execute("DROP INDEX IF EXISTS index_submission_versions")
connection.execute("ALTER INDEX index_submission_versions2 RENAME TO index_submission_versions")
rename_index :submission_versions, 'index_submissions_version2', 'index_submission_versions'
end
end
end

View File

@ -3,7 +3,7 @@ class FixNameOfSisBatchesPendingIndex < ActiveRecord::Migration
def self.up
if connection.adapter_name == 'PostgreSQL' && connection.select_value("SELECT 1 FROM pg_class INNER JOIN pg_namespace ON relnamespace=pg_namespace.oid WHERE relname='index_sis_batches_on_account_id_and_created_at' AND nspname=ANY(current_schemas(false))")
execute("ALTER INDEX index_sis_batches_on_account_id_and_created_at RENAME TO index_sis_batches_pending_for_accounts")
rename_index :sis_batches, 'index_sis_batches_on_account_id_and_created_at', 'index_sis_batches_pending_for_accounts'
end
end
end

View File

@ -4,7 +4,7 @@ class FixAttachmentSortingIndexes < ActiveRecord::Migration
def self.up
if connection.adapter_name == 'PostgreSQL' && connection.select_value("SELECT 1 FROM pg_index WHERE indexrelid='index_attachments_on_folder_id_and_file_state_and_position'::regclass AND indpred IS NOT NULL")
execute("ALTER INDEX index_attachments_on_folder_id_and_file_state_and_position RENAME TO index_attachments_on_folder_id_and_file_state_and_position2")
rename_index :attachments, 'index_attachments_on_folder_id_and_file_state_and_position', 'index_attachments_on_folder_id_and_file_state_and_position2'
add_index :attachments, [:folder_id, :file_state, :position], :algorithm => :concurrently
remove_index :attachments, name: 'index_attachments_on_folder_id_and_file_state_and_position2'
end

View File

@ -7,13 +7,9 @@ class UpdateIcuSortableNameIndex < ActiveRecord::Migration
if connection.adapter_name == "PostgreSQLAdapter" &&
connection.select_value("SELECT COUNT(*) FROM pg_proc WHERE proname='collkey'").to_i != 0
concurrently = "CONCURRENTLY" if connection.open_transactions == 0
rename_index :users, 'index_users_on_sortable_name', 'index_users_on_sortable_name_old'
rename_index :attachments, 'index_attachments_on_folder_id_and_file_state_and_display_name', 'index_attachments_on_folder_id_and_file_state_and_display_name_old'
execute <<-SQL
ALTER INDEX index_users_on_sortable_name
RENAME TO index_users_on_sortable_name_old;
ALTER INDEX index_attachments_on_folder_id_and_file_state_and_display_name
RENAME TO index_attachments_on_folder_id_and_file_state_and_display_name_old;
CREATE INDEX #{concurrently} index_users_on_sortable_name
ON USERS (collkey(sortable_name, 'root', false, 0, true));
@ -33,14 +29,8 @@ class UpdateIcuSortableNameIndex < ActiveRecord::Migration
remove_index "users", :name => "index_users_on_sortable_name"
remove_index "users", :name => "index_attachments_on_folder_id_and_file_state_and_display_name"
execute <<-SQL
ALTER INDEX index_users_on_sortable_name_old
RENAME TO index_users_on_sortable_name;
ALTER INDEX
index_attachments_on_folder_id_and_file_state_and_display_name_old
RENAME TO index_attachments_on_folder_id_and_file_state_and_display_name
SQL
rename_index :users, 'index_users_on_sortable_name_old', 'index_users_on_sortable_name'
rename_index :attachments, 'index_attachments_on_folder_id_and_file_state_and_display_name_old', 'index_attachments_on_folder_id_and_file_state_and_display_name'
end
end
end