Skip to content

tomkurt/reversible_data_migration

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Reversible Data Migration

Need to update a small amount of data in migration? But still want to make it reversable? Reversable Data Migration comes to the rescue.

Example usage

class RemoveStateFromProduct < ActiveRecord::Migration
  def self.up
    backup_data = []
    Product.all.each do |product|
      backup_data << {:id => product.id, :state => product.state}
    end
    backup backup_data
    remove_column :products, :state
  end
  def self.down
    add_column :products, :state, :string
    restore Product
  end
end

Installing

gem install reversible_data_migration

Rails 2 & 3 supported

About

Makes data migrations reversible. Backup data is saved to yaml files. The reverse process loads the yaml and restores the records. Works for new and update but not for delete.

Resources

Stars

4 stars

Watchers

1 watching

Forks

Packages

 
 
 

Contributors

Languages