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
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.