Skip to content

Commit

Permalink
cleaning up the migration, removing support for backward migrations a…
Browse files Browse the repository at this point in the history
…nd added an upgrade notes file
  • Loading branch information
Matthew Peychich committed Oct 10, 2009
1 parent 959cb0f commit 26e79a7
Show file tree
Hide file tree
Showing 41 changed files with 150 additions and 2,980 deletions.
1 change: 1 addition & 0 deletions README
@@ -1,5 +1,6 @@
How to get LovdByLess up and running

USERS WHO ARE UPGRADING READ THE UPGRADE NOTES

WINDOWS USERS READ THIS: http://www.gamutworks.net/blog/?p=17
UBUNTO USERS READ THIS: http://groups.google.com/group/lovdbyless/browse_thread/thread/d29043342c47f06?hl=en
Expand Down
2 changes: 2 additions & 0 deletions UPGRADE_NOTES
@@ -0,0 +1,2 @@
2009-10-09 - Upgrading from file_column to paperclip
This upgrade has no reverse migration provided. It is strongly recommended that production files and databases be backed up prior to upgrading and that this upgrade be tested locally in development before an upgrade is performed on production. If you have modified the default path for file_column, you will need to update the DEFAULT_FILE_COLUMN_PATH found in '20091006171847_move_to_paperclip.rb'. Once the upgrade is complete, delete the old file_column directories.
4 changes: 2 additions & 2 deletions app/helpers/photos_helper.rb
Expand Up @@ -9,8 +9,8 @@ def image photo, size = :square, img_opts = {}

def photo_path photo = nil, size = :square
path = nil
unless photo.nil? || photo.image.blank?
path = url_for_file_column(photo, :image, size.to_s) rescue nil
unless photo.image.exists?
path = photo.image.url(size) rescue nil
end
path = missing_photo_path(size) if path.nil?
return path
Expand Down
9 changes: 1 addition & 8 deletions app/models/photo.rb
Expand Up @@ -18,7 +18,7 @@ class Photo < ActiveRecord::Base

belongs_to :profile

has_attached_file :image, :styles => { :square => "50x50#", :small => "175x250>"}
has_attached_file :image, :styles => { :square => "50x50#", :small => "175x250>"}, :path => ":rails_root/public/system/:attachment/:id/:style/:basename.:extension"

validates_attachment_presence :image
validates_presence_of :profile_id
Expand All @@ -28,12 +28,5 @@ def after_create
feed_item = FeedItem.create(:item => self)
([profile] + profile.friends + profile.followers).each{ |p| p.feed_items << feed_item }
end

# file_column :image, :magick => {
# :versions => {
# :square => {:crop => "1:1", :size => "50x50", :name => "square"},
# :small => "175x250>"
# }
# }

end
17 changes: 8 additions & 9 deletions app/models/profile.rb
Expand Up @@ -78,15 +78,14 @@ class Profile < ActiveRecord::Base
set_property :min_prefix_len => 3, :morphology => false
end

has_attached_file :icon, :styles => { :big => "150x150#", :medium => "100x100#", :small => "50x50#" }, :default_url => "/avatar_default_:style.png"
#
# file_column :icon, :magick => {
# :versions => {
# :big => {:crop => "1:1", :size => "150x150", :name => "big"},
# :medium => {:crop => "1:1", :size => "100x100", :name => "medium"},
# :small => {:crop => "1:1", :size => "50x50", :name => "small"}
# }
# }
has_attached_file :icon,
:styles => {
:big => "150x150#",
:medium => "100x100#",
:small => "50x50#"
},
:default_url => "/avatar_default_:style.png",
:path => ":rails_root/public/system/:attachment/:id/:style/:basename.:extension"

cattr_accessor :featured_profile
@@featured_profile = {:date=>Date.today-4, :profile=>nil}
Expand Down
2 changes: 1 addition & 1 deletion config/initializers/avatar_sources.rb
Expand Up @@ -7,7 +7,7 @@
require 'sized_gravatar_source'

# order:
# 1. FileColumn(Profile#icon)
# 1. Paperclip(Profile#icon)
# 2. Gravatar(Profile#email), with default
# a RailsAssetSourceWrapper containing
# a StringSubstitutionSourceWrapper containing
Expand Down
2 changes: 0 additions & 2 deletions config/initializers/file_column_settings.rb

This file was deleted.

67 changes: 7 additions & 60 deletions db/migrate/20091006171847_move_to_paperclip.rb
@@ -1,4 +1,6 @@
class MoveToPaperclip < ActiveRecord::Migration
DEFAULT_FILE_COLUMN_PATH = File.join(RAILS_ROOT, "public", 'system')

def self.up
# Profiles
add_column :profiles, :icon_file_name, :string
Expand All @@ -7,8 +9,8 @@ def self.up
add_column :profiles, :icon_updated_at, :datetime

Profile.find_each do |profile|
next unless profile.old_icon
profile.icon = File.new(profile.old_icon)
next unless profile.read_attribute('icon')
profile.icon = File.new(File.join(DEFAULT_FILE_COLUMN_PATH, 'profile', 'icon', profile.id.to_s, profile.read_attribute('icon')))
profile.save
end

Expand All @@ -21,70 +23,15 @@ def self.up
add_column :photos, :image_updated_at, :datetime

Photo.find_each do |photo|
next unless photo.old_image
photo.image = File.new(profile.old_image)
next unless photo.read_attribute('image')
photo.image = File.new(File.join(DEFAULT_FILE_COLUMN_PATH, 'photo', 'image', photo.id.to_s, photo.read_attribute('image')))
photo.save
end

remove_column :photos, :image
end

def self.down
# Profiles
add_column :profiles, :icon, :string

Profile.find_each do |profile|
next unless profile.icon
profile.old_icon = File.new(profile.icon.path)
profile.save
end

remove_column :profiles, :icon_updated_at
remove_column :profiles, :icon_file_size
remove_column :profiles, :icon_content_type
remove_column :profiles, :icon_file_name

# Photos
add_column :photos, :image, :string

Photo.find_each do |photo|
next unless photo.image
photo.old_image = File.new(photo.image.path)
photo.save
end

remove_column :photos, :image_updated_at
remove_column :photos, :image_file_size
remove_column :photos, :image_content_type
remove_column :photos, :image_file_name
raise ActiveRecord::IrreversibleMigration.new('The migrations from file_column to paperclip is not reversable')
end
end


# just for redundancy. we want this to be a reverdable migration.
class Profile < ActiveRecord::Base
file_column :icon, :magick => {
:versions => {
:big => {:crop => "1:1", :size => "150x150", :name => "big"},
:medium => {:crop => "1:1", :size => "100x100", :name => "medium"},
:small => {:crop => "1:1", :size => "50x50", :name => "small"}
}
}
alias_method :old_icon=, :icon=
alias_method :old_icon, :icon

has_attached_file :icon, :styles => { :big => "150x150>", :medium => "100x100>", :small => "50x50>" }
end

class Photo < ActiveRecord::Base
file_column :image, :magick => {
:versions => {
:square => {:crop => "1:1", :size => "50x50", :name => "square"},
:small => "175x250>"
}
}
alias_method :old_image=, :image=
alias_method :old_image, :image

has_attached_file :image, :styles => { :square => "50x50#", :small => "175x250>"}
end
8 changes: 4 additions & 4 deletions test/functional/profiles_controller_test.rb
Expand Up @@ -124,19 +124,19 @@ class ProfilesControllerTest < ActionController::TestCase
#raise (p.send :icon_state).inspect
assert_not_nil p.icon
get :show, {:id => p.id, :public_view => true}, {:user => p.id}
assert_tag :img, :attributes => { :src => /\/system\/icons\/\d*\/big\/user.png/ }
assert_tag :img, :attributes => { :src => /\/icons\/\d*\/big\/user.png/ }
end

should 'use gravatar otherwise' do
p = profiles(:user2)
assert !p.icon.file?
assert !p.icon.exists?
get :show, {:id => p.id}, {:user => p.id, :public_view => true}
assert_tag :img, :attributes => {:src => /www\.gravatar\.com/}
end

should 'send the app\'s internal default as the default to gravatar' do
p = profiles(:user2)
assert !p.icon.file?
assert !p.icon.exists?
get :show, {:id => p.id}, {:user => p.id, :public_view => true}
assert_tag :img, :attributes => { :src => /http...www.gravatar.com\/avatar\/[0-9a-f]+\?size\=50&amp;default\=http...test\.host\/images\/avatar_default_small\.png/ }
end
Expand All @@ -148,7 +148,7 @@ class ProfilesControllerTest < ActionController::TestCase
assert_not_nil profiles(:user).icon
post :delete_icon, {:id => profiles(:user).id, :format => 'js'}, {:user => profiles(:user).id}
assert_response :success
assert !assigns(:p).reload.icon.file?
assert !assigns(:p).reload.icon.exists?
end
end

Expand Down
5 changes: 4 additions & 1 deletion vendor/gems/colored-1.1/.specification
Expand Up @@ -27,10 +27,13 @@ files:
- test/colored_test.rb
has_rdoc: false
homepage: http://errtheblog.com/
licenses: []

post_install_message:
rdoc_options: []

require_paths:
- bin
- lib
required_ruby_version: !ruby/object:Gem::Requirement
requirements:
Expand All @@ -47,7 +50,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
requirements: []

rubyforge_project:
rubygems_version: 1.3.1
rubygems_version: 1.3.5
signing_key:
specification_version: 2
summary: Add some color to your life.
Expand Down
5 changes: 4 additions & 1 deletion vendor/gems/gcnovus-avatar-0.0.7/.specification
Expand Up @@ -51,6 +51,8 @@ files:
- lib/avatar.rb
has_rdoc: true
homepage: http://github.com/gcnovus/avatar
licenses: []

post_install_message:
rdoc_options:
- --line-numbers
Expand All @@ -60,6 +62,7 @@ rdoc_options:
- --charset
- utf-8
require_paths:
- bin
- lib
required_ruby_version: !ruby/object:Gem::Requirement
requirements:
Expand All @@ -76,7 +79,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
requirements: []

rubyforge_project:
rubygems_version: 1.3.1
rubygems_version: 1.3.5
signing_key:
specification_version: 2
summary: Multi-source avatar support
Expand Down
5 changes: 4 additions & 1 deletion vendor/gems/mocha-0.9.3/.specification
Expand Up @@ -195,6 +195,8 @@ files:
- RELEASE
has_rdoc: true
homepage: http://mocha.rubyforge.org
licenses: []

post_install_message:
rdoc_options:
- --title
Expand All @@ -204,6 +206,7 @@ rdoc_options:
- --line-numbers
require_paths:
- bin
- bin
- lib
required_ruby_version: !ruby/object:Gem::Requirement
requirements:
Expand All @@ -220,7 +223,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
requirements: []

rubyforge_project: mocha
rubygems_version: 1.3.1
rubygems_version: 1.3.5
signing_key:
specification_version: 2
summary: Mocking and stubbing library
Expand Down
96 changes: 96 additions & 0 deletions vendor/gems/paperclip-2.1.2/.specification
@@ -0,0 +1,96 @@
--- !ruby/object:Gem::Specification
name: paperclip
version: !ruby/object:Gem::Version
version: 2.1.2
platform: ruby
authors:
- Jon Yurek
autorequire:
bindir: bin
cert_chain: []

date: 2008-05-13 00:00:00 -04:00
default_executable:
dependencies: []

description:
email: jyurek@thoughtbot.com
executables: []

extensions: []

extra_rdoc_files:
- README
files:
- README
- LICENSE
- Rakefile
- init.rb
- generators/paperclip
- generators/paperclip/paperclip_generator.rb
- generators/paperclip/templates
- generators/paperclip/templates/paperclip_migration.rb
- generators/paperclip/USAGE
- lib/paperclip
- lib/paperclip/attachment.rb
- lib/paperclip/geometry.rb
- lib/paperclip/iostream.rb
- lib/paperclip/storage.rb
- lib/paperclip/thumbnail.rb
- lib/paperclip/upfile.rb
- lib/paperclip.rb
- tasks/paperclip_tasks.rake
- test/database.yml
- test/debug.log
- test/fixtures
- test/fixtures/12k.png
- test/fixtures/50x50.png
- test/fixtures/5k.png
- test/fixtures/bad.png
- test/fixtures/text.txt
- test/helper.rb
- test/s3.yml
- test/test_attachment.rb
- test/test_geometry.rb
- test/test_integration.rb
- test/test_iostream.rb
- test/test_paperclip.rb
- test/test_storage.rb
- test/test_thumbnail.rb
has_rdoc: true
homepage: http://www.thoughtbot.com/
licenses: []

post_install_message:
rdoc_options:
- --line-numbers
- --inline-source
require_paths:
- lib
required_ruby_version: !ruby/object:Gem::Requirement
requirements:
- - ">="
- !ruby/object:Gem::Version
version: "0"
version:
required_rubygems_version: !ruby/object:Gem::Requirement
requirements:
- - ">="
- !ruby/object:Gem::Version
version: "0"
version:
requirements:
- ImageMagick
rubyforge_project: paperclip
rubygems_version: 1.3.5
signing_key:
specification_version: 2
summary: File attachments as attributes for ActiveRecord
test_files:
- test/test_attachment.rb
- test/test_geometry.rb
- test/test_integration.rb
- test/test_iostream.rb
- test/test_paperclip.rb
- test/test_storage.rb
- test/test_thumbnail.rb

0 comments on commit 26e79a7

Please sign in to comment.