never use AR classes in migrations if you can help it
This commit is contained in:
parent
b55cadb4a4
commit
2ea0ca0e9b
1 changed files with 6 additions and 5 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in a new issue