how do i create same tables in different schemas using liquibase

Imagine i had a table ‘some-table’ that i want to create in multiple schemas. File called ‘create-some-table.yaml’

 databaseChangeLog:
      - changeSet:
          id: create-some-table
          runOnChange: true
          author: gimazov (generated)
          preConditions:
            - onFail: MARK_RAN
              not:
                tableExists:
                  tableName: some-table
          changes:
            - createTable:
                columns:
                  - column:
                      autoIncrement: true
                      constraints:
                        nullable: false
                        primaryKey: true
                        primaryKeyName: some-table_pkey
                      name: id
                      type: BIGINT
                tableName: some-table
                schemaName: ${schema}

Then there’s a yaml file ‘schema1.yaml’ that includes the previous file and sets schema

 databaseChangeLog:
  - property:
      name: schema
      value: schema1
  - include:
      file: classpath:/db/changelog/create-some-table.yaml

Then the same file as the above one just named ‘schema2.yaml’ with corresponding schema name

The last thing is changelog-master which is pretty simple

databaseChangeLog:
    - include:
        file: classpath:/db/changelog/schema1.yaml
    - include:
        file: classpath:/db/changelog/schema2.yaml

Is there any way i can do something similar to this, thanks :slight_smile:

We found it easiest to use Bash and iterate over multiple databases using a simple loop.

We have lots of databases that all need the same schemas applied so it was quite simple to implement.