Closed garethrees closed 9 years ago
[17:09:50] <gareth> do they want to keep all the requests?
[17:12:53] <Jen> no
They only want their requests and their accounts (so the administrators) to stay on the site for now :)
console code for this:
non_admins = User.where(['admin_level != ?', 'super']).all
requests = non_admins.map(&:info_requests).flatten
requests.each(&:fully_destroy)
non_admins.each(&:destroy)
Requests:
non_admins = User.where(['admin_level != ?', 'super']).all
requests = non_admins.map(&:info_requests).flatten
requests.each(&:fully_destroy)
# InfoRequest#fully_destroy does not destroy comments
InfoRequest.find(40).comments.first.destroy
non_admins = User.where(['admin_level != ?', 'super']).all
requests = non_admins.map(&:info_requests).flatten
requests.each(&:fully_destroy)
Users:
User.where(['admin_level != ?', 'super']).all.map(&:post_redirects).flatten.map(&:destroy)
User.where(['admin_level != ?', 'super']).all.map(&:censor_rules).flatten.each(&:destroy)
User.where(['admin_level != ?', 'super']).all.each(&:destroy)
# ActiveRecord::InvalidForeignKey: PG::ForeignKeyViolation: ERROR: update or delete on table "users" violates foreign key constraint "fk_comments_user" on table "comments"
# DETAIL: Key (id)=(6) is still referenced from table "comments".
# : DELETE FROM "users" WHERE "users"."id" = $1
Comment.where(:user_id => 6).all.map(&:destroy)
# ActiveRecord::InvalidForeignKey: PG::ForeignKeyViolation: ERROR: update or delete on table "comments" violates foreign key constraint "fk_info_request_events_comment_id" on table "info_request_events"
# DETAIL: Key (id)=(2) is still referenced from table "info_request_events".
# : DELETE FROM "comments" WHERE "comments"."id" = $1
InfoRequestEvent.where(:comment_id => 2).map(&:destroy)
# ActiveRecord::InvalidForeignKey: PG::ForeignKeyViolation: ERROR: update or delete on table "info_request_events" violates foreign key constraint "fk_user_info_request_sent_alert_info_request_event" on table "user_info_request_sent_alerts"
# DETAIL: Key (id)=(77) is still referenced from table "user_info_request_sent_alerts".
# : DELETE FROM "info_request_events" WHERE "info_request_events"."id" = $1
UserInfoRequestSentAlert.where(:info_request_event_id => 77).all.map(&:destroy)
InfoRequestEvent.where(:comment_id => 2).map(&:destroy)
Comment.where(:user_id => 6).all.map(&:destroy)
# ActiveRecord::InvalidForeignKey: PG::ForeignKeyViolation: ERROR: update or delete on table "comments" violates foreign key constraint "fk_info_request_events_comment_id" on table "info_request_events"
# DETAIL: Key (id)=(3) is still referenced from table "info_request_events".
# : DELETE FROM "comments" WHERE "comments"."id" = $1
InfoRequestEvent.where(:comment_id => 3).all.map(&:destroy)
# ActiveRecord::InvalidForeignKey: PG::ForeignKeyViolation: ERROR: update or delete on table "info_request_events" violates foreign key constraint "fk_user_info_request_sent_alert_info_request_event" on table "user_info_request_sent_alerts"
# DETAIL: Key (id)=(104) is still referenced from table "user_info_request_sent_alerts".
# : DELETE FROM "info_request_events" WHERE "info_request_events"."id" = $1
UserInfoRequestSentAlert.where(:info_request_event_id => 104).all.map(&:destroy)
InfoRequestEvent.where(:comment_id => 3).all.map(&:destroy)
Comment.where(:user_id => 6).all.map(&:destroy)
User.where(['admin_level != ?', 'super']).all.each(&:destroy)
# ActiveRecord::InvalidForeignKey: PG::ForeignKeyViolation: ERROR: update or delete on table "users" violates foreign key constraint "fk_track_request_tracking_user" on table "track_things"
# DETAIL: Key (id)=(6) is still referenced from table "track_things".
# : DELETE FROM "users" WHERE "users"."id" = $1
TrackThing.where(:tracking_user_id => 6).all.map(&:destroy)
User.where(['admin_level != ?', 'super']).all.each(&:destroy)
Done