javah2database-migrationflywaymariadb-10.3

FlyWay configuration for several databases


I'm integrating FlyWay to the project. Besides of migrations for working database I would like to setup database with fixtures for integration tests during gitlab pipeline job(just for cases when somebody pushes the branch).

On project is used MariaDB, so I'm thinking now about such way: to add H2 database, to create migrations with testing fixtures for it. So for prod/staging/dev will be used MariadDb with its migrations, but during gitlab pipeline on one of jobs temporary will be used H2 with test fixtures.

So I have a couple of questions about this:


Solution

  • Is it a approach way, or this can be done 'simplier'?

    The simplest solution would be to configure your CI job in gitlab to use MariaDB service. This would guarantee that your test will be executed in the same environment as your production code. (take a look here: https://docs.gitlab.com/ee/ci/services/mysql.html)

    Another alternative to this is to configure testcontainers (https://www.testcontainers.org/). It allows you to startup empty db during test setup. However from my experience sometimes there are issues because it depends on docker so you work in "DIND mode".

    Can FlyWay be configured in such way to work with different databases?

    You can configure Flyway in a way that you would run different set of migration scripts depending on whatever you like (for example database driver). However, it requires some manual configuration and code writing that handles it and it is useful if in your tests (or production) you would like to use different databases (for example you want to test if you code works with postgres and mariadb)

    I found in documentation how depending on placeholders to run migrations.

    Well in principle you should have different configuration for tests and prod so you could separate it easily. Different application.properties should be enough for that but you can use FlyWay environments.