5
votes

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.

1

1 Answers

3
votes

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.