Database Setup So Simple, Your Cat May just Do It: Docker and Flyway Version | Weblog | bol.com


Image source

Alright, folks, unless you’re one of those rare people who own a genius cat that can code (and if you are, we need to talk), setting up a local database might seem like a daunting task. Fear not! With Docker and Flyway, it’s so straightforward that even your cat could do it — well, theoretically. So let’s dive into it!

The need

If an application is using a database for persistence, then it will need one which it can connect to locally, in order to run itself or its (integration) tests. The question is, what’s a convenient and efficient way to set a database up like that?

Ideally we would have a database setup which:

  • is only used locally
  • has the same schema and data every time
  • can be built up and broken down whenever we want
  • is easy to re-create every time

Let’s take a closer look at these statements:

Only used locally

It is important that the tasks we perform in local development do not affect our other environments (like staging or production). Data of each environment should only come from that environment to avoid pollution and potential confusion.

Has the same schema and data every time

The local database needs to be a reliable representation of our real database. The code expects a certain state and we need to guarantee it will find that state every time our database is created. Otherwise we can have anything from compilation failures to broken tests.

Can be built up and broken down whenever you want

The more control we have over this, the cooler the things we can do. How nice would it be if we could easily fire up the setup before a build and then break it down? And how nicer would it be if that was automatically happening by simply running the build?

Easy to re-create every time

The easier it is to re-create, the more likely we are to use it. I’m sure many of us have the experience of avoiding to run that terrible app locally because it’s just too much hassle.

Now, if only there was a setup that could guarantee all of the above…

Leave a Reply

Your email address will not be published. Required fields are marked *