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 end
while index < shareable_size + 100 do while index < shareable_size + 100 do
sql = <<-SQL if postgres?
DELETE sql = <<-SQL
FROM share_visibilities AS sv DELETE
USING #{table_name} as p FROM share_visibilities AS sv
WHERE sv.shareable_id = p.id USING #{table_name} as p
AND sv.shareable_type = '#{type}' WHERE sv.shareable_id = p.id
AND p.public IS TRUE AND sv.shareable_type = '#{type}'
AND p.id < #{index}; AND p.public IS TRUE
SQL 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}" puts "deleted public share vis up to #{index} of #{type}"
ActiveRecord::Base.connection.execute(sql) ActiveRecord::Base.connection.execute(sql)