Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Liquibase multiple changelog execution

Tags:

I'm using SpringLiquibase for liquibase configuration, below configuration works fine with single changelog file (sql formatted)

@Configuration
@Slf4j
public class LiquibaseConfiguration {

  @Inject
  private DataSource dataSource;

  @Bean
  public SpringLiquibase liquibase() {
    log.info("################## Entering into liquibase #################");
    SpringLiquibase liquibase = new SpringLiquibase();
    liquibase.setDataSource(dataSource);
    liquibase.setChangeLog("classpath:schema/update-schema-01.sql");
    // Configure rest of liquibase here...
    // ...
    return liquibase;
  }
}

In my application, i may need to run more than one changelog files and i couldn't make such execution,
I tried to feed multiple changelogs as follows,

liquibase.setChangeLog("classpath:schema/update-schema-01.sql");

liquibase.setChangeLog("classpath:schema/update-schema-02.sql");

the last one changelog file alone getting executed.

liquibase.setChangeLog("classpath:schema/*.sql");

Getting error as liquibase.exception.ChangeLogParseException: java.io.IOException: Found 2 files that match classpath:schema/*.sql

Please suggest a way to includeAll changelogs here.

like image 768
Nat4j Avatar asked May 24 '19 12:05

Nat4j


People also ask

What is the purpose of adding changesets to your changelog?

Liquibase Concepts A change is contained in a changeset and changesets are added to the changelog in the order they need to be deployed. Simply put – a changelog contains an ordered list of changesets, and a changeset contains a change.

What is Liquibase Databasechangelog?

Liquibase uses a changelog to sequentially list all changes made to your database. Think of it as a ledger. It is a file that contains a record of all your database changes (changesets). Liquibase uses this changelog record to audit your database and execute any changes that are not yet applied to your database.

What is logicalFilePath Liquibase?

The logicalFilePath attribute is used to override the file name and path when creating the unique identifier of changesets.


1 Answers

One of the possible solution: you can create the main changelog, which will includes other changelogs as much as you wish. And in the SpringLiquibase object you will set only one main liquibase changelog.

For example, assume you have 2 changelog files: one-changelog.xml and two-changelog.xml and you need to run the both. I suggest you to create one more file main-changelog.xml and include in it one-changelog.xml and two-changelog.xml files like this:

<?xml version="1.0" encoding="UTF-8"?>

<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog/1.9"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog/1.9
        http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-1.9.xsd">

    <include file="one.xml"/>
    <include file="two.xml"/>
</databaseChangeLog>

And set main-changelog.xml file as changelog for SpringLiquibase.

As result, you will have 2 separate changelog files.

like image 58
Golov Pavel Avatar answered Oct 19 '22 06:10

Golov Pavel