Do know about database version control? It's called migrations and here I will tell you how to do it in a simple way.
If you know about it and work with JavaScript, you probably have tried one of these tools to handle database migrations: Sequelize, TypeORM, Bookshelf, etc… But, seriously… Are you happy with these options? I'm not.
Since I started to work with Java and met the beautiful Flyway, I was missing a tool as great as it is in another languages. And now comes the good news: there's a "dockerized" version that you can use with any language you want!
So if you trust me, keep reading about this magical tool.
The examples bellow are here: https://github.com/arojunior/tests-with-nodejs-graphql
Then we can create the config file and the migrations, as you can see in the volumes arguments.
Those names for the migration files are following a convention that you can find here in the documentation, but it's very simple:
Did you notice that the file extension is .sql? Yes! You are able to write plain SQL scripts and don't need to learn a new syntax or object mappings. That's what I love in this tool.
Flyway will create a table to manage the migrations and it runs automagically every time you start the container. It will check the applied scripts and run the new ones. No additional command is needed, you just have to create the new files in the specified folder.
Flyway supports also SQL Server, Postgres, Oracle, MariaDB and more…
Take a look in the documentation for more infos: https://flywaydb.org/documentation/migrations
Now clap your hands for this amazing tool.
Top comments (0)