Sorry, this is endless… I have now a notification reference to delete
Can you help me with this, once again? Pleaase
irb(main):363:0> # Actual deletion, requires overview run before
=> nil
irb(main):364:0> User.where(active: false).where.not(id: 1).find_each do |user|
irb(main):365:1* puts "Customer #{user.login}/#{user.email}/#{user.id} has #{Ticket.where(customer_id: user.id).count} tickets"
irb(main):366:1>
irb(main):367:1> puts " Removing references for user with E-Mail #{user.email}..."
irb(main):368:1> ActivityStream.where(created_by_id: user.id).update_all(created_by_id: 1)
irb(main):369:1> History.where(created_by_id: user.id).update_all(created_by_id: 1)
irb(main):370:1> Ticket::Article.where(created_by_id: user.id).update_all(created_by_id: 1)
irb(main):371:1> Ticket::Article.where(updated_by_id: user.id).update_all(updated_by_id: 1)
irb(main):372:1> Store.where(created_by_id: user.id).update_all(created_by_id: 1)
StatsStore.where(created_by_id: user.id).update_all(created_by_id: 1)
Tag.where(created_by_id: user.id).update_all(created_by_id: 1)
if OnlineNotification.find_by(user_id: user.id)==""
OnlineNotification.find_by(user_id: user.id).destroy!
end
puts " Deleting user #{user.login}/#{user.email}..."
user.destroy
endirb(main):373:1> StatsStore.where(created_by_id: user.id).update_all(created_by_id: 1)
irb(main):374:1> Tag.where(created_by_id: user.id).update_all(created_by_id: 1)
irb(main):375:1> if OnlineNotification.find_by(user_id: user.id)==""
irb(main):376:2> OnlineNotification.find_by(user_id: user.id).destroy!
irb(main):377:2> end
irb(main):378:1>
irb(main):379:1> puts " Deleting user #{user.login}/#{user.email}..."
irb(main):380:1> user.destroy
irb(main):381:1> end
Customer reperich@amadamachinetools.de/reperich@amadamachinetools.de/457 has 0 tickets
Removing references for user with E-Mail reperich@amadamachinetools.de...
Deleting user reperich@amadamachinetools.de/reperich@amadamachinetools.de...
Traceback (most recent call last):
2: from (irb):364
1: from (irb):380:in `block in irb_binding'
ActiveRecord::InvalidForeignKey (PG::ForeignKeyViolation: ERROR: update or delete on table "users" violates foreign key constraint "fk_rails_0c0055c5df" on table "online_notifications")
DETAIL: Key (id)=(457) is still referenced from table "online_notifications".
: DELETE FROM "users" WHERE "users"."id" = $1
irb(main):382:0>