Skip to content

Commit

Permalink
Clean up foreign keys so that users can be deleted
Browse files Browse the repository at this point in the history
  • Loading branch information
akofink committed Mar 31, 2014
1 parent 3f50873 commit c588c6a
Show file tree
Hide file tree
Showing 10 changed files with 1,178 additions and 695 deletions.
10 changes: 5 additions & 5 deletions app/controllers/student_team_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def view
end

def create
@student = AssignmentParticipant.find(params[:student_id])
@student = AssignmentParticipant.find(params[:id])
return unless current_user_id?(@student.user_id)

check = AssignmentTeam.where( ["name =? and parent_id =?", params[:team][:name], @student.parent_id])
Expand Down Expand Up @@ -93,11 +93,11 @@ def leave
end

#if your old team does not have any members, delete the entry for the team
other_members = TeamsUser.where( ['team_id = ?', params[:team_id]]).first
if other_members.length == 0
other_members = TeamsUser.where( ['team_id = ?', params[:team_id]])
if other_members.count == 0
old_team = AssignmentTeam.where( ['id = ?', params[:team_id]])
if old_team != nil
old_team.destroy
if old_team
old_team.delete
#if assignment has signup sheet then the topic selected by the team has to go back to the pool
#or to the first team in the waitlist
signups = SignedUpUser.where( {:creator_id => params[:team_id]})
Expand Down
2 changes: 1 addition & 1 deletion app/models/assignment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class Assignment < ActiveRecord::Base
has_many :due_dates, :dependent => :destroy
has_many :teams, :class_name => 'AssignmentTeam', :foreign_key => 'parent_id'
has_many :team_review_mappings, :class_name => 'TeamReviewResponseMap', :through => :teams, :source => :review_mappings
has_many :invitations, :class_name => 'Invitation', :foreign_key => 'assignment_id'
has_many :invitations, :class_name => 'Invitation', :foreign_key => 'assignment_id', :dependent => :destroy
has_many :assignment_questionnaires,:dependent => :destroy
has_many :questionnaires, :through => :assignment_questionnaires
belongs_to :instructor, :class_name => 'User', :foreign_key => 'instructor_id'
Expand Down
2 changes: 1 addition & 1 deletion app/models/feedback_response_map.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class FeedbackResponseMap < ResponseMap
belongs_to :reviewee, :class_name => 'Participant', :foreign_key => 'reviewee_id'
belongs_to :review, :class_name => 'Response', :foreign_key => 'reviewed_object_id'
belongs_to :reviewer, :class_name => 'AssignmentParticipant'
belongs_to :reviewer, :class_name => 'AssignmentParticipant', dependent: :destroy

def assignment
self.review.map.assignment
Expand Down
6 changes: 3 additions & 3 deletions app/models/participant.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ class Participant < ActiveRecord::Base

has_many :comments, :dependent => :destroy
has_many :resubmission_times, :dependent => :destroy
has_many :reviews, :class_name => 'ResponseMap', :foreign_key => 'reviewer_id'
has_many :team_reviews, :class_name => 'TeamReviewResponseMap', :foreign_key => 'reviewer_id'
has_many :response_maps, :class_name =>'ResponseMap', :foreign_key => 'reviewee_id'
has_many :reviews, :class_name => 'ResponseMap', :foreign_key => 'reviewer_id', dependent: :destroy
has_many :team_reviews, :class_name => 'TeamReviewResponseMap', :foreign_key => 'reviewer_id', dependent: :destroy
has_many :response_maps, :class_name =>'ResponseMap', :foreign_key => 'reviewee_id', dependent: :destroy

validates_numericality_of :grade, :allow_nil => true

Expand Down
4 changes: 2 additions & 2 deletions app/models/response.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class Response < ActiveRecord::Base
belongs_to :map, :class_name => 'ResponseMap', :foreign_key => 'map_id'
belongs_to :map, :class_name => 'ResponseMap', :foreign_key => 'map_id', dependent: :destroy
has_many :scores, :class_name => 'Score', :foreign_key => 'response_id', :dependent => :destroy
has_many :metareview_response_maps, :class_name => 'MetareviewResponseMap', :foreign_key => 'reviewed_object_id'
has_many :metareview_response_maps, :class_name => 'MetareviewResponseMap', :foreign_key => 'reviewed_object_id', dependent: :destroy
before_create :add_dummy_map_id

attr_accessor :difficulty_rating
Expand Down
4 changes: 2 additions & 2 deletions app/models/response_map.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class ResponseMap < ActiveRecord::Base
has_one :response, foreign_key: 'map_id'
belongs_to :reviewer, :class_name => 'Participant', :foreign_key => 'reviewer_id'
has_one :response, foreign_key: 'map_id', dependent: :destroy
belongs_to :reviewer, :class_name => 'Participant', :foreign_key => 'reviewer_id',:dependent => :destroy

def map_id
id
Expand Down
2 changes: 2 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ class User < ActiveRecord::Base

has_many :teams_users, :dependent => :destroy
has_many :teams, :through => :teams_users
has_many :sent_invitations, class_name: 'Invitation', foreign_key: 'from_id', dependent: :destroy
has_many :received_invitations, class_name: 'Invitation', foreign_key: 'to_id', dependent: :destroy

has_many :children, class_name: 'User', :foreign_key => 'parent_id'
belongs_to :parent, class_name: 'User'
Expand Down
8 changes: 8 additions & 0 deletions db/migrate/20140331120322_remove_fks.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class RemoveFks < ActiveRecord::Migration
def self.up
execute "ALTER TABLE response_maps DROP FOREIGN KEY fk_response_map_reviewer"
end

def self.down
end
end
101 changes: 51 additions & 50 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.

ActiveRecord::Schema.define(:version => 20131206231914) do
ActiveRecord::Schema.define(:version => 20140331120322) do

create_table "assignment_questionnaires", :force => true do |t|
t.integer "assignment_id"
Expand Down Expand Up @@ -39,25 +39,24 @@
t.integer "num_review_of_reviewers", :default => 0, :null => false
t.integer "review_questionnaire_id"
t.integer "review_of_review_questionnaire_id"
t.integer "teammate_review_questionnaire_id"
t.boolean "reviews_visible_to_all"
t.boolean "team_assignment"
t.integer "wiki_type_id"
t.integer "wiki_type_id", :default => 0, :null => false
t.boolean "require_signup"
t.integer "num_reviewers", :default => 0, :null => false
t.text "spec_location"
t.integer "author_feedback_questionnaire_id"
t.integer "teammate_review_questionnaire_id"
t.integer "max_team_size", :default => 0, :null => false
t.boolean "staggered_deadline"
t.boolean "allow_suggestions"
t.integer "days_between_submissions"
t.string "review_assignment_strategy"
t.integer "max_reviews_per_submission"
t.integer "review_topic_threshold", :default => 0
t.boolean "availability_flag"
t.boolean "copy_flag", :default => false
t.integer "rounds_of_reviews", :default => 1
t.boolean "microtask", :default => false
t.boolean "availability_flag"
t.boolean "require_quiz"
t.integer "num_quiz_questions", :default => 0, :null => false
t.boolean "is_coding_assignment"
Expand Down Expand Up @@ -165,9 +164,9 @@
end

create_table "comments", :force => true do |t|
t.integer "participant_id", :null => false
t.boolean "private", :null => false
t.text "comment", :null => false
t.integer "participant_id", :default => 0, :null => false
t.boolean "private", :default => false, :null => false
t.text "comment", :null => false
end

create_table "content_pages", :force => true do |t|
Expand Down Expand Up @@ -248,11 +247,11 @@

add_index "due_dates", ["assignment_id"], :name => "fk_due_dates_assignments"
add_index "due_dates", ["deadline_type_id"], :name => "fk_deadline_type_due_date"
add_index "due_dates", ["rereview_allowed_id"], :name => "idx_rereview_allowed"
add_index "due_dates", ["resubmission_allowed_id"], :name => "idx_resubmission_allowed"
add_index "due_dates", ["review_allowed_id"], :name => "idx_review_allowed"
add_index "due_dates", ["review_of_review_allowed_id"], :name => "idx_review_of_review_allowed"
add_index "due_dates", ["submission_allowed_id"], :name => "idx_submission_allowed"
add_index "due_dates", ["rereview_allowed_id"], :name => "fk_due_date_rereview_allowed"
add_index "due_dates", ["resubmission_allowed_id"], :name => "fk_due_date_resubmission_allowed"
add_index "due_dates", ["review_allowed_id"], :name => "fk_due_date_review_allowed"
add_index "due_dates", ["review_of_review_allowed_id"], :name => "fk_due_date_review_of_review_allowed"
add_index "due_dates", ["submission_allowed_id"], :name => "fk_due_date_submission_allowed"

create_table "institutions", :force => true do |t|
t.string "name", :default => "", :null => false
Expand Down Expand Up @@ -330,7 +329,7 @@
t.integer "max_question_score"
t.integer "team_id", :default => 0, :null => false
t.integer "participant_id"
t.integer "assignment_id", :default => 0, :null => false
t.integer "assignment_id"
end

create_table "participant_team_roles", :force => true do |t|
Expand All @@ -344,15 +343,15 @@
add_index "participant_team_roles", ["role_assignment_id"], :name => "fk_role_assignment_id"

create_table "participants", :force => true do |t|
t.boolean "submit_allowed", :default => true
t.boolean "review_allowed", :default => true
t.boolean "submit_allowed", :default => true
t.boolean "review_allowed", :default => true
t.integer "user_id"
t.integer "parent_id"
t.integer "directory_num"
t.datetime "submitted_at"
t.boolean "permission_granted"
t.integer "penalty_accumulated", :default => 0, :null => false
t.string "submitted_hyperlinks", :limit => 500
t.integer "penalty_accumulated", :default => 0, :null => false
t.text "submitted_hyperlinks"
t.float "grade"
t.string "type"
t.string "handle"
Expand Down Expand Up @@ -382,9 +381,9 @@
add_index "question_advices", ["question_id"], :name => "fk_question_question_advices"

create_table "question_types", :force => true do |t|
t.string "q_type", :null => false
t.string "q_type", :default => "", :null => false
t.string "parameters"
t.integer "question_id", :default => 1, :null => false
t.integer "question_id", :default => 1, :null => false
end

add_index "question_types", ["question_id"], :name => "fk_question_type_question"
Expand All @@ -400,8 +399,8 @@
t.integer "default_num_choices"
t.string "type"
t.string "display_type"
t.string "section"
t.text "instruction_loc"
t.string "section"
end

create_table "questions", :force => true do |t|
Expand All @@ -420,20 +419,23 @@
end

create_table "response_maps", :force => true do |t|
t.integer "reviewed_object_id", :null => false
t.integer "reviewer_id", :null => false
t.integer "reviewee_id", :null => false
t.string "type", :null => false
t.boolean "notification_accepted", :default => false
t.integer "reviewed_object_id", :default => 0, :null => false
t.integer "reviewer_id", :default => 0, :null => false
t.integer "reviewee_id", :default => 0, :null => false
t.string "type", :default => "", :null => false
t.boolean "notification_accepted", :default => false
t.datetime "created_at"
t.datetime "updated_at"
end

add_index "response_maps", ["reviewer_id"], :name => "fk_response_map_reviewer"

create_table "responses", :force => true do |t|
t.integer "map_id", :null => false
t.string "additional_comment"
t.integer "map_id", :default => 0, :null => false
t.text "additional_comment"
t.datetime "created_at"
t.datetime "updated_at"
t.integer "version_num"
end

add_index "responses", ["map_id"], :name => "fk_response_response_map"
Expand Down Expand Up @@ -486,16 +488,16 @@
add_index "roles_permissions", ["role_id"], :name => "fk_roles_permission_role_id"

create_table "score_caches", :force => true do |t|
t.integer "reviewee_id", :default => 0, :null => false
t.integer "reviewee_id"
t.float "score", :default => 0.0, :null => false
t.string "range", :default => ""
t.string "object_type", :null => false
t.string "object_type", :default => "", :null => false
end

create_table "score_views", :id => false, :force => true do |t|
t.integer "question_weight"
t.integer "q_id", :default => 0
t.string "q_type"
t.string "q_type", :default => ""
t.string "q_parameters"
t.integer "q_question_id", :default => 1
t.integer "q1_id", :default => 0
Expand All @@ -514,14 +516,14 @@
t.integer "ques_id", :default => 0, :null => false
t.integer "ques_questionnaire_id"
t.integer "s_id", :default => 0
t.integer "s_question_id"
t.integer "s_question_id", :default => 0
t.integer "s_score"
t.text "s_comments"
t.integer "s_response_id"
end

create_table "scores", :force => true do |t|
t.integer "question_id", :null => false
t.integer "question_id", :default => 0, :null => false
t.integer "score"
t.text "comments"
t.integer "response_id"
Expand All @@ -531,7 +533,7 @@
add_index "scores", ["response_id"], :name => "fk_score_response"

create_table "sessions", :force => true do |t|
t.string "session_id", :null => false
t.string "session_id", :default => "", :null => false
t.text "data", :limit => 16777215
t.datetime "created_at"
t.datetime "updated_at"
Expand All @@ -542,8 +544,8 @@

create_table "sign_up_topics", :force => true do |t|
t.text "topic_name", :null => false
t.integer "assignment_id", :null => false
t.integer "max_choosers", :null => false
t.integer "assignment_id", :default => 0, :null => false
t.integer "max_choosers", :default => 0, :null => false
t.text "category"
t.string "topic_identifier", :limit => 10
t.integer "micropayment", :default => 0
Expand All @@ -553,9 +555,9 @@
add_index "sign_up_topics", ["assignment_id"], :name => "fk_sign_up_categories_sign_up_topics"

create_table "signed_up_users", :force => true do |t|
t.integer "topic_id", :null => false
t.integer "creator_id", :null => false
t.boolean "is_waitlisted", :null => false
t.integer "topic_id", :default => 0, :null => false
t.integer "creator_id", :default => 0, :null => false
t.boolean "is_waitlisted", :default => false, :null => false
t.integer "preference_priority_number"
end

Expand All @@ -580,7 +582,7 @@
create_table "suggestions", :force => true do |t|
t.integer "assignment_id"
t.string "title"
t.string "description", :limit => 750
t.text "description"
t.string "status"
t.string "unityID"
t.string "signup_preference"
Expand All @@ -592,6 +594,7 @@
t.datetime "end_date"
t.integer "num_of_students"
t.datetime "last_reminder"
t.integer "course_id", :default => 0, :null => false
end

create_table "survey_participants", :force => true do |t|
Expand All @@ -609,10 +612,6 @@
t.integer "survey_deployment_id"
end

add_index "survey_responses", ["assignment_id"], :name => "fk_survey_assignments"
add_index "survey_responses", ["question_id"], :name => "fk_survey_questions"
add_index "survey_responses", ["survey_id"], :name => "fk_survey_questionnaires"

create_table "system_settings", :force => true do |t|
t.string "site_name", :default => "", :null => false
t.string "site_subtitle"
Expand Down Expand Up @@ -686,7 +685,7 @@

create_table "teams", :force => true do |t|
t.string "name"
t.integer "parent_id", :default => 0, :null => false
t.integer "parent_id"
t.string "type"
t.text "comments_for_advertisement"
t.boolean "advertise_for_partner"
Expand All @@ -713,6 +712,8 @@
t.integer "round"
end

add_index "topic_deadlines", ["deadline_type_id"], :name => "fk_deadline_type_topic_deadlines"
add_index "topic_deadlines", ["late_policy_id"], :name => "fk_topic_deadlines_late_policies"
add_index "topic_deadlines", ["rereview_allowed_id"], :name => "idx_rereview_allowed"
add_index "topic_deadlines", ["resubmission_allowed_id"], :name => "idx_resubmission_allowed"
add_index "topic_deadlines", ["review_allowed_id"], :name => "idx_review_allowed"
Expand All @@ -721,8 +722,8 @@
add_index "topic_deadlines", ["topic_id"], :name => "fk_topic_deadlines_topics"

create_table "topic_dependencies", :force => true do |t|
t.integer "topic_id", :null => false
t.string "dependent_on", :null => false
t.integer "topic_id", :default => 0, :null => false
t.string "dependent_on", :default => "", :null => false
end

create_table "tree_folders", :force => true do |t|
Expand All @@ -744,15 +745,15 @@
t.boolean "email_on_review"
t.boolean "email_on_submission"
t.boolean "email_on_review_of_review"
t.boolean "is_new_user", :default => true
t.boolean "master_permission_granted"
t.boolean "is_new_user", :default => true, :null => false
t.integer "master_permission_granted", :limit => 1, :default => 0
t.string "handle"
t.boolean "leaderboard_privacy", :default => false
t.boolean "copy_of_emails", :default => false
t.text "digital_certificate"
t.string "persistence_token"
t.string "timezonepref"
t.text "public_key"
t.boolean "copy_of_emails", :default => false
end

add_index "users", ["role_id"], :name => "fk_user_role_id"
Expand Down

0 comments on commit c588c6a

Please sign in to comment.