This project illustrates the approach described in my article, which allows squashing (compacting) database migrations into a single file using Testcontainers. This can result in a reduced test execution time in certain cases.
The example project uses:
- Spring Boot 3,
- Flyway migrations,
- PostgreSQL,
- Testcontainers.
Yet, the approach should look rather similar with different framework and databases.
The project uses Maven as its build tool, so it's enough to run:
./mvnw clean verify
I recommend reading the article before digging into the code.
There are three classes that could be used as a good entry points:
- SquashDbMigrationsManualContainerManagementTest using manual DB container setup via JDBC URL scheme.
- SquashDbMigrationsAutoContainerManagementTest using automated DB container setup via JDBC URL scheme.
- PostgresDumper dumping DB schema of a running container into a set of SQL statements.
Database migrations can be found within the db.migration directory.
The output of squashing procedure is stored within the init.sql file.