This repository has been archived on 2020-05-27. You can view files and clone it, but cannot push or open issues/pull-requests.
tuxbliki/schema/migrations/012_album_thumbnail_migrati...

14 lines
377 B
Ruby
Raw Permalink Normal View History

2008-07-03 12:37:33 -04:00
class AlbumThumbnailMigration < ActiveRecord::Migration
def self.up
add_column :albums, :album_thumbnail_id, :integer
add_index :albums, :album_thumbnail_id
Album.find(:all).each do |album|
album.update_attribute :album_thumbnail_id, (album.photos.first.id rescue nil)
end
end
def self.down
remove_column :albums, :album_thumbnail_id
end
end