https://github.com/andyatkinson/rails-with-seedster
Example application using Seedster gem
https://github.com/andyatkinson/rails-with-seedster
Last synced: about 2 months ago
JSON representation
Example application using Seedster gem
- Host: GitHub
- URL: https://github.com/andyatkinson/rails-with-seedster
- Owner: andyatkinson
- Created: 2019-08-02T16:17:44.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2023-01-19T14:03:44.000Z (over 2 years ago)
- Last Synced: 2024-10-19T04:31:17.903Z (7 months ago)
- Language: Ruby
- Homepage: https://github.com/groupon/seedster
- Size: 44.9 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 8
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Rails App With Seedster
### Initializer
Running `rails g` should show:
```sh
Seedster:
seedster:initializer
```This can be run with `rails g seedster:initializer`
#### Rake Tasks
```sh
$ 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
```sh
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.
```sh
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:
```sql
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;
```