diff --git a/db/migrate/20111011195702_share_anything.rb b/db/migrate/20111011195702_share_anything.rb index a7cdda2d9..2889718c5 100644 --- a/db/migrate/20111011195702_share_anything.rb +++ b/db/migrate/20111011195702_share_anything.rb @@ -1,19 +1,35 @@ class ShareAnything < ActiveRecord::Migration def self.up - remove_foreign_key :aspect_visibilities, :posts - remove_index :aspect_visibilities, :post_id_and_aspect_id - remove_index :aspect_visibilities, :post_id + # add_column :comments, :name, :string + # add_column :comments, :user_id, :integer, :null => false + # add_index :comments, :user_id + # becomes + # execute "ALTER TABLE comments add name varchar(255), add user_id int NOT NULL, add index `index_comments_on_user_id` (`user_id`);" + start_sql = "ALTER TABLE aspect_visibilities " + sql = [] - change_table :aspect_visibilities do |t| - t.rename :post_id, :shareable_id - t.string :shareable_type, :default => 'Post', :null => false - end + #remove_index :aspect_visibilities, :post_id_and_aspect_id + sql << "remove index `index_post_id_and_aspect_id`" + + #remove_index :aspect_visibilities, :post_id + sql << "remove index `index_aspect_visibilities_on_post_id`" - add_index :aspect_visibilities, [:shareable_id, :shareable_type, :aspect_id], :name => 'shareable_and_aspect_id' - add_index :aspect_visibilities, [:shareable_id, :shareable_type] + # change_table :aspect_visibilities do |t| + # t.rename :post_id, :shareable_id + # t.string :shareable_type, :default => 'Post', :null => false + # end + sql << "RENAME COLUMN post_id shareable_id" + sql << "ADD shareable_type varchar(255) NOT NULL DEFAULT `Post`" - remove_foreign_key :post_visibilities, :posts + # add_index :aspect_visibilities, [:shareable_id, :shareable_type, :aspect_id], :name => 'shareable_and_aspect_id' + # add_index :aspect_visibilities, [:shareable_id, :shareable_type] + + sql << "add index `shareable_and_aspect_id` (`shareable_id`, `shareable_type`, `aspect_id`)" + sql << "add index `index_aspect_visibilities_on_shareable_id_and_shareable_type` (`shareable_id`, `shareable_type`)" + + execute(start_sql + sql.join(', ') + ';') + remove_index :post_visibilities, :contact_id_and_post_id remove_index :post_visibilities, :post_id_and_hidden_and_contact_id