wesleyy
wesleyy

Reputation: 2735

Liquibase exclude schema name from changelog

I have a multi-tenant application. Each tenant has it's own schema in the database. All the schemas are logically the same, the only difference is the schema name (the actual schema).

I want to be able to run something liquibase:update schemaName=my-schema which would update the given schema.

My changelogs.xml look like this:

<createTable tableName="myTable" schemaName="${schemaName}">

where schemaName is parametrized, and obtained as a dynamic property. However, the problem is with this that the databasechangelog and databasechangeloglock tables only exist in the default schema, the one used for openning a connection to the database. I have this configured in liquibase.properties.

liquibase.properties

url: jdbc:postgresql://localhost:5431/my-db?currentSchema=public

And now schema given as a parameter and schema defined in properties don't match, ie. schema given as a parameter doesn't have it's own databasechangelog and databasechangeloglock, instead validates itself against these tables in public schema.

Error

Error setting up or running Liquibase: Validation Failed:
[ERROR]      1 change sets check sum
[ERROR]           001-add-table-mytable.xml::001::wesleyy was: 7:fb1f721005e26807efc07bde45f459b9 but is now: 7:0722a27fccf7137a326a1e50685a22fc

Looks like the schemaName parameter changed the checkSum.

Is there a way to:

  1. Somehow exclude schemaName from the checksum? OR
  2. Dynamically generate databasechangelog and databasechangeloglock on each given schemaName?

Upvotes: 0

Views: 3897

Answers (1)

Amit
Amit

Reputation: 163

When running liquibase, use optional parameter "--liquibaseSchemaName=[schemaName]"

Liquibase will to create/use changelog tables in [schemaName] instead of the default user you are connected to.

As each schema/tenant will have it's own copy of changelog there will not be any checksum issues caused by a change in the schema name.

Upvotes: 2

Related Questions