Liquibase multi-tenancy: update every schema

298 views Asked by At

I have separate DB schemas (could have used different DB instances) for each tenant to be able to cleanly separate their data.

For a single tenant setup the following container configuration is used:

...
  liquibase:
    image: "liquibase/liquibase:4.17.2"
    volumes:
      - ../migration:/liquibase/db/migration/
      - ./liquibase.properties:/liquibase/liquibase.properties
    command: --defaultsFile=liquibase.properties update
...

Each DB schema has to be updated the same way every time the changelog is updated.

My first idea is to create as many containers (short lived) as schemas, however that doesn't really scale that well if you have a lot of them (~100).

But is there a better way?

(eg. to execute the liquibase CLI for multiple schemas (multiple liquibase.properties?) in a single container - nothing found about that in their docs)

1

There are 1 answers

1
PJatLiquibase On BEST ANSWER

There's nothing in the Liquibase CLI to handle this. There are two options to consider:

  1. Create a custom docker image that has a bash script to call out to the Liquibase CLI multiple times or even in parallel.

  2. Create a customer docker image with custom Java code to call the Liquibase APIs to update all your databases at once. You can read more about how to create custom integrations here -> https://contribute.liquibase.com/extensions-integrations/integrations-overview/