I am trying to figure out an approach to load in our initial data into
our
database.
I have written some load_data migrations which populate a lot of the
stuff,
how some of the database
items are images etc and I am trying to figure out how to approach added
them to the database
during a rake db:migrate
I am thinking if I store the files in a folder off the RAILS_ROOT I
should
be able to run code in the migration
script to add them to the database. Does this sound like a valid
approach?
I am thinking if I store the files in a folder off the RAILS_ROOT I
should be able to run code in the migration
script to add them to the database. Does this sound like a valid
approach?
Thanks,
Keith
Here’s one way of building initial data into a migration. I put the
data into a subdirectory of db/migrate called ‘initial_data’ so it’s
a bit more clear that it was relevant at a particular point in time.
You could certainly get the data some other way that using YAML
fixtures loaded by ActiveRecord, but that all depends on what format
your data has now.
Borogrove.reset_column_information
say_with_time("Load initial data from fixture") do
directory = File.join(File.dirname(__FILE__), "initial_data")
say "Fixture directory is: #{directory}", true
Fixtures.create_fixtures(directory, Borogrove.table_name)
end