From 2ea0ca0e9bd881f50ae97ec71b82914fa890d86e Mon Sep 17 00:00:00 2001 From: Maxwell Salzberg Date: Thu, 2 Feb 2012 14:25:33 -0800 Subject: [PATCH] never use AR classes in migrations if you can help it --- ...20120202190701_remove_public_share_visibilities.rb | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/db/migrate/20120202190701_remove_public_share_visibilities.rb b/db/migrate/20120202190701_remove_public_share_visibilities.rb index e51805a93..db3bcfb48 100644 --- a/db/migrate/20120202190701_remove_public_share_visibilities.rb +++ b/db/migrate/20120202190701_remove_public_share_visibilities.rb @@ -10,16 +10,17 @@ # caution: you may want to take your pod offline during the OPTIMIZE command. class RemovePublicShareVisibilities < ActiveRecord::Migration - class ShareVisibility < ActiveRecord::Base; end - class Post < ActiveRecord::Base; end - class Photo < ActiveRecord::Base; end - def self.up %w{Post Photo}.each do |type| index = 0 - shareable_size = type.constantize.count + table_name = type.tableize + if postgres? + shareable_size = ActiveRecord::Base.connection.execute("SELECT COUNT(*) FROM #{table_name}").first['count'].to_i + else + shareable_size = ActiveRecord::Base.connection.execute("SELECT COUNT(*) FROM #{table_name}").first.first + end while index < shareable_size + 100 do sql = <<-SQL