Generate .sql files using rake task
I have a table called 'choices' in this table i am storing static data for my site like Blood Groups , qualification, job types etc., I have to create rake tasks one is for to create backup choices.sql file from choices table data, second one is dump the data from .sql file to choice table. How can I create the rake tasks.
Any other best way to take backup data from a table and load data into the table
Thanks开发者_如何学C
Sure,
the best way is to do a rake db:schema:dump and db:schema:load
with that you will have the schemas. To load data to your database you should add it through seeds (db/seeds.rb)
So if you want to load this data in your application you should:
- dump the schema
- load the schema
- load the seed data
it will solve your problem if you want to load your schema and initial data. It won't help you to restore a backup, that i think it's what you want as well
to help you with that you have an option dumping the data to YAML and reloading it on the other side. There is an good example of backup rake task here: http://blog.leetsoft.com/2006/5/29/easy-migration-between-databases
精彩评论