From aebb15337b2ecfa8611b7dd7616eb3528dc75e3c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9gis=20Hanol?= Date: Sat, 14 May 2016 18:34:03 +0200 Subject: [PATCH] remove invalid topic_users rows --- .../20160514100852_remove_invalid_topic_user.rb | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 db/migrate/20160514100852_remove_invalid_topic_user.rb diff --git a/db/migrate/20160514100852_remove_invalid_topic_user.rb b/db/migrate/20160514100852_remove_invalid_topic_user.rb new file mode 100644 index 00000000000..9f9f09f5858 --- /dev/null +++ b/db/migrate/20160514100852_remove_invalid_topic_user.rb @@ -0,0 +1,14 @@ +class RemoveInvalidTopicUser < ActiveRecord::Migration + def up + execute <<-SQL + DELETE FROM topic_users + USING topic_users tu + LEFT JOIN users u ON u.id = tu.user_id + WHERE u.id IS NULL + AND topic_users.id = tu.id + SQL + end + + def down + end +end