From 2c89a71958f9dac0f457865495653095d952ff2c Mon Sep 17 00:00:00 2001 From: Pistos Date: Sun, 23 Oct 2011 21:03:54 -0400 Subject: [PATCH] PostgreSQL compatibility for FixPhotoShareVisibilities migration. --- ...1023230730_fix_photo_share_visibilities.rb | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/db/migrate/20111023230730_fix_photo_share_visibilities.rb b/db/migrate/20111023230730_fix_photo_share_visibilities.rb index 7ed466152..18a89425a 100644 --- a/db/migrate/20111023230730_fix_photo_share_visibilities.rb +++ b/db/migrate/20111023230730_fix_photo_share_visibilities.rb @@ -2,9 +2,25 @@ class FixPhotoShareVisibilities < ActiveRecord::Migration class Photo < ActiveRecord::Base; end 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| ActiveRecord::Base.connection.execute <