Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Reset Yourself Free

Reset Yourself Free

When was the last time you ran rake db:reset locally?

My guess is not recently. Nor do you think of doing it frequently. And I want to persuade you that deleting your precious local environment this way is a Very Good Thing Indeed.

Because, friends, db:reset will not only delete your database, but it will seed it too.

And by spending quality time with your seeds file, I believe you’ll make your entire development team more productive.

You’ll give your project the opportunity to grow its own shared development environment – a beautiful, idealistic place where all devs can talk through the same problem in the same context.

Here's a supporting post 👇🏽
https://christhesoul.com/2019/05/06/seeds-rails-and-you.html

Chris Waters

May 01, 2019
Tweet

Other Decks in Programming

Transcript

  1. !8

  2. # activerecord/lib/active_record/railties/databases.rake desc 'Drops and recreates the db from db/schema.rb

    and loads seeds.' task reset: [ "db:drop", "db:setup" ] desc "Creates the database, loads the schema, and inits with seed data" task setup: ["db:schema:load_if_ruby", "db:structure:load_if_sql", :seed]
  3. # activerecord/lib/active_record/railties/databases.rake desc 'Drops and recreates the db from db/schema.rb

    and loads seeds.' task reset: [ "db:drop", "db:setup" ] desc "Creates the database, loads the schema, and inits with seed data" task setup: ["db:schema:load_if_ruby", "db:structure:load_if_sql", :seed]
  4. # activerecord/lib/active_record/railties/databases.rake desc 'Drops and recreates the db from db/schema.rb

    and loads seeds.' task reset: [ "db:drop", "db:setup" ] desc "Creates the database, loads the schema, and inits with seed data" task setup: ["db:schema:load_if_ruby", "db:structure:load_if_sql", :seed]
  5. # databases.rake desc "Loads the seed data from db/seeds.rb" task

    seed: :load_config do db_namespace["abort_if_pending_migrations"].invoke ActiveRecord::Tasks::DatabaseTasks.load_seed end
  6. # databases.rake desc "Loads the seed data from db/seeds.rb" task

    seed: :load_config do db_namespace["abort_if_pending_migrations"].invoke ActiveRecord::Tasks::DatabaseTasks.load_seed end
  7. # Two seed files # db/seeds/people.rb # db/seeds/pies.rb # db/seeds.rb

    %w[ people pies ].each do |seed| require_relative("seeds/#{seed}") end
  8. class Seeder SEEDS = %w[people pies] def seed! SEEDS.each do

    |seed| require_relative("seeds/#{seed}") end end end
  9. class Seeder SEEDS = %w[people pies] def initialize @seeds =

    ENV["seedfile"] || SEEDS end def seed! Array(@seeds).each do |seed| require_relative("seeds/#{seed}") end end end
  10. class Seeder SEEDS = %w[people pies] def initialize @seeds =

    ENV["seedfile"] || SEEDS end def load_seed Array(@seeds).each do |seed| require_relative("seeds/#{seed}") end end end