never use AR classes in migrations if you can help it

This commit is contained in:
Maxwell Salzberg 2012-02-02 14:25:33 -08:00
parent b55cadb4a4
commit 2ea0ca0e9b

View file

@ -10,16 +10,17 @@
# caution: you may want to take your pod offline during the OPTIMIZE command. # caution: you may want to take your pod offline during the OPTIMIZE command.
class RemovePublicShareVisibilities < ActiveRecord::Migration class RemovePublicShareVisibilities < ActiveRecord::Migration
class ShareVisibility < ActiveRecord::Base; end
class Post < ActiveRecord::Base; end
class Photo < ActiveRecord::Base; end
def self.up def self.up
%w{Post Photo}.each do |type| %w{Post Photo}.each do |type|
index = 0 index = 0
shareable_size = type.constantize.count
table_name = type.tableize 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 while index < shareable_size + 100 do
sql = <<-SQL sql = <<-SQL