Merge branch 'roll_up_slow_migrations'
This commit is contained in:
commit
924e18887a
4 changed files with 66 additions and 33 deletions
|
|
@ -4,7 +4,7 @@ class CommentAnything < ActiveRecord::Migration
|
|||
remove_index :comments, :post_id
|
||||
change_table :comments do |t|
|
||||
t.rename :post_id, :commentable_id
|
||||
t.string :commentable_type, :default => 'Post', :null => false
|
||||
t.string :commentable_type, :default => 'Post', :null => false, :limit => 60
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -1,30 +1,67 @@
|
|||
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
|
||||
|
||||
change_table :aspect_visibilities do |t|
|
||||
t.rename :post_id, :shareable_id
|
||||
t.string :shareable_type, :default => 'Post', :null => false
|
||||
end
|
||||
start_sql = "ALTER TABLE aspect_visibilities "
|
||||
sql = []
|
||||
|
||||
#remove_index :aspect_visibilities, :post_id_and_aspect_id
|
||||
sql << "DROP INDEX `index_aspect_visibilities_on_post_id_and_aspect_id`"
|
||||
|
||||
#remove_index :aspect_visibilities, :post_id
|
||||
sql << "DROP INDEX `index_aspect_visibilities_on_post_id`"
|
||||
|
||||
|
||||
|
||||
# change_table :aspect_visibilities do |t|
|
||||
|
||||
# t.rename :post_id, :shareable_id
|
||||
# t.string :shareable_type, :default => 'Post', :null => false
|
||||
# end
|
||||
|
||||
sql << "CHANGE COLUMN post_id shareable_id int NOT NULL"
|
||||
sql << "ADD shareable_type varchar(255) NOT NULL DEFAULT 'Post'"
|
||||
|
||||
|
||||
# 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(', ') + ';')
|
||||
|
||||
add_index :aspect_visibilities, [:shareable_id, :shareable_type, :aspect_id], :name => 'shareable_and_aspect_id'
|
||||
add_index :aspect_visibilities, [:shareable_id, :shareable_type]
|
||||
|
||||
|
||||
remove_foreign_key :post_visibilities, :posts
|
||||
remove_index :post_visibilities, :contact_id_and_post_id
|
||||
remove_index :post_visibilities, :post_id_and_hidden_and_contact_id
|
||||
|
||||
change_table :post_visibilities do |t|
|
||||
t.rename :post_id, :shareable_id
|
||||
t.string :shareable_type, :default => 'Post', :null => false
|
||||
end
|
||||
|
||||
rename_table :post_visibilities, :share_visibilities
|
||||
add_index :share_visibilities, [:shareable_id, :shareable_type, :contact_id], :name => 'shareable_and_contact_id'
|
||||
add_index :share_visibilities, [:shareable_id, :shareable_type, :hidden, :contact_id], :name => 'shareable_and_hidden_and_contact_id'
|
||||
|
||||
start_sql = "ALTER TABLE share_visibilities "
|
||||
sql = []
|
||||
|
||||
#remove_index :post_visibilities, :contact_id_and_post_id
|
||||
#remove_index :post_visibilities, :post_id_and_hidden_and_contact_id
|
||||
|
||||
sql << "DROP INDEX `index_post_visibilities_on_contact_id_and_post_id`"
|
||||
sql << "DROP INDEX `index_post_visibilities_on_post_id_and_hidden_and_contact_id`"
|
||||
|
||||
#change_table :post_visibilities do |t|
|
||||
# t.rename :post_id, :shareable_id
|
||||
# t.string :shareable_type, :default => 'Post', :null => false
|
||||
#end
|
||||
|
||||
sql << "CHANGE COLUMN post_id shareable_id int NOT NULL"
|
||||
sql << "ADD shareable_type varchar(60) NOT NULL DEFAULT 'Post'"
|
||||
|
||||
#add_index :share_visibilities, [:shareable_id, :shareable_type, :contact_id], :name => 'shareable_and_contact_id'
|
||||
#add_index :share_visibilities, [:shareable_id, :shareable_type, :hidden, :contact_id], :name => 'shareable_and_hidden_and_contact_id'
|
||||
|
||||
sql << "add index `shareable_and_contact_id` (`shareable_id`, `shareable_type`, `contact_id`)"
|
||||
sql << "add index `shareable_and_hidden_and_contact_id` (`shareable_id`, `shareable_type`, `hidden`, `contact_id`)"
|
||||
|
||||
execute(start_sql + sql.join(', ') + ';')
|
||||
|
||||
end
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,8 +1,6 @@
|
|||
class AddBackIndexes < ActiveRecord::Migration
|
||||
def self.up
|
||||
# reduce index size
|
||||
change_column :comments, :commentable_type, :string, :default => "Post", :null => false, :length => 60
|
||||
change_column :share_visibilities, :shareable_type, :string, :default => "Post", :null => false, :length => 60
|
||||
|
||||
add_index :photos, :status_message_guid
|
||||
add_index :comments, [:commentable_id, :commentable_type]
|
||||
|
|
@ -12,8 +10,6 @@ class AddBackIndexes < ActiveRecord::Migration
|
|||
remove_index :comments, :column => [:commentable_id, :commentable_type]
|
||||
remove_index :photos, :column => :status_message_guid
|
||||
|
||||
change_column :share_visibilities, :shareable_type, :string, :default => "Post", :null => false
|
||||
change_column :comments, :commentable_type, :string, :default => "Post", :null => false
|
||||
# reduce index size
|
||||
end
|
||||
end
|
||||
|
|
|
|||
20
db/schema.rb
20
db/schema.rb
|
|
@ -48,17 +48,17 @@ ActiveRecord::Schema.define(:version => 20111018010003) do
|
|||
add_index "aspects", ["user_id"], :name => "index_aspects_on_user_id"
|
||||
|
||||
create_table "comments", :force => true do |t|
|
||||
t.text "text", :null => false
|
||||
t.integer "commentable_id", :null => false
|
||||
t.integer "author_id", :null => false
|
||||
t.string "guid", :null => false
|
||||
t.text "text", :null => false
|
||||
t.integer "commentable_id", :null => false
|
||||
t.integer "author_id", :null => false
|
||||
t.string "guid", :null => false
|
||||
t.text "author_signature"
|
||||
t.text "parent_author_signature"
|
||||
t.text "youtube_titles"
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
t.integer "likes_count", :default => 0, :null => false
|
||||
t.string "commentable_type", :default => "Post", :null => false
|
||||
t.integer "likes_count", :default => 0, :null => false
|
||||
t.string "commentable_type", :limit => 60, :default => "Post", :null => false
|
||||
end
|
||||
|
||||
add_index "comments", ["author_id"], :name => "index_comments_on_person_id"
|
||||
|
|
@ -364,12 +364,12 @@ ActiveRecord::Schema.define(:version => 20111018010003) do
|
|||
add_index "services", ["user_id"], :name => "index_services_on_user_id"
|
||||
|
||||
create_table "share_visibilities", :force => true do |t|
|
||||
t.integer "shareable_id", :null => false
|
||||
t.integer "shareable_id", :null => false
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
t.boolean "hidden", :default => false, :null => false
|
||||
t.integer "contact_id", :null => false
|
||||
t.string "shareable_type", :default => "Post", :null => false
|
||||
t.boolean "hidden", :default => false, :null => false
|
||||
t.integer "contact_id", :null => false
|
||||
t.string "shareable_type", :limit => 60, :default => "Post", :null => false
|
||||
end
|
||||
|
||||
add_index "share_visibilities", ["contact_id"], :name => "index_post_visibilities_on_contact_id"
|
||||
|
|
|
|||
Loading…
Reference in a new issue