possible fix for migration, hang tight before running it
This commit is contained in:
parent
8a61718efd
commit
da1345502f
1 changed files with 5 additions and 4 deletions
|
|
@ -19,16 +19,17 @@ class RemovePublicShareVisibilities < ActiveRecord::Migration
|
||||||
|
|
||||||
index = 0
|
index = 0
|
||||||
shareable_size = type.constantize.count
|
shareable_size = type.constantize.count
|
||||||
|
table_name = type.tableize
|
||||||
|
|
||||||
while index < shareable_size + 100 do
|
while index < shareable_size + 100 do
|
||||||
sql = <<-SQL
|
sql = <<-SQL
|
||||||
DELETE sv
|
DELETE sv
|
||||||
FROM share_visibilities AS sv
|
FROM share_visibilities AS sv
|
||||||
INNER JOIN posts
|
INNER JOIN #{table_name}
|
||||||
ON sv.shareable_id = posts.id
|
ON sv.shareable_id = #{table_name}.id
|
||||||
WHERE sv.shareable_type = "#{type}"
|
WHERE sv.shareable_type = "#{type}"
|
||||||
AND #{type.tableize}.public IS TRUE
|
AND #{table_name}.public IS TRUE
|
||||||
AND #{type.tableize}.id < #{index};
|
AND #{table_name}.id < #{index};
|
||||||
SQL
|
SQL
|
||||||
|
|
||||||
ActiveRecord::Base.connection.execute(sql)
|
ActiveRecord::Base.connection.execute(sql)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue