Running rails g
should show:
Seedster:
seedster:initializer
This can be run with rails g seedster:initializer
$ 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
Even thought the intention is to create data dumps in production, we can create a dump locally for testing purposes.
- 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.
rake seedster:dump USER_ID=1
The users data file should have been generated.
- 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
viapsql
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
totrue
.
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.
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;