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,6 +40,52 @@ SQL
def self.down def self.down
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 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 NULL AS id, author_id, public, diaspora_handle, guid, pending, 'Photo' AS type, text, remote_photo_path, remote_photo_name, random_string,
@ -67,6 +113,7 @@ WHERE
posts.guid=photos.guid AND posts.guid=photos.guid AND
photos.id=share_visibilities.shareable_id photos.id=share_visibilities.shareable_id
SQL SQL
end
execute "DROP TABLE photos" execute "DROP TABLE photos"
end end