DEV Community

Discussion on: Dropping the working database (NO! NO! NO!)

Collapse
suprnova32 profile image
Patricio Cano • Edited on

Rails already has its own migration framework, which devise uses to set up the database changes needed for it to work.

I guess what Saral did wrong is not that he forgot to use migrations, but rather, to make a backup of the database.

If you are using PostgreSQL (which I recommend, it is way better than MySQL), you can use this command to create a copy of your DB:

createdb -T development_db development_db_copy

And when you want to restore your working copy to the backup, this one liner will drop the current one, create it from your backup and run rails db:migrate to bring everything up to date:

dropdb development_db && createdb -T development_db_copy development_db && bin/rails db:migrate
Collapse
saral profile image
Saral Karki Author

Yeap. I think this definitely does address my issue and how I could have worked around it. Will give it a go next time I am working with my database.

Thank you Patricio. :D