Skip to content

Instantly share code, notes, and snippets.

@BrianTheCoder
Created September 22, 2008 19:06
Show Gist options
  • Select an option

  • Save BrianTheCoder/12097 to your computer and use it in GitHub Desktop.

Select an option

Save BrianTheCoder/12097 to your computer and use it in GitHub Desktop.
migration 2, :new_image_handling do
up do
modify_table :users do
add_column :avatar_file_name, String, :length => 0..200, :nullable => true
add_column :avatar_content_type, String, :length => 0..200, :nullable => true
add_column :avatar_file_size, Integer
add_column :profile_image_file_name, String, :length => 0..200, :nullable => true
add_column :profile_image_content_type, String, :length => 0..200, :nullable => true
add_column :profile_image_file_size, Integer
end
modify_table :submissions do
add_column :thumb_file_name, String, :length => 0..200, :nullable => true
add_column :thumb_content_type, String, :length => 0..200, :nullable => true
add_column :thumb_file_size, Integer
add_column :image_file_name, String, :length => 0..200, :nullable => true
add_column :image_content_type, String, :length => 0..200, :nullable => true
add_column :image_file_size, Integer
end
ProfileImage.all.each do |img|
u = img.user
u.profile_image = File.new(img.location)
u.save
end
Avatar.all.each do |img|
u = img.user
u.avatar = File.new(img.location)
u.save
end
SubmissionImage.all.each do |img|
s = img.submission
s.image = File.new(img.location)
s.save
end
SubmissionThumb.all.each do |img|
s = img.submission
s.thumb = File.new(img.location)
s.save
end
end
down do
modify_table :users do
drop_columns :avatar_file_name,
:avatar_content_type,
:avatar_file_size,
:profile_image_file_name,
:profile_image_content_type,
:profile_image_file_size
end
modify_table :submissions do
drop_columns :thumb_file_name,
:thumb_content_type,
:thumb_file_size,
:image_file_name,
:image_content_type,
:image_file_size
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment