Merge pull request #2232 from Pistos/postgresql-fix-photo-share-visibilities
PostgreSQL compatibility for FixPhotoShareVisibilities migration.
This commit is contained in:
commit
ff10f563ce
1 changed files with 18 additions and 2 deletions
|
|
@ -2,9 +2,25 @@ class FixPhotoShareVisibilities < ActiveRecord::Migration
|
||||||
class Photo < ActiveRecord::Base; end
|
class Photo < ActiveRecord::Base; end
|
||||||
|
|
||||||
def self.up
|
def self.up
|
||||||
raise 'migration currently only compatable with mysql' if postgres?
|
return if ! Photo.first.respond_to?(:tmp_old_id)
|
||||||
|
|
||||||
if Photo.first.respond_to?(:tmp_old_id)
|
if postgres?
|
||||||
|
['aspect_visibilities', 'share_visibilities'].each do |vis_table|
|
||||||
|
execute "UPDATE #{vis_table} SET shareable_type = 'Post'"
|
||||||
|
|
||||||
|
execute %{
|
||||||
|
UPDATE
|
||||||
|
#{vis_table}
|
||||||
|
SET
|
||||||
|
shareable_type = 'Photo'
|
||||||
|
, shareable_id = photos.id
|
||||||
|
FROM
|
||||||
|
photos
|
||||||
|
WHERE
|
||||||
|
#{vis_table}.shareable_id = photos.tmp_old_id
|
||||||
|
}
|
||||||
|
end
|
||||||
|
else
|
||||||
['aspect_visibilities', 'share_visibilities'].each do |vis_table|
|
['aspect_visibilities', 'share_visibilities'].each do |vis_table|
|
||||||
ActiveRecord::Base.connection.execute <<SQL
|
ActiveRecord::Base.connection.execute <<SQL
|
||||||
UPDATE #{vis_table}
|
UPDATE #{vis_table}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue