From f8266b29ee723abda04fea038b48b538b45a3b42 Mon Sep 17 00:00:00 2001 From: Henne Vogelsang Date: Fri, 15 Feb 2019 01:03:05 +0100 Subject: [PATCH] Task to drop all ahoy events The ChangeVisitIdTypeOfAhoyEventsToInteger from 364be5541 is not very well done. You can not change the schema without changing possibly existing data. Ahoy events used some kind of string as `visit_id`. Changing this column to integrer will just barf up `Mysql2::Error: Truncated incorrect INTEGER value`. So we need a way for people who are in this situation now to get out of it. Luckily we completely dropped ahoy events a while ago so we can just delete them. --- lib/tasks/data.rake | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lib/tasks/data.rake b/lib/tasks/data.rake index 08d2b8c8..2e9863ed 100644 --- a/lib/tasks/data.rake +++ b/lib/tasks/data.rake @@ -17,6 +17,14 @@ namespace :data do nullify_attribute(events_room, 'room_id') end + desc 'Drop all ahoy events' + task drop_all_ahoy_events: :environment do + class TmpAhoy < ActiveRecord::Base + self.table_name = 'ahoy_events' + end + TmpAhoy.delete_all + end + def nullify_attribute(collection, attribute) puts "Will nullify #{attribute} in #{ActionController::Base.helpers.pluralize(collection.length, 'event')}." if collection.any?