diff --git a/db/migrate/20120202190701_remove_public_share_visibilities.rb b/db/migrate/20120202190701_remove_public_share_visibilities.rb new file mode 100644 index 000000000..aa30a696c --- /dev/null +++ b/db/migrate/20120202190701_remove_public_share_visibilities.rb @@ -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 diff --git a/db/schema.rb b/db/schema.rb index 5d2a01eb6..48dd8527f 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # 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| t.string "diaspora_handle"