Skip to content

andyatkinson/rails-with-seedster

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Rails App With Seedster

Initializer

Running rails g should show:

Seedster:
  seedster:initializer

This can be run with rails g seedster:initializer

Rake Tasks

$ rake -T seedster
rake seedster:dump  # Dump application seed data to a data dump file
rake seedster:load  # Load application seed data from a remote dump file

Testing The Flow

Even thought the intention is to create data dumps in production, we can create a dump locally for testing purposes.

Set Up

  • Create the Seedster initializer file by running the command above
  • Configure the users table in the Seedster tables configuration, e.g. %{SELECT * FROM users WHERE id = '%{user_id}'}
  • Populate the database, for example by using the Rails seeds, rake db:seed

Now we can run the data dump task.

Testing Data Dumps

rake seedster:dump USER_ID=1

The users data file should have been generated.

Testing Data Loads

  • To test loads, reset the database: rake db:reset
  • We should have the data file in the tmp dirs.
  • To clear out the database and reset it, check the section below Resetting the Database
  • We can truncate users, posts, comments via psql to empty the tables out if we've already loaded data
  • Seedster can be configured to load from local files, without trying to download. In the Seedster initializer file, set the option skip_download to true.

Now the load task can be run to load from the local data files.

rake seedster:load

We should now have users data, running User.first in rails console should return the User.

Resetting the Database

From a psql prompt:

truncate posts,users,comments;

ALTER SEQUENCE users_id_seq RESTART WITH 1;
ALTER SEQUENCE posts_id_seq RESTART WITH 1;
ALTER SEQUENCE comments_id_seq RESTART WITH 1;

About

Example application using Seedster gem

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published