Photo association on GUID 1/2: Migration

This commit is contained in:
MrZYX 2011-05-27 17:32:09 +02:00
parent 307b69c7cf
commit fba69bd8a5
2 changed files with 42 additions and 4 deletions

View file

@ -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

View file

@ -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|