I''d like to be able to regenerate my development database, tables and data, from script, so that if I ever have a bug in my development code, I can easily get the database back into a known state. What is the best way to do this? Can I use fixtures to populate the tables? Can I share fixtures between tests and migrations? At the moment, I''m using migrations to do this. For example: class CreateFoodTable < ActiveRecord::Migration def self.up create_table "foods" do |t| t.column :name, :string t.column :grade, :string end Food.create({ :name => "Pasta", :grade => "Good" }) Food.create({ :name => "Fish", :grade => "Raw" }) end def self.down drop_table "foods" end end And then to regenerate the database, I''d run: rake migrate VERSION=0 rake migrate Any tips appreciated. Douglas --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
dblack-TKXtfPMJ4Ozk1uMJSBkQmQ@public.gmane.org
2006-Aug-27 19:09 UTC
Re: Migrations and fixtures
Hi -- On Sun, 27 Aug 2006, Douglas Livingstone wrote:> > I''d like to be able to regenerate my development database, tables and > data, from script, so that if I ever have a bug in my development > code, I can easily get the database back into a known state. > > What is the best way to do this? Can I use fixtures to populate the > tables? Can I share fixtures between tests and migrations?You can load any of the databases from your fixtures: rake db:fixtures:load and you can specify particular fixtures by appending FIXTURES=something,other and also of course choose a database/environment with RAILS_ENV=desired_environment. David -- http://www.rubypowerandlight.com => Ruby/Rails training & consultancy ----> SEE SPECIAL DEAL FOR RUBY/RAILS USERS GROUPS! <----- http://dablog.rubypal.com => D[avid ]A[. ]B[lack''s][ Web]log http://www.manning.com/black => book, Ruby for Rails http://www.rubycentral.org => Ruby Central, Inc. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---