Fix migration for MySQL

This commit is contained in:
Sarah Mei 2012-02-03 21:12:44 -08:00
parent 3bd9b0d62e
commit d1fbf7b55c

View file

@ -23,15 +23,27 @@ class RemovePublicShareVisibilities < ActiveRecord::Migration
end
while index < shareable_size + 100 do
sql = <<-SQL
DELETE
FROM share_visibilities AS sv
USING #{table_name} as p
WHERE sv.shareable_id = p.id
AND sv.shareable_type = '#{type}'
AND p.public IS TRUE
AND p.id < #{index};
SQL
if postgres?
sql = <<-SQL
DELETE
FROM share_visibilities AS sv
USING #{table_name} as p
WHERE sv.shareable_id = p.id
AND sv.shareable_type = '#{type}'
AND p.public IS TRUE
AND p.id < #{index};
SQL
else
sql = <<-SQL
DELETE sv
FROM share_visibilities AS sv
INNER JOIN #{table_name}
ON sv.shareable_id = #{table_name}.id
WHERE sv.shareable_type = "#{type}"
AND #{table_name}.public IS TRUE
AND #{table_name}.id < #{index};
SQL
end
puts "deleted public share vis up to #{index} of #{type}"
ActiveRecord::Base.connection.execute(sql)