20140503000001_update_storage3.rb 767 B

12345678910111213141516171819202122232425262728
  1. class UpdateStorage3 < ActiveRecord::Migration
  2. def up
  3. add_column :store_files, :sha, :string, :limit => 128, :null => true
  4. add_index :store_files, [:sha], :unique => true
  5. add_column :store_provider_dbs, :sha, :string, :limit => 128, :null => true
  6. add_index :store_provider_dbs, [:sha], :unique => true
  7. Store::File.all.each {|file|
  8. next if file.sha
  9. sha = Digest::SHA256.hexdigest( file.content )
  10. file.update_attribute( :sha, sha )
  11. }
  12. Store::Provider::DB.all.each {|file|
  13. next if file.sha
  14. sha = Digest::SHA256.hexdigest( file.data )
  15. file.update_attribute( :sha, sha )
  16. }
  17. remove_column :store_files, :md5
  18. remove_column :store_provider_dbs, :md5
  19. end
  20. def down
  21. end
  22. end