Delete newly created disconnected notifications

This commit is contained in:
Raphael Sofaer 2011-03-17 18:30:34 -07:00
parent 924dc13adc
commit fe435d8709
2 changed files with 12 additions and 1 deletions

View file

@ -0,0 +1,11 @@
class DeleteDisconnectedNotifications < ActiveRecord::Migration
def self.up
result = execute("SELECT notifications.id FROM notifications
LEFT OUTER JOIN posts ON posts.id = notifications.target_id
WHERE posts.id IS NULL AND notifications.target_id IS NOT NULL AND notifications.target_type = 'Post'").to_a.flatten!
execute("DELETE FROM notifications WHERE notifications.id IN (#{result.join(',')})") if result
end
def self.down
end
end

View file

@ -10,7 +10,7 @@
#
# It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20110317222802) do
ActiveRecord::Schema.define(:version => 20110318012008) do
create_table "aspect_memberships", :force => true do |t|
t.integer "aspect_id", :null => false