20140823000001_update_recent_viewed_create_object_lookup.rb 686 B

123456789101112131415161718192021222324
  1. class UpdateRecentViewedCreateObjectLookup < ActiveRecord::Migration
  2. def up
  3. if !ActiveRecord::Base.connection.table_exists? 'object_lookups'
  4. create_table :object_lookups do |t|
  5. t.column :name, :string, :limit => 250, :null => false
  6. t.timestamps
  7. end
  8. add_index :object_lookups, [:name], :unique => true
  9. end
  10. RecentView.all.each {|entry|
  11. ro = RecentView::Object.find(entry.recent_view_object_id)
  12. lookup_id = ObjectLookup.by_name( ro.name )
  13. entry.update_attribute( :recent_view_object_id, lookup_id )
  14. entry.cache_delete
  15. }
  16. drop_table :recent_view_objects
  17. Cache.clear
  18. end
  19. def down
  20. end
  21. end