Merge pull request #2202 from Pistos/postgresql-fix-photo-migration

Postgresql fix photo migration
This commit is contained in:
Daniel Grippi 2011-10-17 15:31:41 -07:00
commit 718cb2c2f4

View file

@ -40,7 +40,53 @@ SQL
def self.down
execute <<SQL
if postgres?
execute %{
INSERT INTO posts (
author_id, public, diaspora_handle, guid, pending, type, text,
remote_photo_path, remote_photo_name, random_string, processed_image,
youtube_titles, created_at, updated_at, unprocessed_image,
object_url, image_url, image_height, image_width,
provider_display_name, actor_url, "objectId", root_guid,
status_message_guid, likes_count, comments_count, o_embed_cache_id
) SELECT
author_id, public, diaspora_handle, guid, pending, 'Photo', text,
remote_photo_path, remote_photo_name, random_string, processed_image,
NULL, created_at, updated_at, unprocessed_image, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL,
status_message_guid, 0, comments_count, NULL
FROM photos
}
execute %{
UPDATE
aspect_visibilities
SET
shareable_id=posts.id
, shareable_type='Post'
FROM
posts
, photos
WHERE
posts.guid=photos.guid
AND photos.id=aspect_visibilities.shareable_id
}
execute %{
UPDATE
share_visibilities
SET
shareable_id=posts.id
, shareable_type='Post'
FROM
posts
, photos
WHERE
posts.guid=photos.guid
AND photos.id=share_visibilities.shareable_id
}
else
execute <<SQL
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,
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,
@ -48,7 +94,7 @@ INSERT INTO posts
FROM photos
SQL
execute <<SQL
execute <<SQL
UPDATE aspect_visibilities, posts, photos
SET
aspect_visibilities.shareable_id=posts.id,
@ -58,7 +104,7 @@ posts.guid=photos.guid AND
photos.id=aspect_visibilities.shareable_id
SQL
execute <<SQL
execute <<SQL
UPDATE share_visibilities, posts, photos
SET
share_visibilities.shareable_id=posts.id,
@ -67,6 +113,7 @@ WHERE
posts.guid=photos.guid AND
photos.id=share_visibilities.shareable_id
SQL
end
execute "DROP TABLE photos"
end