I am new to Ruby and Rails and am curious about something.
In two different tutorials I am looking at they use different methods for populating a database with basic test information.
One uses "rake db:seed" to pull from a text file with sample data.
The other uses "rake db:fixtures:load".
To me they appear to do the exact same thing.
Do they, or am I missing something here? (Highly likely)
When you run rake db:seed it will load all the admin data into your application. Rails seeding is generally for development and/or staging environments, there are only a few uses in production. You don't want your production application to seed dummy users!
Rails seed files are a useful way of populating a database with the initial data needed for a Rails project. The Rails db/seeds. rb file contains plain Ruby code and can be run with the Rails-default rails db:seed task.
rake is a Make-like program implemented in Ruby. rails is a web framework, which also has some rake tasks. This means that you can have a ruby program with rake but without rails, but not the other way around. By itself, rake will be faster because you don't need to load the whole rails application.
db:prepare: Runs setup if the database does not exist. Otherwise, it runs the migrations. db:reset: Resets your database using your migrations for the current environment. It does this by running the db:drop , db:create , db:migrate tasks.
rake db:seed
loads the data from db/seeds.rb into the database. This is generally used for development and production databases. It's permanent data that you use to start an empty application. More information here.
rake db:fixtures:load
loads the test fixtures into the test database. This is temporary data used solely by the tests. You can think of fixtures as sample data.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With