1

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 :)

  • Does this answer your question? [How to set up liquibase in Spring for multiple data sources?](https://stackoverflow.com/questions/43523971/how-to-set-up-liquibase-in-spring-for-multiple-data-sources) – blurfus Nov 30 '20 at 16:48
  • No, i don't think so :( – Bulat Gimazov Nov 30 '20 at 17:49

1 Answers1

0

what about having this structure?

master.changelog.yaml
  schemas
    schema1.changelog.yaml
    schema2.changelog.yaml
  templates
    templates.changelog.yaml
    table1.template.yaml
    table2.template.yaml
    ...

so in master.changelog.yaml you will include schema1.changelog.yaml and schema2.changelog.yaml. In both of them you will include templates.changelog.yaml and set the parameters for schema. Then in templates.changelog.yaml you will include all templates that are common for all schemas. I think that should work however I have no experiences with yaml format in liquibase. For xml that shouldn't be issue.

bilak
  • 4,526
  • 3
  • 35
  • 75