Search code examples
spring-bootmicroservicesliquibase

Share database with several microservices which use liquibase


I have to migrate old Spring Boot microservices whiten in 2015 which are using liquibase with Oracle database. So far from what I found all microservices use the same database url. This means only one database is used for every microservice.

Now I want to migrate the microservices using Postgres database. When I start different microservice I get message for different database scheme checksum. This is expected because the database migration scripts are executed by liquibase during miroservice statup.

What are the possible solutions to this problem? I see the same DB connection url link into every microservice which means the DB tables should be shared or there is another configuration that might be missing?


Solution

  • I hope that storing microservice databases in a single schema/database is not your end goal. So I think you might have big problems in the future if you use Liquibase this way.

    What I mean?

    If you move your microservices databases to other schemas or DB instances in the future, you will find that all metadata about the migration of all services is stored in one table maintained by Liquibase: databasechangelog. And distinguishing the data from this table will not be easy.

    I think you should think about different Liquibase tables for each microservice. Luckily, Liquibase provides a mechanism for this:

    Spring Boot Liquibase Description
    spring.liquibase.database-change-log-lock-table databaseChangeLogLockTableName Name of table to use for tracking concurrent Liquibase usage
    spring.liquibase.database-change-log-table databaseChangeLogTableName Name of table to use for tracking change history

    For exmaple, you have services S1, S2, ... SX. Then databasechangelog tables can look like this:

    • databasechangelog-s1
    • databasechangelog-s2
    • ...
    • databasechangelog-sx

    And of course you should do the same for the databasechangeloglock table.

    This approach will automatically solve your problems with conflicting checksums. If I understood your problem correctly.

    It can help you in the future. Just think about it.