add if_not_exists option to add_index
and use it in recent non-transactional migrations Change-Id: Ie96e3cbf727403c5dfe9d04bc3403170c076d5b6 Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/239560 Tested-by: Service Cloud Jenkins <svc.cloudjenkins@instructure.com> Reviewed-by: Simon Williams <simon@instructure.com> QA-Review: Simon Williams <simon@instructure.com> Product-Review: Simon Williams <simon@instructure.com>
This commit is contained in:
parent
d85aa95894
commit
1ac2a1b581
|
@ -181,26 +181,29 @@ module PostgreSQLAdapterExtensions
|
|||
|
||||
def add_index(table_name, column_name, options = {})
|
||||
# catch a concurrent index add that fails because it already exists, and is invalid
|
||||
if options[:algorithm] == :concurrently
|
||||
if options[:algorithm] == :concurrently || options[:if_not_exists]
|
||||
column_names = index_column_names(column_name)
|
||||
index_name = options[:name].to_s if options.key?(:name)
|
||||
index_name ||= index_name(table_name, column_names)
|
||||
|
||||
schema = shard.name if use_qualified_names?
|
||||
|
||||
exists = exec_query(<<-SQL, 'SCHEMA').rows.first[0].to_i > 0
|
||||
SELECT COUNT(*)
|
||||
valid = select_value(<<-SQL, 'SCHEMA')
|
||||
SELECT indisvalid
|
||||
FROM pg_class t
|
||||
INNER JOIN pg_index d ON t.oid = d.indrelid
|
||||
INNER JOIN pg_class i ON d.indexrelid = i.oid
|
||||
WHERE i.relkind = 'i'
|
||||
AND i.relname = '#{index_name}'
|
||||
AND t.relname = '#{table_name}'
|
||||
AND NOT indisvalid
|
||||
AND i.relnamespace IN (SELECT oid FROM pg_namespace WHERE nspname = #{schema ? "'#{schema}'" : 'ANY (current_schemas(false))'} )
|
||||
LIMIT 1
|
||||
SQL
|
||||
remove_index(table_name, name: index_name, algorithm: :concurrently) if exists
|
||||
remove_index(table_name, name: index_name, algorithm: :concurrently) if valid == false && options[:algorithm] == :concurrently
|
||||
return if options[:if_not_exists] && valid == true
|
||||
end
|
||||
# CANVAS_RAILS6_1: can stop doing this in Rails 6.2, when it's natively supported
|
||||
options.delete(:if_not_exists)
|
||||
super
|
||||
end
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@ class AddRootAccountIdToWikis < ActiveRecord::Migration[5.2]
|
|||
|
||||
def up
|
||||
add_column_and_fk :wikis, :root_account_id, :accounts, if_not_exists: true
|
||||
add_index :wikis, :root_account_id, algorithm: :concurrently
|
||||
add_index :wikis, :root_account_id, algorithm: :concurrently, if_not_exists: true
|
||||
end
|
||||
|
||||
def down
|
||||
|
|
|
@ -23,7 +23,7 @@ class AddRootAccountIdToWikiPages < ActiveRecord::Migration[5.2]
|
|||
|
||||
def up
|
||||
add_column_and_fk :wiki_pages, :root_account_id, :accounts, if_not_exists: true
|
||||
add_index :wiki_pages, :root_account_id, algorithm: :concurrently
|
||||
add_index :wiki_pages, :root_account_id, algorithm: :concurrently, if_not_exists: true
|
||||
end
|
||||
|
||||
def down
|
||||
|
|
|
@ -23,7 +23,7 @@ class AddRootAccountIdToRubrics < ActiveRecord::Migration[5.2]
|
|||
|
||||
def up
|
||||
add_column_and_fk :rubrics, :root_account_id, :accounts, if_not_exists: true
|
||||
add_index :rubrics, :root_account_id, algorithm: :concurrently
|
||||
add_index :rubrics, :root_account_id, algorithm: :concurrently, if_not_exists: true
|
||||
end
|
||||
|
||||
def down
|
||||
|
|
|
@ -23,7 +23,7 @@ class AddRootAccountIdToRubricAssociations < ActiveRecord::Migration[5.2]
|
|||
|
||||
def up
|
||||
add_column_and_fk :rubric_associations, :root_account_id, :accounts, if_not_exists: true
|
||||
add_index :rubric_associations, :root_account_id, algorithm: :concurrently
|
||||
add_index :rubric_associations, :root_account_id, algorithm: :concurrently, if_not_exists: true
|
||||
end
|
||||
|
||||
def down
|
||||
|
|
|
@ -23,7 +23,7 @@ class AddRootAccountIdToRubricAssessments < ActiveRecord::Migration[5.2]
|
|||
|
||||
def up
|
||||
add_column_and_fk :rubric_assessments, :root_account_id, :accounts, if_not_exists: true
|
||||
add_index :rubric_assessments, :root_account_id, algorithm: :concurrently
|
||||
add_index :rubric_assessments, :root_account_id, algorithm: :concurrently, if_not_exists: true
|
||||
end
|
||||
|
||||
def down
|
||||
|
|
|
@ -23,7 +23,7 @@ class AddRootAccountIdToMasterCoursesMigrationResults < ActiveRecord::Migration[
|
|||
|
||||
def up
|
||||
add_column_and_fk :master_courses_migration_results, :root_account_id, :accounts, if_not_exists: true
|
||||
add_index :master_courses_migration_results, :root_account_id, algorithm: :concurrently
|
||||
add_index :master_courses_migration_results, :root_account_id, algorithm: :concurrently, if_not_exists: true
|
||||
end
|
||||
|
||||
def down
|
||||
|
|
|
@ -23,7 +23,7 @@ class AddRootAccountIdToMasterCoursesMasterTemplates < ActiveRecord::Migration[5
|
|||
|
||||
def up
|
||||
add_column_and_fk :master_courses_master_templates, :root_account_id, :accounts, if_not_exists: true
|
||||
add_index :master_courses_master_templates, :root_account_id, algorithm: :concurrently
|
||||
add_index :master_courses_master_templates, :root_account_id, algorithm: :concurrently, if_not_exists: true
|
||||
end
|
||||
|
||||
def down
|
||||
|
|
|
@ -23,7 +23,7 @@ class AddRootAccountIdToMasterCoursesMasterContentTags < ActiveRecord::Migration
|
|||
|
||||
def up
|
||||
add_column_and_fk :master_courses_master_content_tags, :root_account_id, :accounts, if_not_exists: true
|
||||
add_index :master_courses_master_content_tags, :root_account_id, algorithm: :concurrently
|
||||
add_index :master_courses_master_content_tags, :root_account_id, algorithm: :concurrently, if_not_exists: true
|
||||
end
|
||||
|
||||
def down
|
||||
|
|
|
@ -22,7 +22,7 @@ class AddRootAccountIdToQuizzes < ActiveRecord::Migration[5.2]
|
|||
|
||||
def up
|
||||
add_column_and_fk :quizzes, :root_account_id, :accounts, if_not_exists: true
|
||||
add_index :quizzes, :root_account_id, algorithm: :concurrently
|
||||
add_index :quizzes, :root_account_id, algorithm: :concurrently, if_not_exists: true
|
||||
end
|
||||
|
||||
def down
|
||||
|
|
|
@ -22,7 +22,7 @@ class AddRootAccountIdToQuizQuestions < ActiveRecord::Migration[5.2]
|
|||
|
||||
def up
|
||||
add_column_and_fk :quiz_questions, :root_account_id, :accounts, if_not_exists: true
|
||||
add_index :quiz_questions, :root_account_id, algorithm: :concurrently
|
||||
add_index :quiz_questions, :root_account_id, algorithm: :concurrently, if_not_exists: true
|
||||
end
|
||||
|
||||
def down
|
||||
|
|
|
@ -22,7 +22,7 @@ class AddRootAccountIdToQuizGroups < ActiveRecord::Migration[5.2]
|
|||
|
||||
def up
|
||||
add_column_and_fk :quiz_groups, :root_account_id, :accounts, if_not_exists: true
|
||||
add_index :quiz_groups, :root_account_id, algorithm: :concurrently
|
||||
add_index :quiz_groups, :root_account_id, algorithm: :concurrently, if_not_exists: true
|
||||
end
|
||||
|
||||
def down
|
||||
|
|
|
@ -22,7 +22,7 @@ class AddRootAccountIdToQuizSubmissions < ActiveRecord::Migration[5.2]
|
|||
|
||||
def up
|
||||
add_column_and_fk :quiz_submissions, :root_account_id, :accounts, if_not_exists: true
|
||||
add_index :quiz_submissions, :root_account_id, algorithm: :concurrently
|
||||
add_index :quiz_submissions, :root_account_id, algorithm: :concurrently, if_not_exists: true
|
||||
end
|
||||
|
||||
def down
|
||||
|
|
|
@ -22,7 +22,7 @@ class AddRootAccountIdToAssessmentQuestionBanks < ActiveRecord::Migration[5.2]
|
|||
|
||||
def up
|
||||
add_column_and_fk :assessment_question_banks, :root_account_id, :accounts, if_not_exists: true
|
||||
add_index :assessment_question_banks, :root_account_id, algorithm: :concurrently
|
||||
add_index :assessment_question_banks, :root_account_id, algorithm: :concurrently, if_not_exists: true
|
||||
end
|
||||
|
||||
def down
|
||||
|
|
|
@ -22,7 +22,7 @@ class AddRootAccountIdToAssessmentQuestions < ActiveRecord::Migration[5.2]
|
|||
|
||||
def up
|
||||
add_column_and_fk :assessment_questions, :root_account_id, :accounts, if_not_exists: true
|
||||
add_index :assessment_questions, :root_account_id, algorithm: :concurrently
|
||||
add_index :assessment_questions, :root_account_id, algorithm: :concurrently, if_not_exists: true
|
||||
end
|
||||
|
||||
def down
|
||||
|
|
|
@ -23,7 +23,7 @@ class AddRootAccountIdToMasterCoursesChildSubscriptions < ActiveRecord::Migratio
|
|||
|
||||
def up
|
||||
add_column_and_fk :master_courses_child_subscriptions, :root_account_id, :accounts, if_not_exists: true
|
||||
add_index :master_courses_child_subscriptions, :root_account_id, algorithm: :concurrently
|
||||
add_index :master_courses_child_subscriptions, :root_account_id, algorithm: :concurrently, if_not_exists: true
|
||||
end
|
||||
|
||||
def down
|
||||
|
|
|
@ -22,7 +22,7 @@ class AddRootAccountIdToContentTags < ActiveRecord::Migration[5.2]
|
|||
|
||||
def up
|
||||
add_column_and_fk :content_tags, :root_account_id, :accounts, if_not_exists: true
|
||||
add_index :content_tags, :root_account_id, algorithm: :concurrently
|
||||
add_index :content_tags, :root_account_id, algorithm: :concurrently, if_not_exists: true
|
||||
end
|
||||
|
||||
def down
|
||||
|
|
|
@ -22,7 +22,7 @@ class AddRootAccountIdToDeveloperKeyAccountBindings < ActiveRecord::Migration[5.
|
|||
|
||||
def up
|
||||
add_column_and_fk :developer_key_account_bindings, :root_account_id, :accounts, if_not_exists: true
|
||||
add_index :developer_key_account_bindings, :root_account_id, algorithm: :concurrently
|
||||
add_index :developer_key_account_bindings, :root_account_id, algorithm: :concurrently, if_not_exists: true
|
||||
end
|
||||
|
||||
def down
|
||||
|
|
|
@ -22,7 +22,7 @@ class AddRootAccountIdToDeveloperKeys < ActiveRecord::Migration[5.2]
|
|||
|
||||
def up
|
||||
add_column_and_fk :developer_keys, :root_account_id, :accounts, if_not_exists: true
|
||||
add_index :developer_keys, :root_account_id, algorithm: :concurrently
|
||||
add_index :developer_keys, :root_account_id, algorithm: :concurrently, if_not_exists: true
|
||||
end
|
||||
|
||||
def down
|
||||
|
|
|
@ -22,7 +22,7 @@ class AddRootAccountIdToLtiResourceLinks < ActiveRecord::Migration[5.2]
|
|||
|
||||
def up
|
||||
add_column_and_fk :lti_resource_links, :root_account_id, :accounts, if_not_exists: true
|
||||
add_index :lti_resource_links, :root_account_id, algorithm: :concurrently
|
||||
add_index :lti_resource_links, :root_account_id, algorithm: :concurrently, if_not_exists: true
|
||||
end
|
||||
|
||||
def down
|
||||
|
|
|
@ -22,7 +22,7 @@ class AddRootAccountIdToLtiResults < ActiveRecord::Migration[5.2]
|
|||
|
||||
def up
|
||||
add_column_and_fk :lti_results, :root_account_id, :accounts, if_not_exists: true
|
||||
add_index :lti_results, :root_account_id, algorithm: :concurrently
|
||||
add_index :lti_results, :root_account_id, algorithm: :concurrently, if_not_exists: true
|
||||
end
|
||||
|
||||
def down
|
||||
|
|
|
@ -22,7 +22,7 @@ class AddRootAccountIdToOriginalityReports < ActiveRecord::Migration[5.2]
|
|||
|
||||
def up
|
||||
add_column_and_fk :originality_reports, :root_account_id, :accounts, if_not_exists: true
|
||||
add_index :originality_reports, :root_account_id, algorithm: :concurrently
|
||||
add_index :originality_reports, :root_account_id, algorithm: :concurrently, if_not_exists: true
|
||||
end
|
||||
|
||||
def down
|
||||
|
|
|
@ -23,7 +23,7 @@ class AddRootAccountIdToMasterCoursesChildContentTags < ActiveRecord::Migration[
|
|||
|
||||
def up
|
||||
add_column_and_fk :master_courses_child_content_tags, :root_account_id, :accounts, if_not_exists: true
|
||||
add_index :master_courses_child_content_tags, :root_account_id, algorithm: :concurrently
|
||||
add_index :master_courses_child_content_tags, :root_account_id, algorithm: :concurrently, if_not_exists: true
|
||||
end
|
||||
|
||||
def down
|
||||
|
|
|
@ -23,7 +23,7 @@ class AddRootAccountIdToDiscussionTopicParticipants < ActiveRecord::Migration[5.
|
|||
|
||||
def up
|
||||
add_column_and_fk :discussion_topic_participants, :root_account_id, :accounts, if_not_exists: true
|
||||
add_index :discussion_topic_participants, :root_account_id, algorithm: :concurrently
|
||||
add_index :discussion_topic_participants, :root_account_id, algorithm: :concurrently, if_not_exists: true
|
||||
end
|
||||
|
||||
def down
|
||||
|
|
|
@ -23,7 +23,7 @@ class AddRootAccountIdToCourseAccountAssociations < ActiveRecord::Migration[5.2]
|
|||
|
||||
def up
|
||||
add_column_and_fk :course_account_associations, :root_account_id, :accounts, if_not_exists: true
|
||||
add_index :course_account_associations, :root_account_id, algorithm: :concurrently
|
||||
add_index :course_account_associations, :root_account_id, algorithm: :concurrently, if_not_exists: true
|
||||
end
|
||||
|
||||
def down
|
||||
|
|
|
@ -23,7 +23,7 @@ class AddRootAccountIdToContextModules < ActiveRecord::Migration[5.2]
|
|||
|
||||
def up
|
||||
add_column_and_fk :context_modules, :root_account_id, :accounts, if_not_exists: true
|
||||
add_index :context_modules, :root_account_id, algorithm: :concurrently
|
||||
add_index :context_modules, :root_account_id, algorithm: :concurrently, if_not_exists: true
|
||||
end
|
||||
|
||||
def down
|
||||
|
|
|
@ -23,7 +23,7 @@ class AddRootAccountIdToContextModuleProgressions < ActiveRecord::Migration[5.2]
|
|||
|
||||
def up
|
||||
add_column_and_fk :context_module_progressions, :root_account_id, :accounts, if_not_exists: true
|
||||
add_index :context_module_progressions, :root_account_id, algorithm: :concurrently
|
||||
add_index :context_module_progressions, :root_account_id, algorithm: :concurrently, if_not_exists: true
|
||||
end
|
||||
|
||||
def down
|
||||
|
|
|
@ -22,6 +22,6 @@ class AddRootAccountIdToContentParticipations < ActiveRecord::Migration[5.2]
|
|||
def change
|
||||
add_column :content_participations, :root_account_id, :integer, limit: 8
|
||||
add_foreign_key :content_participations, :accounts, column: :root_account_id
|
||||
add_index :content_participations, :root_account_id, algorithm: :concurrently
|
||||
add_index :content_participations, :root_account_id, algorithm: :concurrently, if_not_exists: true
|
||||
end
|
||||
end
|
||||
|
|
|
@ -22,6 +22,6 @@ class AddRootAccountIdToContentParticipationCounts < ActiveRecord::Migration[5.2
|
|||
def change
|
||||
add_column :content_participation_counts, :root_account_id, :integer, limit: 8
|
||||
add_foreign_key :content_participation_counts, :accounts, column: :root_account_id
|
||||
add_index :content_participation_counts, :root_account_id, algorithm: :concurrently
|
||||
add_index :content_participation_counts, :root_account_id, algorithm: :concurrently, if_not_exists: true
|
||||
end
|
||||
end
|
||||
|
|
|
@ -20,6 +20,6 @@ class AddRootAccountIdIndexToLtiLineItems < ActiveRecord::Migration[5.2]
|
|||
disable_ddl_transaction!
|
||||
|
||||
def change
|
||||
add_index :lti_line_items, :root_account_id, algorithm: :concurrently
|
||||
add_index :lti_line_items, :root_account_id, algorithm: :concurrently, if_not_exists: true
|
||||
end
|
||||
end
|
||||
|
|
|
@ -23,7 +23,7 @@ class AddRootAccountIdToContentMigrations < ActiveRecord::Migration[5.2]
|
|||
|
||||
def up
|
||||
add_column_and_fk :content_migrations, :root_account_id, :accounts, if_not_exists: true
|
||||
add_index :content_migrations, :root_account_id, algorithm: :concurrently
|
||||
add_index :content_migrations, :root_account_id, algorithm: :concurrently, if_not_exists: true
|
||||
end
|
||||
|
||||
def down
|
||||
|
|
|
@ -23,7 +23,7 @@ class AddRootAccountIdToAttachmentAssociations < ActiveRecord::Migration[5.2]
|
|||
|
||||
def up
|
||||
add_column_and_fk :attachment_associations, :root_account_id, :accounts, if_not_exists: true
|
||||
add_index :attachment_associations, :root_account_id, algorithm: :concurrently
|
||||
add_index :attachment_associations, :root_account_id, algorithm: :concurrently, if_not_exists: true
|
||||
end
|
||||
|
||||
def down
|
||||
|
|
|
@ -23,7 +23,7 @@ class AddRootAccountIdToAssignmentOverrideStudents < ActiveRecord::Migration[5.2
|
|||
|
||||
def up
|
||||
add_column_and_fk :assignment_override_students, :root_account_id, :accounts, if_not_exists: true
|
||||
add_index :assignment_override_students, :root_account_id, algorithm: :concurrently
|
||||
add_index :assignment_override_students, :root_account_id, algorithm: :concurrently, if_not_exists: true
|
||||
end
|
||||
|
||||
def down
|
||||
|
|
|
@ -23,7 +23,7 @@ class AddRootAccountIdToAssignmentOverrides < ActiveRecord::Migration[5.2]
|
|||
|
||||
def up
|
||||
add_column_and_fk :assignment_overrides, :root_account_id, :accounts, if_not_exists: true
|
||||
add_index :assignment_overrides, :root_account_id, algorithm: :concurrently
|
||||
add_index :assignment_overrides, :root_account_id, algorithm: :concurrently, if_not_exists: true
|
||||
end
|
||||
|
||||
def down
|
||||
|
|
|
@ -23,7 +23,7 @@ class AddRootAccountIdToAssignmentGroups < ActiveRecord::Migration[5.2]
|
|||
|
||||
def up
|
||||
add_column_and_fk :assignment_groups, :root_account_id, :accounts, if_not_exists: true
|
||||
add_index :assignment_groups, :root_account_id, algorithm: :concurrently
|
||||
add_index :assignment_groups, :root_account_id, algorithm: :concurrently, if_not_exists: true
|
||||
end
|
||||
|
||||
def down
|
||||
|
|
|
@ -23,7 +23,7 @@ class AddRootAccountIdToScoreStatistics < ActiveRecord::Migration[5.2]
|
|||
|
||||
def up
|
||||
add_column_and_fk :score_statistics, :root_account_id, :accounts, if_not_exists: true
|
||||
add_index :score_statistics, :root_account_id, algorithm: :concurrently
|
||||
add_index :score_statistics, :root_account_id, algorithm: :concurrently, if_not_exists: true
|
||||
end
|
||||
|
||||
def down
|
||||
|
|
|
@ -23,7 +23,7 @@ class AddRootAccountIdToScores < ActiveRecord::Migration[5.2]
|
|||
|
||||
def up
|
||||
add_column_and_fk :scores, :root_account_id, :accounts, if_not_exists: true
|
||||
add_index :scores, :root_account_id, algorithm: :concurrently
|
||||
add_index :scores, :root_account_id, algorithm: :concurrently, if_not_exists: true
|
||||
end
|
||||
|
||||
def down
|
||||
|
|
|
@ -23,7 +23,7 @@ class AddRootAccountIdToGradingPeriods < ActiveRecord::Migration[5.2]
|
|||
|
||||
def up
|
||||
add_column_and_fk :grading_periods, :root_account_id, :accounts, if_not_exists: true
|
||||
add_index :grading_periods, :root_account_id, algorithm: :concurrently
|
||||
add_index :grading_periods, :root_account_id, algorithm: :concurrently, if_not_exists: true
|
||||
end
|
||||
|
||||
def down
|
||||
|
|
|
@ -24,7 +24,7 @@ class AddRootAccountIdToPostPolicies < ActiveRecord::Migration[5.2]
|
|||
|
||||
def up
|
||||
add_column_and_fk :post_policies, :root_account_id, :accounts, if_not_exists: true
|
||||
add_index :post_policies, :root_account_id, algorithm: :concurrently
|
||||
add_index :post_policies, :root_account_id, algorithm: :concurrently, if_not_exists: true
|
||||
end
|
||||
|
||||
def down
|
||||
|
|
|
@ -24,7 +24,7 @@ class AddRootAccountIdToLatePolicies < ActiveRecord::Migration[5.2]
|
|||
|
||||
def up
|
||||
add_column_and_fk :late_policies, :root_account_id, :accounts, if_not_exists: true
|
||||
add_index :late_policies, :root_account_id, algorithm: :concurrently
|
||||
add_index :late_policies, :root_account_id, algorithm: :concurrently, if_not_exists: true
|
||||
end
|
||||
|
||||
def down
|
||||
|
|
|
@ -23,7 +23,7 @@ class AddRootAccountIdToGradingStandards < ActiveRecord::Migration[5.2]
|
|||
|
||||
def up
|
||||
add_column_and_fk :grading_standards, :root_account_id, :accounts, if_not_exists: true
|
||||
add_index :grading_standards, :root_account_id, algorithm: :concurrently
|
||||
add_index :grading_standards, :root_account_id, algorithm: :concurrently, if_not_exists: true
|
||||
end
|
||||
|
||||
def down
|
||||
|
|
|
@ -23,7 +23,7 @@ class AddRootAccountIdToCustomGradebookColumns < ActiveRecord::Migration[5.2]
|
|||
|
||||
def up
|
||||
add_column_and_fk :custom_gradebook_columns, :root_account_id, :accounts, if_not_exists: true
|
||||
add_index :custom_gradebook_columns, :root_account_id, algorithm: :concurrently
|
||||
add_index :custom_gradebook_columns, :root_account_id, algorithm: :concurrently, if_not_exists: true
|
||||
end
|
||||
|
||||
def down
|
||||
|
|
|
@ -23,7 +23,7 @@ class AddRootAccountIdToLearningOutcomeGroup < ActiveRecord::Migration[5.2]
|
|||
|
||||
def up
|
||||
add_column_and_fk :learning_outcome_groups, :root_account_id, :accounts, if_not_exists: true
|
||||
add_index :learning_outcome_groups, :root_account_id, algorithm: :concurrently
|
||||
add_index :learning_outcome_groups, :root_account_id, algorithm: :concurrently, if_not_exists: true
|
||||
end
|
||||
|
||||
def down
|
||||
|
|
|
@ -23,7 +23,7 @@ class AddRootAccountIdToCustomGradebookColumnData < ActiveRecord::Migration[5.2]
|
|||
|
||||
def up
|
||||
add_column_and_fk :custom_gradebook_column_data, :root_account_id, :accounts, if_not_exists: true
|
||||
add_index :custom_gradebook_column_data, :root_account_id, algorithm: :concurrently
|
||||
add_index :custom_gradebook_column_data, :root_account_id, algorithm: :concurrently, if_not_exists: true
|
||||
end
|
||||
|
||||
def down
|
||||
|
|
|
@ -23,7 +23,7 @@ class AddRootAccountIdToConversations < ActiveRecord::Migration[5.2]
|
|||
|
||||
def up
|
||||
add_column_and_fk :conversations, :root_account_id, :accounts, if_not_exists: true
|
||||
add_index :conversations, :root_account_id, algorithm: :concurrently
|
||||
add_index :conversations, :root_account_id, algorithm: :concurrently, if_not_exists: true
|
||||
end
|
||||
|
||||
def down
|
||||
|
|
|
@ -23,7 +23,7 @@ class AddRootAccountIdToConversationParticipants < ActiveRecord::Migration[5.2]
|
|||
|
||||
def up
|
||||
add_column_and_fk :conversation_participants, :root_account_id, :accounts, if_not_exists: true
|
||||
add_index :conversation_participants, :root_account_id, algorithm: :concurrently
|
||||
add_index :conversation_participants, :root_account_id, algorithm: :concurrently, if_not_exists: true
|
||||
end
|
||||
|
||||
def down
|
||||
|
|
|
@ -23,7 +23,7 @@ class AddRootAccountIdToMasterCoursesMasterMigrations < ActiveRecord::Migration[
|
|||
|
||||
def up
|
||||
add_column_and_fk :master_courses_master_migrations, :root_account_id, :accounts, if_not_exists: true
|
||||
add_index :master_courses_master_migrations, :root_account_id, algorithm: :concurrently
|
||||
add_index :master_courses_master_migrations, :root_account_id, algorithm: :concurrently, if_not_exists: true
|
||||
end
|
||||
|
||||
def down
|
||||
|
|
|
@ -23,7 +23,7 @@ class AddRootAccountIdToLearningOutcomes < ActiveRecord::Migration[5.2]
|
|||
|
||||
def up
|
||||
add_column_and_fk :learning_outcomes, :root_account_id, :accounts, if_not_exists: true
|
||||
add_index :learning_outcomes, :root_account_id, algorithm: :concurrently
|
||||
add_index :learning_outcomes, :root_account_id, algorithm: :concurrently, if_not_exists: true
|
||||
end
|
||||
|
||||
def down
|
||||
|
|
|
@ -23,7 +23,7 @@ class AddRootAccountIdToLearningOutcomeQuestionResults < ActiveRecord::Migration
|
|||
|
||||
def up
|
||||
add_column_and_fk :learning_outcome_question_results, :root_account_id, :accounts, if_not_exists: true
|
||||
add_index :learning_outcome_question_results, :root_account_id, algorithm: :concurrently
|
||||
add_index :learning_outcome_question_results, :root_account_id, algorithm: :concurrently, if_not_exists: true
|
||||
end
|
||||
|
||||
def down
|
||||
|
|
|
@ -23,7 +23,7 @@ class AddRootAccountIdToLearningOutcomeResults < ActiveRecord::Migration[5.2]
|
|||
|
||||
def up
|
||||
add_column_and_fk :learning_outcome_results, :root_account_id, :accounts, if_not_exists: true
|
||||
add_index :learning_outcome_results, :root_account_id, algorithm: :concurrently
|
||||
add_index :learning_outcome_results, :root_account_id, algorithm: :concurrently, if_not_exists: true
|
||||
end
|
||||
|
||||
def down
|
||||
|
|
|
@ -23,7 +23,7 @@ class AddRootAccountIdToOutcomeProficiencies < ActiveRecord::Migration[5.2]
|
|||
|
||||
def up
|
||||
add_column_and_fk :outcome_proficiencies, :root_account_id, :accounts, if_not_exists: true
|
||||
add_index :outcome_proficiencies, :root_account_id, algorithm: :concurrently
|
||||
add_index :outcome_proficiencies, :root_account_id, algorithm: :concurrently, if_not_exists: true
|
||||
end
|
||||
|
||||
def down
|
||||
|
|
|
@ -23,7 +23,7 @@ class AddRootAccountIdToOutcomeProficiencyRatings < ActiveRecord::Migration[5.2]
|
|||
|
||||
def up
|
||||
add_column_and_fk :outcome_proficiency_ratings, :root_account_id, :accounts, if_not_exists: true
|
||||
add_index :outcome_proficiency_ratings, :root_account_id, algorithm: :concurrently
|
||||
add_index :outcome_proficiency_ratings, :root_account_id, algorithm: :concurrently, if_not_exists: true
|
||||
end
|
||||
|
||||
def down
|
||||
|
|
|
@ -23,7 +23,7 @@ class AddRootAccountIdToAccountUsers < ActiveRecord::Migration[5.2]
|
|||
|
||||
def up
|
||||
add_column_and_fk :account_users, :root_account_id, :accounts, if_not_exists: true
|
||||
add_index :account_users, :root_account_id, algorithm: :concurrently
|
||||
add_index :account_users, :root_account_id, algorithm: :concurrently, if_not_exists: true
|
||||
end
|
||||
|
||||
def down
|
||||
|
|
|
@ -23,7 +23,7 @@ class AddRootAccountIdToEnrollmentStates < ActiveRecord::Migration[5.2]
|
|||
|
||||
def up
|
||||
add_column_and_fk :enrollment_states, :root_account_id, :accounts, if_not_exists: true
|
||||
add_index :enrollment_states, :root_account_id, algorithm: :concurrently
|
||||
add_index :enrollment_states, :root_account_id, algorithm: :concurrently, if_not_exists: true
|
||||
end
|
||||
|
||||
def down
|
||||
|
|
|
@ -23,7 +23,7 @@ class AddRootAccountIdToGroupMemberships < ActiveRecord::Migration[5.2]
|
|||
|
||||
def up
|
||||
add_column_and_fk :group_memberships, :root_account_id, :accounts, if_not_exists: true
|
||||
add_index :group_memberships, :root_account_id, algorithm: :concurrently
|
||||
add_index :group_memberships, :root_account_id, algorithm: :concurrently, if_not_exists: true
|
||||
end
|
||||
|
||||
def down
|
||||
|
|
|
@ -23,7 +23,7 @@ class AddRootAccountIdToRoleOverrides < ActiveRecord::Migration[5.2]
|
|||
|
||||
def up
|
||||
add_column_and_fk :role_overrides, :root_account_id, :accounts, if_not_exists: true
|
||||
add_index :role_overrides, :root_account_id, algorithm: :concurrently
|
||||
add_index :role_overrides, :root_account_id, algorithm: :concurrently, if_not_exists: true
|
||||
end
|
||||
|
||||
def down
|
||||
|
|
|
@ -23,7 +23,7 @@ class AddRootAccountIdToAccessTokens < ActiveRecord::Migration[5.2]
|
|||
|
||||
def up
|
||||
add_column_and_fk :access_tokens, :root_account_id, :accounts, if_not_exists: true
|
||||
add_index :access_tokens, :root_account_id, algorithm: :concurrently
|
||||
add_index :access_tokens, :root_account_id, algorithm: :concurrently, if_not_exists: true
|
||||
end
|
||||
|
||||
def down
|
||||
|
|
|
@ -23,7 +23,7 @@ class AddRootAccountIdToUserAccountAssociations < ActiveRecord::Migration[5.2]
|
|||
|
||||
def up
|
||||
add_column_and_fk :user_account_associations, :root_account_id, :accounts, if_not_exists: true
|
||||
add_index :user_account_associations, :root_account_id, algorithm: :concurrently
|
||||
add_index :user_account_associations, :root_account_id, algorithm: :concurrently, if_not_exists: true
|
||||
end
|
||||
|
||||
def down
|
||||
|
|
|
@ -23,7 +23,7 @@ class AddRootAccountIdToDiscussionEntries < ActiveRecord::Migration[5.2]
|
|||
|
||||
def up
|
||||
add_column_and_fk :discussion_entries, :root_account_id, :accounts, if_not_exists: true
|
||||
add_index :discussion_entries, :root_account_id, algorithm: :concurrently
|
||||
add_index :discussion_entries, :root_account_id, algorithm: :concurrently, if_not_exists: true
|
||||
end
|
||||
|
||||
def down
|
||||
|
|
|
@ -23,7 +23,7 @@ class AddRealUserIdToAccessToken < ActiveRecord::Migration[5.2]
|
|||
|
||||
def up
|
||||
add_column_and_fk :access_tokens, :real_user_id, :users, if_not_exists: true
|
||||
add_index :access_tokens, :real_user_id, algorithm: :concurrently, where: "real_user_id IS NOT NULL"
|
||||
add_index :access_tokens, :real_user_id, algorithm: :concurrently, where: "real_user_id IS NOT NULL", if_not_exists: true
|
||||
end
|
||||
|
||||
def down
|
||||
|
|
|
@ -23,7 +23,7 @@ class AddRootAccountIdToAssetUserAccesses < ActiveRecord::Migration[5.2]
|
|||
|
||||
def up
|
||||
add_column_and_fk :asset_user_accesses, :root_account_id, :accounts, if_not_exists: true
|
||||
add_index :asset_user_accesses, :root_account_id, algorithm: :concurrently
|
||||
add_index :asset_user_accesses, :root_account_id, algorithm: :concurrently, if_not_exists: true
|
||||
end
|
||||
|
||||
def down
|
||||
|
|
|
@ -23,7 +23,7 @@ class AddRootAccountIdToAttachments < ActiveRecord::Migration[5.2]
|
|||
|
||||
def up
|
||||
add_column_and_fk :attachments, :root_account_id, :accounts, if_not_exists: true
|
||||
add_index :attachments, :root_account_id, algorithm: :concurrently
|
||||
add_index :attachments, :root_account_id, algorithm: :concurrently, if_not_exists: true
|
||||
end
|
||||
|
||||
def down
|
||||
|
|
|
@ -23,7 +23,7 @@ class AddRootAccountIdToContentShares < ActiveRecord::Migration[5.2]
|
|||
|
||||
def up
|
||||
add_column_and_fk :content_shares, :root_account_id, :accounts, if_not_exists: true
|
||||
add_index :content_shares, :root_account_id, algorithm: :concurrently
|
||||
add_index :content_shares, :root_account_id, algorithm: :concurrently, if_not_exists: true
|
||||
end
|
||||
|
||||
def down
|
||||
|
|
|
@ -23,7 +23,7 @@ class AddRootAccountIdToUserNotes < ActiveRecord::Migration[5.2]
|
|||
|
||||
def up
|
||||
add_column_and_fk :user_notes, :root_account_id, :accounts, if_not_exists: true
|
||||
add_index :user_notes, :root_account_id, algorithm: :concurrently
|
||||
add_index :user_notes, :root_account_id, algorithm: :concurrently, if_not_exists: true
|
||||
end
|
||||
|
||||
def down
|
||||
|
|
|
@ -23,7 +23,7 @@ class AddRootAccountIdToCalendarEvents < ActiveRecord::Migration[5.2]
|
|||
|
||||
def up
|
||||
add_column_and_fk :calendar_events, :root_account_id, :accounts, if_not_exists: true
|
||||
add_index :calendar_events, :root_account_id, algorithm: :concurrently
|
||||
add_index :calendar_events, :root_account_id, algorithm: :concurrently, if_not_exists: true
|
||||
end
|
||||
|
||||
def down
|
||||
|
|
|
@ -23,7 +23,7 @@ class AddRootAccountIdToFolders < ActiveRecord::Migration[5.2]
|
|||
|
||||
def up
|
||||
add_column_and_fk :folders, :root_account_id, :accounts, if_not_exists: true
|
||||
add_index :folders, :root_account_id, algorithm: :concurrently
|
||||
add_index :folders, :root_account_id, algorithm: :concurrently, if_not_exists: true
|
||||
end
|
||||
|
||||
def down
|
||||
|
|
|
@ -23,7 +23,7 @@ class AddRootAccountIdToCommunicationChannels < ActiveRecord::Migration[5.2]
|
|||
|
||||
def up
|
||||
add_column_and_fk :communication_channels, :root_account_id, :accounts, if_not_exists: true
|
||||
add_index :communication_channels, :root_account_id, algorithm: :concurrently
|
||||
add_index :communication_channels, :root_account_id, algorithm: :concurrently, if_not_exists: true
|
||||
end
|
||||
|
||||
def down
|
||||
|
|
|
@ -23,7 +23,7 @@ class AddRootAccountIdToConversationMessages < ActiveRecord::Migration[5.2]
|
|||
|
||||
def up
|
||||
add_column_and_fk :conversation_messages, :root_account_id, :accounts, if_not_exists: true
|
||||
add_index :conversation_messages, :root_account_id, algorithm: :concurrently
|
||||
add_index :conversation_messages, :root_account_id, algorithm: :concurrently, if_not_exists: true
|
||||
end
|
||||
|
||||
def down
|
||||
|
|
|
@ -23,7 +23,7 @@ class AddRootAccountIdToConversationMessageParticipants < ActiveRecord::Migratio
|
|||
|
||||
def up
|
||||
add_column_and_fk :conversation_message_participants, :root_account_id, :accounts, if_not_exists: true
|
||||
add_index :conversation_message_participants, :root_account_id, algorithm: :concurrently
|
||||
add_index :conversation_message_participants, :root_account_id, algorithm: :concurrently, if_not_exists: true
|
||||
end
|
||||
|
||||
def down
|
||||
|
|
|
@ -23,7 +23,7 @@ class AddRootAccountIdToFavorites < ActiveRecord::Migration[5.2]
|
|||
|
||||
def up
|
||||
add_column_and_fk :favorites, :root_account_id, :accounts, if_not_exists: true
|
||||
add_index :favorites, :root_account_id, algorithm: :concurrently
|
||||
add_index :favorites, :root_account_id, algorithm: :concurrently, if_not_exists: true
|
||||
end
|
||||
|
||||
def down
|
||||
|
|
|
@ -23,7 +23,7 @@ class AddRootAccountIdToDiscussionTopics < ActiveRecord::Migration[5.2]
|
|||
|
||||
def up
|
||||
add_column_and_fk :discussion_topics, :root_account_id, :accounts, if_not_exists: true
|
||||
add_index :discussion_topics, :root_account_id, algorithm: :concurrently
|
||||
add_index :discussion_topics, :root_account_id, algorithm: :concurrently, if_not_exists: true
|
||||
end
|
||||
|
||||
def down
|
||||
|
|
|
@ -23,7 +23,7 @@ class AddRootAccountIdToDiscussionEntryParticipants < ActiveRecord::Migration[5.
|
|||
|
||||
def up
|
||||
add_column_and_fk :discussion_entry_participants, :root_account_id, :accounts, if_not_exists: true
|
||||
add_index :discussion_entry_participants, :root_account_id, algorithm: :concurrently
|
||||
add_index :discussion_entry_participants, :root_account_id, algorithm: :concurrently, if_not_exists: true
|
||||
end
|
||||
|
||||
def down
|
||||
|
|
|
@ -23,7 +23,7 @@ class AddRootAccountIdToWebConferenceParticipants < ActiveRecord::Migration[5.2]
|
|||
|
||||
def up
|
||||
add_column_and_fk :web_conference_participants, :root_account_id, :accounts, if_not_exists: true
|
||||
add_index :web_conference_participants, :root_account_id, algorithm: :concurrently
|
||||
add_index :web_conference_participants, :root_account_id, algorithm: :concurrently, if_not_exists: true
|
||||
end
|
||||
|
||||
def down
|
||||
|
|
|
@ -23,7 +23,7 @@ class AddRootAccountIdToWebConferences < ActiveRecord::Migration[5.2]
|
|||
|
||||
def up
|
||||
add_column_and_fk :web_conferences, :root_account_id, :accounts, if_not_exists: true
|
||||
add_index :web_conferences, :root_account_id, algorithm: :concurrently
|
||||
add_index :web_conferences, :root_account_id, algorithm: :concurrently, if_not_exists: true
|
||||
end
|
||||
|
||||
def down
|
||||
|
|
|
@ -354,6 +354,10 @@ module ActiveRecord
|
|||
User.connection.alter_constraint(:user_services, old_name, new_name: 'test')
|
||||
expect(User.connection.find_foreign_key(:user_services, :users)).to eq 'test'
|
||||
end
|
||||
|
||||
it "allows if_not_exists on add_index" do
|
||||
expect { User.connection.add_index(:enrollments, :user_id, if_not_exists: true) }.not_to raise_exception
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue