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 000000000..9f9f09f58 --- /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