Broadleaf Microservices
  • v1.0.0-latest-prod

Show Index Creation SQL skipped during Liquibase migration

Indexes are specifically NOT applied during a liquibase upgrade, unless the target table is empty. This is to protect the database and application from locking behavior during index creation that could cause an outage. To review index creation SQL separately for each service targeted for upgrade, you can perform several steps:

  1. Emit a sql file by referencing your target version liquibase changelog file and reference database using Liquibase utilities.

  2. Repeat step 1 for each microservice you plan to upgrade.

The end result be a migrate.sql file that represents the delta between the reference and the target version. Moreover, it should only contain the relevant index creation statements. This SQL will then be useful to apply manually against your environment(s) during a window that best fits your needs.

More Detail

Create Index SQL

Once you have identified a copy of a lower environment database (or local DB) where Liquibase is used, you may proceed with generating the index sql for the upgrade.

  • Identify the pom.xml for the FlexPackage (e.g. Min, Browse, Cart, Processing, Supporting), or granular service for which an upgrade is desired.

  • Add support for the liquibase maven plugin to the pom.xml file - similar to Liquibase Maven Example.

  • Upgrade your project pom.xml to reference the release train BOM for your target version (or upgrade your pom with more granular overrides) to cause your codebase to adopt the newer release of Broadleaf.

  • In the same directory as the pom.xml file, add a file called liquibase.properties.

  • In the liquibase.properties file, add values to inform liquibase of how to connect to your reference database. Refer to Liquibase Properties Example.

  • In a terminal in the same directory as the pom.xml file, execute mvn liquibase:updateSQL. This should result in a file called migrate.sql being created in the ./target directory of your maven project. Review this file. It should only contain index creation statements (see #7 in Liquibase Properties Example). You will most likely want to edit these statements to make then non-blocking before using. See Mitigate Index Creation Blocking. Note, this file may contain SQL updates to databasechangeloglock and databasechangelog (internal Liquibase maintenance tables) that are not interesting for the purpose of understanding the index creation SQL. If so, you can safely ignore these additional statements.

Liquibase Maven Example

<build>
    <pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.liquibase</groupId>
                <artifactId>liquibase-maven-plugin</artifactId>
                <version>4.9.1</version>
                <configuration>
                    <propertyFile>liquibase.properties</propertyFile>
                </configuration>
            </plugin>
        </plugins>
    </pluginManagement>
</build>

Liquibase Properties Example

changelogFile: classpath:/db/changelog/adminnavigation.postgresql.changelog-master.xml (1)
url: jdbc:postgresql://localhost:5432/broadleaf (2)
username: broadleaf (3)
password: demo (4)
defaultSchemaName: adminnavigation (5)
liquibaseSchemaName: adminnavigation (6)
labels: index (7)
  1. Path pointing to the Broadleaf liquibase changelog for the target service. Note, if you have your own changelog that internally references the Broadleaf changelog, then you may use that here instead.

  2. JDBC URL pointing to the temporary database

  3. Username for the JDBC connection

  4. Password for the JDBC connection

  5. The name of the schema in which the baseline Broadleaf database objects should be created. You may wish to create this schema if it does not already exist in the temporary database (if applicable).

  6. The name of the schema in which liquibase specific maintenance database objects should be created. This can be the same as the default schema declared above.

  7. Filter on the index label to only include index creation related changesets.

See https://docs.liquibase.com/concepts/connections/creating-config-properties.html for more information on the contents and properties available to liquibase.properties.

Mitigate Index Creation Blocking