fix photo share visibilities for the recently migrated

This commit is contained in:
danielgrippi 2011-10-23 16:37:36 -07:00
parent b78ed1b794
commit 75da4e560d
2 changed files with 25 additions and 1 deletions

View file

@ -0,0 +1,24 @@
class FixPhotoShareVisibilities < ActiveRecord::Migration
class Photo < ActiveRecord::Base; end
def self.up
raise 'migration currently only compatable with mysql' if postgres?
if Photo.first.respond_to?(:tmp_old_id)
['aspect_visibilities', 'share_visibilities'].each do
ActiveRecord::Base.connection.execute <<SQL
UPDATE #{vis_table}
SET shareable_type='Post'
SQL
ActiveRecord::Base.connection.execute <<SQL
UPDATE #{vis_table}, photos
SET #{vis_table}.shareable_type='Photo', #{vis_table}.shareable_id=photo.id
WHERE #{vis_table}.shareable_id=photos.tmp_old_id
SQL
end
end
end
def self.down
end
end

View file

@ -10,7 +10,7 @@
#
# It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20111021184041) do
ActiveRecord::Schema.define(:version => 20111023230730) do
create_table "aspect_memberships", :force => true do |t|
t.integer "aspect_id", :null => false