The existing environment might be your local development environment, or a colleague’s. It might be someone to whom you are distributing code.
All these have something in common: they are already using your application with an existing database.
These environments need a way to the database to the newest version. The new environment might be someone setting up your application for the first time.
It might be the developer you just hired getting her machine up and running.
A migration is just a regular Ruby class so you’re not limited to these functions.
For example after adding a column you could write code to set the value of that column for existing records (if necessary using your models).
But, when I checkout another branch and run rake db:migrate, Ideally the changes made my the migration in the previous branch should be removed from and the details of the new migration should get into This doesn't happen.
So, I did a rake db:rollback STEP=5, when I checked out a new branch and then did a db:migrate. ) doesn't exist in branch master (the file with code exists only in branch_1! So you can't rollback DB changes made in branch_1 from branch master.
The new environment doesn’t need anything upgraded; it needs to create a new database that mirrors your latest.
It may also need to seed the database with some defaults or dummy data. In ages past, we use migrations for new environments.
we do this are often glossed over by long-time Rails developers who know the history of the feature, leaving newcomers frustrated by a habit that seems confusing or redundant.