From de58e58272b73fa08c193e444605c0153224115a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9gis=20Hanol?= Date: Mon, 1 Feb 2016 19:37:10 +0100 Subject: [PATCH] migration to fix email_logs not attached to a user --- db/migrate/20160201181320_fix_email_logs.rb | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 db/migrate/20160201181320_fix_email_logs.rb diff --git a/db/migrate/20160201181320_fix_email_logs.rb b/db/migrate/20160201181320_fix_email_logs.rb new file mode 100644 index 00000000000..402761a8fb6 --- /dev/null +++ b/db/migrate/20160201181320_fix_email_logs.rb @@ -0,0 +1,16 @@ +class FixEmailLogs < ActiveRecord::Migration + def up + execute <<-SQL + UPDATE email_logs + SET user_id = u.id + FROM email_logs el + LEFT JOIN users u ON u.email = el.to_address + WHERE email_logs.id = el.id + AND email_logs.user_id IS NULL + AND NOT email_logs.skipped + SQL + end + + def down + end +end