From b92ee9c8d5eb6bb4d88e91a51aac82d3045b0771 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20Sch=C3=B6lling?= Date: Sat, 22 Oct 2011 16:12:41 +0200 Subject: [PATCH 1/4] Store old post id for photos --- ...12215141_move_photos_to_their_own_table.rb | 29 ++++++++++++------- db/schema.rb | 2 ++ 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/db/migrate/20111012215141_move_photos_to_their_own_table.rb b/db/migrate/20111012215141_move_photos_to_their_own_table.rb index 77604f756..21dedf0cf 100644 --- a/db/migrate/20111012215141_move_photos_to_their_own_table.rb +++ b/db/migrate/20111012215141_move_photos_to_their_own_table.rb @@ -1,6 +1,7 @@ class MovePhotosToTheirOwnTable < ActiveRecord::Migration def self.up create_table "photos", :force => true do |t| + t.integer "tmp_old_id", :null => true t.integer "author_id", :null => false t.boolean "public", :default => false, :null => false t.string "diaspora_handle" @@ -18,18 +19,26 @@ class MovePhotosToTheirOwnTable < ActiveRecord::Migration t.integer "comments_count" end - execute < 20111021184041) do add_index "people", ["owner_id"], :name => "index_people_on_owner_id", :unique => true create_table "photos", :force => true do |t| + t.integer "tmp_old_id" t.integer "author_id", :null => false t.boolean "public", :default => false, :null => false t.string "diaspora_handle" From afe8ee98893a4a17a3f058737031979a2a0731b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20Sch=C3=B6lling?= Date: Sat, 22 Oct 2011 19:10:29 +0200 Subject: [PATCH 2/4] Fixed INSERT statement --- db/migrate/20111012215141_move_photos_to_their_own_table.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/migrate/20111012215141_move_photos_to_their_own_table.rb b/db/migrate/20111012215141_move_photos_to_their_own_table.rb index 21dedf0cf..63cab1734 100644 --- a/db/migrate/20111012215141_move_photos_to_their_own_table.rb +++ b/db/migrate/20111012215141_move_photos_to_their_own_table.rb @@ -52,7 +52,7 @@ SQL if postgres? execute %{ INSERT INTO posts ( - tmp_old_id AS id, author_id, public, diaspora_handle, guid, pending, type, text, + tmp_old_id, 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, From d8e410f242908e0b9206cb8fbff05259b02a935f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20Sch=C3=B6lling?= Date: Sat, 22 Oct 2011 19:53:59 +0200 Subject: [PATCH 3/4] Fixed postgre queries as suggested by Pistos --- ...12215141_move_photos_to_their_own_table.rb | 51 +++++++++++++++---- 1 file changed, 42 insertions(+), 9 deletions(-) diff --git a/db/migrate/20111012215141_move_photos_to_their_own_table.rb b/db/migrate/20111012215141_move_photos_to_their_own_table.rb index 63cab1734..33e3d9e55 100644 --- a/db/migrate/20111012215141_move_photos_to_their_own_table.rb +++ b/db/migrate/20111012215141_move_photos_to_their_own_table.rb @@ -20,16 +20,49 @@ class MovePhotosToTheirOwnTable < ActiveRecord::Migration end if postgres? - execute < Date: Sun, 23 Oct 2011 15:23:39 +0200 Subject: [PATCH 4/4] Fixed Pistos' issue in downmigration --- ...12215141_move_photos_to_their_own_table.rb | 83 +++++++++---------- 1 file changed, 41 insertions(+), 42 deletions(-) diff --git a/db/migrate/20111012215141_move_photos_to_their_own_table.rb b/db/migrate/20111012215141_move_photos_to_their_own_table.rb index 33e3d9e55..4e8b31a3c 100644 --- a/db/migrate/20111012215141_move_photos_to_their_own_table.rb +++ b/db/migrate/20111012215141_move_photos_to_their_own_table.rb @@ -21,45 +21,45 @@ class MovePhotosToTheirOwnTable < ActiveRecord::Migration if postgres? execute %{ -INSERT INTO photos ( -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 -) SELECT -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' -} + INSERT INTO photos ( + 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 + ) SELECT + 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' + } execute "UPDATE aspect_visibilities SET shareable_type='Photo' FROM photos WHERE shareable_id=photos.id" execute "UPDATE share_visibilities SET shareable_type='Photo' FROM photos WHERE shareable_id=photos.id" @@ -85,7 +85,7 @@ SQL if postgres? execute %{ INSERT INTO posts ( - tmp_old_id, author_id, public, diaspora_handle, guid, pending, type, text, + id, 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, @@ -95,8 +95,7 @@ SQL tmp_old_id, 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 + NULL, NULL, NULL, NULL, status_message_guid, 0, comments_count, NULL FROM photos }