We write about Ruby on Rails, React.js, React Native, remote work, open source, engineering and design.
Rails 6.0 was recently released.
Rails 6 adds rails db:prepare to migrate or setup a database if it doesn't exist.
Before Rails 6, we had to run the following tasks to set up the database.
1# create the database
2rails db:create
3
4# run the migrations
5rails db:migrate
6
7# prepopulate the database with initial/default data
8rails db:seed
Rails 6,
adds rails db:prepare
to get rid of
running all the above tasks individually.
rails db:prepare
first calls the migrate
to run the migrations,
but if the database doesn't exist,
migrate
throws an ActiveRecord::NoDatabaseError
.
Once it is catched,
it performs the following operations:
Thus, rails db:prepare
saves a lot of
time spent on
running database tasks individually
while setting up an application
and finishes it
with just one command.
Here is the relevant pull request.