rolled up share_anything migration
This commit is contained in:
parent
e4b284da7f
commit
4cae3e9d62
1 changed files with 26 additions and 10 deletions
|
|
@ -34,20 +34,36 @@ class ShareAnything < ActiveRecord::Migration
|
|||
|
||||
|
||||
execute(start_sql + sql.join(', ') + ';')
|
||||
sql = []
|
||||
|
||||
|
||||
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(255) 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
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue