From fba69bd8a50c4301fe4df4f16507c608f0d7be09 Mon Sep 17 00:00:00 2001 From: MrZYX Date: Fri, 27 May 2011 17:32:09 +0200 Subject: [PATCH] Photo association on GUID 1/2: Migration --- ...hoto_status_message_association_on_guid.rb | 38 +++++++++++++++++++ db/schema.rb | 8 ++-- 2 files changed, 42 insertions(+), 4 deletions(-) create mode 100644 db/migrate/20110527135552_photo_status_message_association_on_guid.rb diff --git a/db/migrate/20110527135552_photo_status_message_association_on_guid.rb b/db/migrate/20110527135552_photo_status_message_association_on_guid.rb new file mode 100644 index 000000000..d6c16c3ee --- /dev/null +++ b/db/migrate/20110527135552_photo_status_message_association_on_guid.rb @@ -0,0 +1,38 @@ +class PhotoStatusMessageAssociationOnGuid < ActiveRecord::Migration + class Post < ActiveRecord::Base + attr_accessible :id, :guid, :status_message_id, :status_message_guid + self.inheritance_column = :_type_disabled + end + + def self.up + add_column :posts, :status_message_guid, :string + + photos = Post.where(Post.arel_table[:status_message_id].not_eq(nil).and(Post.arel_table[:type].eq('Photo'))) + photos.each do |photo| + status_message = Post.find(photo.status_message_id) + photo.update_attributes(:status_message_guid => status_message.guid) + end + + remove_index :posts, [:status_message_id, :pending] + add_index :posts, :status_message_guid + add_index :posts, [:status_message_guid, :pending] + + remove_column :posts, :status_message_id + end + + def self.down + add_column :posts, :status_message_id, :integer + + photos = Post.where(Post.arel_table[:status_message_guid].not_eq(nil).and(Post.arel_table[:type].eq('Photo'))) + photos.each do |photo| + status_message = Post.where(:guid => photo.status_message_guid).first + photo.update_attributes(:status_message_id => status_message.id) + end + + remove_index :posts, [:status_message_guid, :pending] + add_index :posts, :status_message_id + add_index :posts, [:status_message_id, :pending] + + remove_column :posts, :status_message_guid + end +end diff --git a/db/schema.rb b/db/schema.rb index ce8183c91..4ccf06d4b 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20110524184202) do +ActiveRecord::Schema.define(:version => 20110527135552) do create_table "aspect_memberships", :force => true do |t| t.integer "aspect_id", :null => false @@ -232,7 +232,6 @@ ActiveRecord::Schema.define(:version => 20110524184202) do t.boolean "pending", :default => false, :null => false t.string "type", :limit => 40, :null => false t.text "text" - t.integer "status_message_id" t.text "remote_photo_path" t.string "remote_photo_name" t.string "random_string" @@ -249,13 +248,14 @@ ActiveRecord::Schema.define(:version => 20110524184202) do t.string "provider_display_name" t.string "actor_url" t.integer "objectId" + t.string "status_message_guid" end add_index "posts", ["author_id"], :name => "index_posts_on_person_id" add_index "posts", ["guid"], :name => "index_posts_on_guid", :unique => true add_index "posts", ["mongo_id"], :name => "index_posts_on_mongo_id" - add_index "posts", ["status_message_id", "pending"], :name => "index_posts_on_status_message_id_and_pending" - add_index "posts", ["status_message_id"], :name => "index_posts_on_status_message_id" + add_index "posts", ["status_message_guid", "pending"], :name => "index_posts_on_status_message_guid_and_pending" + add_index "posts", ["status_message_guid"], :name => "index_posts_on_status_message_guid" add_index "posts", ["type", "pending", "id"], :name => "index_posts_on_type_and_pending_and_id" create_table "profiles", :force => true do |t|