remove public share visibilities. NOTE: you should run optimize table as detailed in the migration's comments after executing this. [ci skip]
This commit is contained in:
parent
4151f9c1a4
commit
7bd6a450a0
2 changed files with 38 additions and 1 deletions
|
|
@ -0,0 +1,37 @@
|
||||||
|
# NOTE: this migration will remove a lot of unused rows. It is highly suggested
|
||||||
|
# that you run `OPTIMIZE TABLE share_visibilities` after this
|
||||||
|
# migration is complete.
|
||||||
|
#
|
||||||
|
# caution: you may want to take your pod offline during the OPTIMIZE command.
|
||||||
|
|
||||||
|
class RemovePublicShareVisibilities < ActiveRecord::Migration
|
||||||
|
class ShareVisibility < ActiveRecord::Base; end
|
||||||
|
|
||||||
|
def self.up
|
||||||
|
%w{Post Photo}.each do |type|
|
||||||
|
|
||||||
|
index = 0
|
||||||
|
visibilitiy_size = ShareVisibility.count
|
||||||
|
|
||||||
|
while index < visibilitiy_size + 100 do
|
||||||
|
sql = <<-SQL
|
||||||
|
DELETE sv
|
||||||
|
FROM share_visibilities AS sv
|
||||||
|
INNER JOIN posts
|
||||||
|
ON sv.shareable_id = posts.id
|
||||||
|
WHERE sv.shareable_type = "#{type}"
|
||||||
|
AND #{type.tableize}.public IS TRUE
|
||||||
|
AND #{type.tableize}.id < #{index};
|
||||||
|
SQL
|
||||||
|
|
||||||
|
ActiveRecord::Base.connection.execute(sql)
|
||||||
|
|
||||||
|
index += 100
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.down
|
||||||
|
raise ActiveRecord::IrreversibleMigration
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
@ -11,7 +11,7 @@
|
||||||
#
|
#
|
||||||
# It's strongly recommended to check this file into your version control system.
|
# It's strongly recommended to check this file into your version control system.
|
||||||
|
|
||||||
ActiveRecord::Schema.define(:version => 20120114191018) do
|
ActiveRecord::Schema.define(:version => 20120202190701) do
|
||||||
|
|
||||||
create_table "account_deletions", :force => true do |t|
|
create_table "account_deletions", :force => true do |t|
|
||||||
t.string "diaspora_handle"
|
t.string "diaspora_handle"
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue