From 8d3f4609a3c98ad20797d0cda7e765f0286b9ae5 Mon Sep 17 00:00:00 2001 From: Raphael Sofaer Date: Tue, 5 Apr 2011 10:35:48 -0700 Subject: [PATCH] Take models back out of migration, will have to fix it for postgres again later --- .../20110328202414_post_visibilities_on_contacts.rb | 12 ++++++++---- db/migrate/20110330230206_pm_foreign_keys.rb | 2 +- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/db/migrate/20110328202414_post_visibilities_on_contacts.rb b/db/migrate/20110328202414_post_visibilities_on_contacts.rb index 85cffd7aa..568a235fc 100644 --- a/db/migrate/20110328202414_post_visibilities_on_contacts.rb +++ b/db/migrate/20110328202414_post_visibilities_on_contacts.rb @@ -56,6 +56,10 @@ SQL SQL end + def pv_count + @pv_count ||= execute('SELECT count(*) FROM post_visibilities').to_a.first.first + end + def self.up create_table :aspect_visibilities do |t| t.integer :post_id, :null => false @@ -68,14 +72,14 @@ SQL add_foreign_key :aspect_visibilities, :aspects, :dependent => :delete add_foreign_key :aspect_visibilities, :posts, :dependent => :delete - delete_disconnected_pvs if PostVisibility.count > 0 + delete_disconnected_pvs if pv_count > 0 add_column :post_visibilities, :contact_id, :integer, :null => false - move_author_pvs_to_aspect_pvs if PostVisibility.count > 0 - set_pv_contact_ids if PostVisibility.count > 0 + move_author_pvs_to_aspect_pvs if pv_count > 0 + set_pv_contact_ids if pv_count > 0 - delete_duplicate_pvs if PostVisibility.count > 0 + delete_duplicate_pvs if pv_count > 0 remove_index :post_visibilities, [:aspect_id, :post_id] remove_column :post_visibilities, :aspect_id diff --git a/db/migrate/20110330230206_pm_foreign_keys.rb b/db/migrate/20110330230206_pm_foreign_keys.rb index 652133004..71a1641e4 100644 --- a/db/migrate/20110330230206_pm_foreign_keys.rb +++ b/db/migrate/20110330230206_pm_foreign_keys.rb @@ -23,7 +23,7 @@ SQL SQL end def self.up - if Message.count > 0 + if execute('SELECT COUNT(*) FROM messages').to_a.first.first > 0 delete_disconnected_conversations delete_disconnected_messages delete_disconnected_cvs