-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enable interventions for ProgrammingGroups and add indices
- Loading branch information
Showing
6 changed files
with
52 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
# frozen_string_literal: true | ||
|
||
class UserExerciseIntervention < ApplicationRecord | ||
include Creation | ||
include ContributorCreation | ||
belongs_to :intervention | ||
belongs_to :exercise | ||
end |
30 changes: 30 additions & 0 deletions
30
db/migrate/20231208194632_add_index_to_user_exercise_interventions.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# frozen_string_literal: true | ||
|
||
class AddIndexToUserExerciseInterventions < ActiveRecord::Migration[7.1] | ||
def change | ||
up_only do | ||
# We cannot add a foreign key to a table that has rows that violate the constraint. | ||
UserExerciseIntervention.where.not(exercise_id: Exercise.select(:id)).delete_all | ||
UserExerciseIntervention.where.not(intervention_id: Intervention.select(:id)).delete_all | ||
end | ||
|
||
rename_column :user_exercise_interventions, :user_id, :contributor_id | ||
rename_column :user_exercise_interventions, :user_type, :contributor_type | ||
|
||
change_column_null :user_exercise_interventions, :contributor_type, false | ||
change_column_null :user_exercise_interventions, :contributor_id, false | ||
add_index :user_exercise_interventions, %i[contributor_type contributor_id] | ||
|
||
change_column_null :user_exercise_interventions, :exercise_id, false | ||
add_index :user_exercise_interventions, :exercise_id | ||
add_foreign_key :user_exercise_interventions, :exercises | ||
|
||
change_column_null :user_exercise_interventions, :intervention_id, false | ||
add_index :user_exercise_interventions, :intervention_id | ||
add_foreign_key :user_exercise_interventions, :interventions | ||
end | ||
|
||
class Exercise < ActiveRecord::Base; end | ||
class Intervention < ActiveRecord::Base; end | ||
class UserExerciseIntervention < ActiveRecord::Base; end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters