DEV Community

loading...

How do you plan your database in development, before migrating to production?

Pacharapol Withayasakpunt
Currently interested in TypeScript, Vue, Kotlin and Python. Looking forward to learning DevOps, though.
・1 min read
  • Do you install database on your machine (like, on macOS), use a real online one (albeit, maybe temporary), like MongoDB Atlas, or use temporary alternative (like SQLite)?
  • Do you snapshot, perhaps to rollback database schema, if necessary? I find this convenient with SQLite and Git, but what are professional alternatives?
  • How do you migrate development database to production database? Schema-only, or with records? Is ORM necessary or sufficient?

Discussion (5)

Collapse
ronald_arias profile image
Ron

My approach is to use Docker to run an instance of my database server locally.
The idea is to keep my local and prod DBs in sync, but for the local one to be easily destroyed and recreated.
For this I use schema migrations. I've created a project in which I leverage ActiveRecord migrations to keep my DBs in sync (whether they belong to ruby apps or not).
That way I can go up or down in specific changes, both in prod and dev, or simply redo my local one. You could do the prod one as well, but not recommended.

Hope it helps

Collapse
adaendra profile image
Maxime Guilbert • Edited
  1. Like Ron, I use a Docker image. It's the easiest way to keep the same config in all your environment.

  2. I only do snapshots to keep a version of my database in case of crash, and store it in a S3 bucket in AWS.

  3. About migrate your development DB to prod, it will depend on your case and your project. Generally, I only migrate schemas manually.

I hope it will help you

Collapse
ajeebkp23 profile image
Ajeeb.K.P • Edited
  1. I install Mysql/Postgres/MongoDB locally using apt/flatpak/snap. And I use systemctl enable/disable/start/stop if not using any service/ not required.
  2. Keep backup of data with tools like mysqldump/pg_dump. Roll back is done by ORM's migrations (I use Django and Laravel by the way, both support rollbacks)
  3. I migrate with ORM.

My scenarios mostly include users under 1000 in numbers. Of which daily users may be under 100. Of course, I may need to change if more number of users are active.

Collapse
bias profile image
Tobias Nickel

knex migrations are very good as tou have good control over the updates. but they need test before getting to prod. and still doing a backup is to be save. you never want to need it.

Collapse
muzammilaalpha profile image
muzammilaalpha

thanks