Added PostgreSQL-compatible versions of raw SQL migration code in ShareAnything migration.
This commit is contained in:
parent
fdcd6d47ed
commit
0ef81d7112
1 changed files with 52 additions and 34 deletions
|
|
@ -2,6 +2,14 @@ class ShareAnything < ActiveRecord::Migration
|
|||
def self.up
|
||||
remove_foreign_key :aspect_visibilities, :posts
|
||||
|
||||
if postgres?
|
||||
execute "DROP INDEX index_aspect_visibilities_on_post_id_and_aspect_id"
|
||||
execute "DROP INDEX index_aspect_visibilities_on_post_id"
|
||||
execute "ALTER TABLE aspect_visibilities RENAME COLUMN post_id TO shareable_id"
|
||||
execute "ALTER TABLE aspect_visibilities ADD COLUMN shareable_type VARCHAR(255) NOT NULL DEFAULT 'Post'"
|
||||
execute "CREATE INDEX shareable_and_aspect_id ON aspect_visibilities ( shareable_id, shareable_type, aspect_id )"
|
||||
execute "CREATE INDEX index_aspect_visibilities_on_shareable_id_and_shareable_type ON aspect_visibilities ( shareable_id, shareable_type )"
|
||||
else
|
||||
start_sql = "ALTER TABLE aspect_visibilities "
|
||||
sql = []
|
||||
|
||||
|
|
@ -31,12 +39,21 @@ class ShareAnything < ActiveRecord::Migration
|
|||
|
||||
|
||||
execute(start_sql + sql.join(', ') + ';')
|
||||
end
|
||||
|
||||
|
||||
|
||||
remove_foreign_key :post_visibilities, :posts
|
||||
rename_table :post_visibilities, :share_visibilities
|
||||
|
||||
if postgres?
|
||||
execute "DROP INDEX index_post_visibilities_on_contact_id_and_post_id"
|
||||
execute "DROP INDEX index_post_visibilities_on_post_id_and_hidden_and_contact_id"
|
||||
execute "ALTER TABLE share_visibilities RENAME COLUMN post_id TO shareable_id"
|
||||
execute "ALTER TABLE share_visibilities ADD COLUMN shareable_type VARCHAR(60) NOT NULL DEFAULT 'Post'"
|
||||
execute "CREATE INDEX shareable_and_contact_id ON share_visibilities ( shareable_id, shareable_type, contact_id )"
|
||||
execute "CREATE INDEX shareable_and_hidden_and_contact_id ON share_visibilities ( shareable_id, shareable_type, hidden, contact_id )"
|
||||
else
|
||||
start_sql = "ALTER TABLE share_visibilities "
|
||||
sql = []
|
||||
|
||||
|
|
@ -61,6 +78,7 @@ class ShareAnything < ActiveRecord::Migration
|
|||
sql << "add index `shareable_and_hidden_and_contact_id` (`shareable_id`, `shareable_type`, `hidden`, `contact_id`)"
|
||||
|
||||
execute(start_sql + sql.join(', ') + ';')
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue