mysociety / derechoapreguntar-theme

The Alaveteli theme for Derecho a Preguntar (Nicaragua)
https://derechoapreguntar.org/
Other
0 stars 3 forks source link

Delete all users other than admins #109

Closed garethrees closed 9 years ago

garethrees commented 9 years ago

Javier has asked if it's possible to delete all the users that were in the first tests and just have the Violeta B de Chamorro team on the site

garethrees commented 9 years ago
[17:09:50]  <gareth>     do they want to keep all the requests?
[17:12:53]  <Jen>    no
JenMysoc commented 9 years ago

They only want their requests and their accounts (so the administrators) to stay on the site for now :)

garethrees commented 9 years ago

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)
garethrees commented 9 years ago

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)
garethrees commented 9 years ago

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)
garethrees commented 9 years ago

Done