Subscribe to The Rails Future        RSS Feed
-----

Rails - How to backup and restore the current status of the database easily

Icon Leave Comment
While I'm a huge fan of THIS method which I detailed in a prior post, that method is only helpfull for setting up tables with very few records.

I just recently found myself in a situation where I built a rails app that interfaced with a C# program which was designed to migrate a database up the rails website. This C# app takes a long time to compile the database into TCP, and rails takes a while loading up it's own database. Naturally, I wanted to do away with this down time throughout the development process. But there's no chance in hell you will be able to get me to fill in thousands of records by hand. The answer was to run my migration program once so it setup all the tables, and then dump those tables to a datafile.

The gem that allows for this is called db_yaml, and it does what the name implies, converts a database to yaml.

ref: https://github.com/ludicast/yaml_db
ref: http://stackoverflow...xtures-in-rails


(Gemfile)
gem 'yaml_db'



My usage was

(save the current status of the database.)
$  rake db:data:dump 




(load up the database with the data last saved)
$  rake db:data:load




It looks like at the moment there is a bug against doing
rake db:data:dump_dir


...which would be more ideal for me, since I'd only like to save each table to an individual file within a directory... so yeah, bummer, but I don't mind. There was a bug in rails 3.0.7 which prevented it from functioning, but 3.0.8 is fine, and 3.0.9 is ideal but I gotta check that my webhost doesn't freak on me about these changes.

0 Comments On This Entry

 

Trackbacks for this entry [ Trackback URL ]

There are no Trackbacks for this entry

January 2022

S M T W T F S
      1
2345678
9101112131415
161718192021 22
23242526272829
3031     

Tags

    Search My Blog

    2 user(s) viewing

    2 Guests
    0 member(s)
    0 anonymous member(s)

    Categories