Skip to content

Instantly share code, notes, and snippets.

@raghubetina
Last active December 8, 2020 15:45
Show Gist options
  • Select an option

  • Save raghubetina/9b1dd3f6fcb0a459b6244c379628c675 to your computer and use it in GitHub Desktop.

Select an option

Save raghubetina/9b1dd3f6fcb0a459b6244c379628c675 to your computer and use it in GitHub Desktop.

Revisions

  1. raghubetina revised this gist May 16, 2017. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions seeding.md
    Original file line number Diff line number Diff line change
    @@ -29,10 +29,10 @@ bundle install
    Then run the following command:

    ```bash
    rake db:seed:dump EXCLUDE=
    rake db:seed:dump EXCLUDE=[]
    ```

    This will replace your existing `db/seeds.rb` file (say "yes" if it asks your permission to overwrite).
    This will replace your existing `db/seeds.rb` file (say "yes" if it asks your permission to overwrite). (You could also choose to exclude certain columns.)

    You can now `rake db:seed` whenever you want to re-create your data; for example, if things get into a bad state, you can

  2. raghubetina revised this gist May 16, 2017. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion seeding.md
    Original file line number Diff line number Diff line change
    @@ -50,4 +50,4 @@ The other way to go is to write some plain old Ruby yourself to do the work of C

    ## From a CSV

    [Here is a guide to seeding from a CSV file.](https://gist.github.com/arjunvenkat/1115bc41bf395a162084)
    [Here is a guide to seeding from a CSV file.](https://guides.firstdraft.com/loading-data-from-a-csv-file-into-your-database.html)
  3. raghubetina revised this gist Jun 23, 2016. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion seeding.md
    Original file line number Diff line number Diff line change
    @@ -29,7 +29,7 @@ bundle install
    Then run the following command:

    ```bash
    rake db:seed:dump EXCLUDE=[]
    rake db:seed:dump EXCLUDE=
    ```

    This will replace your existing `db/seeds.rb` file (say "yes" if it asks your permission to overwrite).
  4. raghubetina revised this gist Jun 3, 2016. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion seeding.md
    Original file line number Diff line number Diff line change
    @@ -50,4 +50,4 @@ The other way to go is to write some plain old Ruby yourself to do the work of C

    ## From a CSV

    [Follow Arjun's guide to seeding from a CSV file.](https://gist.github.com/arjunvenkat/1115bc41bf395a162084)
    [Here is a guide to seeding from a CSV file.](https://gist.github.com/arjunvenkat/1115bc41bf395a162084)
  5. raghubetina revised this gist Jun 3, 2016. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions seeding.md
    Original file line number Diff line number Diff line change
    @@ -48,3 +48,6 @@ to reset. You can re-run `rake db:seed:dump EXCLUDE=[]` at any time to overwrite

    The other way to go is to write some plain old Ruby yourself to do the work of CRUDing some starter data. I often use the [faker gem](https://github.com/stympy/faker) to help with this; [here is an example](https://github.com/firstdraft/listception_auth/blob/master/db/seeds.rb).

    ## From a CSV

    [Follow Arjun's guide to seeding from a CSV file.](https://gist.github.com/arjunvenkat/1115bc41bf395a162084)
  6. raghubetina revised this gist Jun 3, 2016. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion seeding.md
    Original file line number Diff line number Diff line change
    @@ -42,7 +42,7 @@ rake db:migrate
    rake db:seed
    ```

    to reset.
    to reset. You can re-run `rake db:seed:dump EXCLUDE=[]` at any time to overwrite your `db/seeds.rb` again with the current state of your tables.

    ## Write some Ruby yourself

  7. raghubetina revised this gist Jun 3, 2016. 1 changed file with 5 additions and 0 deletions.
    5 changes: 5 additions & 0 deletions seeding.md
    Original file line number Diff line number Diff line change
    @@ -43,3 +43,8 @@ rake db:seed
    ```

    to reset.

    ## Write some Ruby yourself

    The other way to go is to write some plain old Ruby yourself to do the work of CRUDing some starter data. I often use the [faker gem](https://github.com/stympy/faker) to help with this; [here is an example](https://github.com/firstdraft/listception_auth/blob/master/db/seeds.rb).

  8. raghubetina created this gist Jun 3, 2016.
    45 changes: 45 additions & 0 deletions seeding.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,45 @@
    # Seeding your database

    It is very helpful to take the time to pre-populate your database with some dummy data before you start working on any features. It's nice to have some data to look at to see whether you are going down the right path.

    It's also very helpful to other developers on the project, so they can get started quickly right after they clone.

    Here are two ways to create seed data:

    ## Manually + `seed_dump`

    The simplest way is to use the forms that were written by the generator, and manually enter some realistic data.

    (It might help to at least replace the `<input type="text" ...>`s for foreign keys with `<%= select_tag ... %>`s before doing this, to make your life a little easier.)

    Once you've added some data to your tables manually, we can use the [seed_dump gem](https://github.com/rroblak/seed_dump) to automatically generate a `db/seeds.rb` file for us:

    Add the gem:

    ```ruby
    # Gemfile

    gem "seed_dump"
    ```

    ```bash
    bundle install
    ```

    Then run the following command:

    ```bash
    rake db:seed:dump EXCLUDE=[]
    ```

    This will replace your existing `db/seeds.rb` file (say "yes" if it asks your permission to overwrite).

    You can now `rake db:seed` whenever you want to re-create your data; for example, if things get into a bad state, you can

    ```bash
    rake db:drop
    rake db:migrate
    rake db:seed
    ```

    to reset.