Skip to content

Commit

Permalink
made migrations more robust
Browse files Browse the repository at this point in the history
molily committed Dec 1, 2009
1 parent 7d172bc commit aec0190
Showing 2 changed files with 20 additions and 9 deletions.
18 changes: 13 additions & 5 deletions db/migrate/20091104114243_new_jsonobject_to_flexitypes.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
class NewJsonobjectToFlexitypes < ActiveRecord::Migration
def self.up
puts 'NewJsonobjectToFlexitypes'
Category.all.each do |category|
puts "Migrating category '#{category.title}' (ID #{category.id})"
json = JSON.parse(category.schema_json, :create_additions => false)
next if json.has_key?('json_class')
json['json_class'] = "JsonObject::Schema"
@@ -32,12 +34,18 @@ def self.up
end

Document.all.each do |document|
json = JSON.parse(document.meta_json, :create_additions => false)
next if json.has_key?('json_class')
json['json_class'] = "JsonObject::Store"
document.meta_json = json.to_json
document.save
puts "Migrating document '#{document.title}' (ID #{document.id})"
begin
json = JSON.parse(document.meta_json, :create_additions => false)
next if json.has_key?('json_class')
json['json_class'] = "JsonObject::Store"
document.meta_json = json.to_json
document.save
rescue
puts "Error in Document #{document.id} #{document.title}"
end
end

end

def self.down
11 changes: 7 additions & 4 deletions db/migrate/20091112172212_get_dimensions_from_existing_files.rb
Original file line number Diff line number Diff line change
@@ -9,10 +9,13 @@ def self.up
puts " Posterframe: #{dim}"
end
if asset.file? && asset.file.is_image?
dim = Paperclip::Geometry.from_file(asset.file.path(:original))
asset.file_width = dim.width
asset.file_height = dim.height
puts " File: #{dim}"
filepath = asset.file.path(:original)
if File.exist?(filepath)
dim = Paperclip::Geometry.from_file(filepath)
asset.file_width = dim.width
asset.file_height = dim.height
puts " File: #{dim}"
end
end
asset.save
end

0 comments on commit aec0190

Please sign in to comment.