1

I have used liquibase 3.8.9 version on my spring boot application for database versioning and now I need to generate an sql for the production environment (we cannot run liquibase from the app).

I have some issues for which I haven't found any recent answers:

  1. Can I generate sql without databasechangelog and databasechangeloglock table? I don't see any value in having the on the production environment.

If I cannot generate without them, I saw that liquibase doesn't generate for me the creation of the databasechangelog and databasechangeloglock, can I configure liquibase to generate them without defining new changesets?

  1. In some change sets I have files that are in the root of the project, something like this:

<include file="./liquibase/some-file.xml" relativeToChangelogFile="false"/>

When I run the app, the change sets are ran well, but when I try to run updateSQL I receive:

./liquibase/some-file.xml does not exist

I've included the file from the root folder because it is dependent on the environment. Is there a way to include the file to use it for the plugin as well?

  1. Is it a way to generate versioned sql? For example the first version should be version 1.0, and if I add a new column it should generate version 1.1 with only the new added column without the sql from version 1.0

Best regards

Dorin
  • 2,167
  • 4
  • 20
  • 32

1 Answers1

0
  1. Can I generate SQL without databasechangelog and databasechangeloglock table? I don't see any value in having the on the production environment?

WHY? The features of the liquibase are lying on these two tables. Liquibase uses the DATABASECHANGELOG table to track which changesets have been run.

The table tracks each changeset as a row, identified by a combination of the “id”, “author”, and “filename” columns. Liquibase uses the DATABASECHANGELOGLOCK table to ensure only one instance of Liquibase is running at one time. Basically, these two tables are used to help you do not run the same changeset again without your knowledge and provide a mechanism to stop the concurrent access.

2.In some change sets I have files that are in the root of the project, something like this: When I run the app, the change sets are ran well, but when I try to run updateSQL I receive: ./liquibase/some-file.xml does not exist?

How did you configure the liquibase. In my case, I have configured the liquibase with spring boot & also added the liquibase gradle plugin. Because of this relative path issue, what I have done is, changed the logicalFilePath of changelog as follow, and also used the relative path file.

<?xml version="1.0" encoding="UTF-8"?>
<databaseChangeLog
        xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
                      http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.4.xsd"
        logicalFilePath="schema/15-01-changelog-comment-order-header-table.xml">
    <changeSet id="10" author="sivaramr" dbms="postgresql" context="dev,qa,prod">
<changeset> ... </changeset>
</changelog>

When you configure the master changelog file don't configure the path as well instead of using the default path.

spring.liquibase.change-log=classpath:db/changelog/changelog-master.xml
  1. You can use tag to do that,

Version Control with liquibase

Tag command

The tag command is typically used to mark the current database state, version, release, or any other information by adding the tag to the last row in the DATABASECHANGELOG table

We can add a tag with changeset as follow for the database.

Before creating the tag we have to check that, the tag is ready there or not by following the liquibase command

./gradlew tagExists -PliquibaseCommandValue=v1.0.0

We can use the following command to add the tag to the last changeset of the database

./gradlew tag -PliquibaseCommandValue=v1.0.0

Rollback Tag Command

The rollback command is typically used to revert all changes that were made to the database after the tag you specify.

When you run rollback , Liquibase will roll back sequentially all the deployed changes until it reaches the tag row in the DATABASECHANGELOG table.

It is a best practice to run the rollbackSQL command that allows you to inspect for potential mistakes before running the command.

./gradlew rollback -PliquibaseCommandValue=v1.0.0
Sivaram Rasathurai
  • 5,533
  • 3
  • 22
  • 45