Skip to content

Commit

Permalink
Merge pull request #371 from openstax/fix_data
Browse files Browse the repository at this point in the history
Fix data so foreign key constraints can be added
  • Loading branch information
Dantemss authored May 24, 2022
2 parents b2c2f41 + 447ad0f commit 19700af
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions db/migrate/20220523181437_fix_foreign_keys.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,26 @@ def change
remove_foreign_key :vocab_term_tags, :tags, on_update: :cascade, on_delete: :cascade
remove_foreign_key :vocab_term_tags, :vocab_terms, on_update: :cascade, on_delete: :cascade

reversible do |dir|
dir.up do
Answer.where.not(
Question.where('"questions"."id" = "answers"."question_id"').arel.exists
).delete_all

CollaboratorSolution.where.not(
Question.where('"questions"."id" = "collaborator_solutions"."question_id"').arel.exists
).delete_all

StemAnswer.where.not(
Answer.where('"answers"."id" = "stem_answers"."answer_id"').arel.exists
).delete_all

Stem.where.not(
Question.where('"questions"."id" = "stems"."question_id"').arel.exists
).delete_all
end
end

add_foreign_key :administrators, :users
add_foreign_key :answers, :questions
add_foreign_key :authors, :publications
Expand Down

0 comments on commit 19700af

Please sign in to comment.