Store old post id for photos

This commit is contained in:
Manuel Schölling 2011-10-22 16:12:41 +02:00
parent 79ec50a16c
commit b92ee9c8d5
2 changed files with 21 additions and 10 deletions

View file

@ -1,6 +1,7 @@
class MovePhotosToTheirOwnTable < ActiveRecord::Migration class MovePhotosToTheirOwnTable < ActiveRecord::Migration
def self.up def self.up
create_table "photos", :force => true do |t| create_table "photos", :force => true do |t|
t.integer "tmp_old_id", :null => true
t.integer "author_id", :null => false t.integer "author_id", :null => false
t.boolean "public", :default => false, :null => false t.boolean "public", :default => false, :null => false
t.string "diaspora_handle" t.string "diaspora_handle"
@ -18,18 +19,26 @@ class MovePhotosToTheirOwnTable < ActiveRecord::Migration
t.integer "comments_count" t.integer "comments_count"
end end
execute <<SQL if postgres?
execute <<SQL
INSERT INTO photos INSERT INTO photos
SELECT id, author_id, public, diaspora_handle, guid, pending, text, remote_photo_path, remote_photo_name, random_string, processed_image, SELECT id AS tmp_old_id, author_id, public, diaspora_handle, guid, pending, text, remote_photo_path, remote_photo_name, random_string, processed_image,
created_at, updated_at, unprocessed_image, status_message_guid, comments_count created_at, updated_at, unprocessed_image, status_message_guid, comments_count
FROM posts FROM posts
WHERE type = 'Photo' WHERE type = 'Photo'
SQL SQL
if postgres?
execute "UPDATE aspect_visibilities AS av SET shareable_type='Photo' FROM photos WHERE av.shareable_id=photos.id" execute "UPDATE aspect_visibilities AS av SET shareable_type='Photo' FROM photos WHERE av.shareable_id=photos.id"
execute "UPDATE share_visibilities AS sv SET shareable_type='Photo' FROM photos WHERE sv.shareable_id=photos.id" execute "UPDATE share_visibilities AS sv SET shareable_type='Photo' FROM photos WHERE sv.shareable_id=photos.id"
else else
execute <<SQL
INSERT INTO photos
SELECT NULL as id, id AS tmp_old_id, author_id, public, diaspora_handle, guid, pending, text, remote_photo_path, remote_photo_name, random_string, processed_image,
created_at, updated_at, unprocessed_image, status_message_guid, comments_count
FROM posts
WHERE type = 'Photo'
SQL
execute "UPDATE aspect_visibilities AS av, photos SET av.shareable_type='Photo' WHERE av.shareable_id=photos.id" execute "UPDATE aspect_visibilities AS av, photos SET av.shareable_type='Photo' WHERE av.shareable_id=photos.id"
execute "UPDATE share_visibilities AS sv, photos SET sv.shareable_type='Photo' WHERE sv.shareable_id=photos.id" execute "UPDATE share_visibilities AS sv, photos SET sv.shareable_type='Photo' WHERE sv.shareable_id=photos.id"
end end
@ -43,14 +52,14 @@ SQL
if postgres? if postgres?
execute %{ execute %{
INSERT INTO posts ( INSERT INTO posts (
author_id, public, diaspora_handle, guid, pending, type, text, tmp_old_id AS id, author_id, public, diaspora_handle, guid, pending, type, text,
remote_photo_path, remote_photo_name, random_string, processed_image, remote_photo_path, remote_photo_name, random_string, processed_image,
youtube_titles, created_at, updated_at, unprocessed_image, youtube_titles, created_at, updated_at, unprocessed_image,
object_url, image_url, image_height, image_width, object_url, image_url, image_height, image_width,
provider_display_name, actor_url, "objectId", root_guid, provider_display_name, actor_url, "objectId", root_guid,
status_message_guid, likes_count, comments_count, o_embed_cache_id status_message_guid, likes_count, comments_count, o_embed_cache_id
) SELECT ) SELECT
author_id, public, diaspora_handle, guid, pending, 'Photo', text, tmp_old_id, author_id, public, diaspora_handle, guid, pending, 'Photo', text,
remote_photo_path, remote_photo_name, random_string, processed_image, remote_photo_path, remote_photo_name, random_string, processed_image,
NULL, created_at, updated_at, unprocessed_image, NULL, NULL, NULL, NULL, NULL, created_at, updated_at, unprocessed_image, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
@ -68,7 +77,7 @@ SQL
posts posts
, photos , photos
WHERE WHERE
posts.guid=photos.guid posts.id=photos.tmp_old_id
AND photos.id=aspect_visibilities.shareable_id AND photos.id=aspect_visibilities.shareable_id
} }
@ -82,13 +91,13 @@ SQL
posts posts
, photos , photos
WHERE WHERE
posts.guid=photos.guid posts.id=photos.tmp_old_id
AND photos.id=share_visibilities.shareable_id AND photos.id=share_visibilities.shareable_id
} }
else else
execute <<SQL execute <<SQL
INSERT INTO posts INSERT INTO posts
SELECT NULL AS id, author_id, public, diaspora_handle, guid, pending, 'Photo' AS type, text, remote_photo_path, remote_photo_name, random_string, SELECT tmp_old_id AS id, author_id, public, diaspora_handle, guid, pending, 'Photo' AS type, text, remote_photo_path, remote_photo_name, random_string,
processed_image, NULL AS youtube_titles, created_at, updated_at, unprocessed_image, NULL AS object_url, NULL AS image_url, NULL AS image_height, NULL AS image_width, NULL AS provider_display_name, processed_image, NULL AS youtube_titles, created_at, updated_at, unprocessed_image, NULL AS object_url, NULL AS image_url, NULL AS image_height, NULL AS image_width, NULL AS provider_display_name,
NULL AS actor_url, NULL AS objectId, NULL AS root_guid, status_message_guid, 0 AS likes_count, comments_count, NULL AS o_embed_cache_id NULL AS actor_url, NULL AS objectId, NULL AS root_guid, status_message_guid, 0 AS likes_count, comments_count, NULL AS o_embed_cache_id
FROM photos FROM photos
@ -100,7 +109,7 @@ SET
aspect_visibilities.shareable_id=posts.id, aspect_visibilities.shareable_id=posts.id,
aspect_visibilities.shareable_type='Post' aspect_visibilities.shareable_type='Post'
WHERE WHERE
posts.guid=photos.guid AND posts.id=photos.tmp_old_id AND
photos.id=aspect_visibilities.shareable_id photos.id=aspect_visibilities.shareable_id
SQL SQL
@ -110,7 +119,7 @@ SET
share_visibilities.shareable_id=posts.id, share_visibilities.shareable_id=posts.id,
share_visibilities.shareable_type='Post' share_visibilities.shareable_type='Post'
WHERE WHERE
posts.guid=photos.guid AND posts.id=photos.tmp_old_id AND
photos.id=share_visibilities.shareable_id photos.id=share_visibilities.shareable_id
SQL SQL
end end

View file

@ -1,3 +1,4 @@
# encoding: UTF-8
# This file is auto-generated from the current state of the database. Instead # This file is auto-generated from the current state of the database. Instead
# of editing this file, please use the migrations feature of Active Record to # of editing this file, please use the migrations feature of Active Record to
# incrementally modify your database, and then regenerate this schema definition. # incrementally modify your database, and then regenerate this schema definition.
@ -248,6 +249,7 @@ ActiveRecord::Schema.define(:version => 20111021184041) do
add_index "people", ["owner_id"], :name => "index_people_on_owner_id", :unique => true add_index "people", ["owner_id"], :name => "index_people_on_owner_id", :unique => true
create_table "photos", :force => true do |t| create_table "photos", :force => true do |t|
t.integer "tmp_old_id"
t.integer "author_id", :null => false t.integer "author_id", :null => false
t.boolean "public", :default => false, :null => false t.boolean "public", :default => false, :null => false
t.string "diaspora_handle" t.string "diaspora_handle"