migration to cleanup aspect_visibilities
* remove all for public posts * remove all for deleted posts
This commit is contained in:
parent
e0d6da7ad7
commit
54ff7ee278
2 changed files with 31 additions and 6 deletions
27
db/migrate/20160302025129_cleanup_aspect_visibility.rb
Normal file
27
db/migrate/20160302025129_cleanup_aspect_visibility.rb
Normal file
|
|
@ -0,0 +1,27 @@
|
||||||
|
class CleanupAspectVisibility < ActiveRecord::Migration
|
||||||
|
class AspectVisibility < ActiveRecord::Base
|
||||||
|
end
|
||||||
|
|
||||||
|
def up
|
||||||
|
AspectVisibility.joins("LEFT OUTER JOIN posts ON posts.id = aspect_visibilities.shareable_id")
|
||||||
|
.where(shareable_type: "Post").delete_all("posts.id is NULL")
|
||||||
|
AspectVisibility.joins("LEFT OUTER JOIN photos ON photos.id = aspect_visibilities.shareable_id")
|
||||||
|
.where(shareable_type: "Photo").delete_all("photos.id is NULL")
|
||||||
|
AspectVisibility.joins("INNER JOIN posts ON posts.id = aspect_visibilities.shareable_id")
|
||||||
|
.where(shareable_type: "Post").delete_all(posts: {public: true})
|
||||||
|
AspectVisibility.joins("INNER JOIN photos ON photos.id = aspect_visibilities.shareable_id")
|
||||||
|
.where(shareable_type: "Photo").delete_all(photos: {public: true})
|
||||||
|
|
||||||
|
remove_columns :aspect_visibilities, :created_at, :updated_at
|
||||||
|
end
|
||||||
|
|
||||||
|
def down
|
||||||
|
add_column :aspect_visibilities, :created_at, :datetime
|
||||||
|
add_column :aspect_visibilities, :updated_at, :datetime
|
||||||
|
|
||||||
|
User.all.each do |user|
|
||||||
|
user.posts.where(public: true).each {|post| user.add_to_streams(post, user.aspects) }
|
||||||
|
user.photos.where(public: true).each {|photo| user.add_to_streams(photo, user.aspects) }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
10
db/schema.rb
10
db/schema.rb
|
|
@ -11,7 +11,7 @@
|
||||||
#
|
#
|
||||||
# It's strongly recommended that you check this file into your version control system.
|
# It's strongly recommended that you check this file into your version control system.
|
||||||
|
|
||||||
ActiveRecord::Schema.define(version: 20160225232049) do
|
ActiveRecord::Schema.define(version: 20160302025129) do
|
||||||
|
|
||||||
create_table "account_deletions", force: :cascade do |t|
|
create_table "account_deletions", force: :cascade do |t|
|
||||||
t.string "diaspora_handle", limit: 255
|
t.string "diaspora_handle", limit: 255
|
||||||
|
|
@ -31,11 +31,9 @@ ActiveRecord::Schema.define(version: 20160225232049) do
|
||||||
add_index "aspect_memberships", ["contact_id"], name: "index_aspect_memberships_on_contact_id", using: :btree
|
add_index "aspect_memberships", ["contact_id"], name: "index_aspect_memberships_on_contact_id", using: :btree
|
||||||
|
|
||||||
create_table "aspect_visibilities", force: :cascade do |t|
|
create_table "aspect_visibilities", force: :cascade do |t|
|
||||||
t.integer "shareable_id", limit: 4, null: false
|
t.integer "shareable_id", limit: 4, null: false
|
||||||
t.integer "aspect_id", limit: 4, null: false
|
t.integer "aspect_id", limit: 4, null: false
|
||||||
t.datetime "created_at", null: false
|
t.string "shareable_type", limit: 255, default: "Post", null: false
|
||||||
t.datetime "updated_at", null: false
|
|
||||||
t.string "shareable_type", limit: 255, default: "Post", null: false
|
|
||||||
end
|
end
|
||||||
|
|
||||||
add_index "aspect_visibilities", ["aspect_id"], name: "index_aspect_visibilities_on_aspect_id", using: :btree
|
add_index "aspect_visibilities", ["aspect_id"], name: "index_aspect_visibilities_on_aspect_id", using: :btree
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue