Tagging in SQL format changeset

I am trying to create tag of database whenever any data is updated on database with liquibase command.

Does liquibase support tagging in SQL format changeset?

Please find the content of the .sql changeset:

–liquibase formatted sql

–changeset anant:1585068371411-1

CREATE TABLE service_request1 (id BIGINT AUTO_INCREMENT NOT NULL, request_id VARCHAR(45) NOT NULL, input_json MEDIUMTEXT NULL, output_json MEDIUMTEXT NULL, created_date timestamp DEFAULT NOW() NULL, modified_date timestamp DEFAULT NOW() NULL, cal_version_no VARCHAR(45) NULL, CONSTRAINT PK_SERVICE_REQUEST PRIMARY KEY (id));

–rollback drop table service_request1

Note:I am doing this to integrate with Bamboo for CI/CD.

Hi Steve,

I am using liquibase cli with steps you mentioned that I need to perform in bamboo.

Do I need to perform liquibase with tagging option in cli?

Please refer the screenshot of bamboo attached.Let me know if I am doing wrong.

Thanks and Regards,

Anantdev Pathak

Hi Steve,

All the file are checked out from bitbucket repository.

Bamboo Changelog task:

Generating changelog from existing DB

cd ${bamboo.changeLogFile}

rm dbchangelog.mysql.sql

cd ${bamboo.liquibasepath}

.\liquibase.bat --driver=${bamboo.driver} --classpath=${bamboo.classpath} --changeLogFile=’${bamboo.changeLogFile}/dbchangelog.mysql.sql’ --url=${bamboo.url} --username=${bamboo.username} --password=’${bamboo.password}’ generateChangeLog

Bamboo update command:

cd ${bamboo.liquibasepath}

.\liquibase.bat --driver=${bamboo.driver} --classpath=${bamboo.classpath} --changeLogFile=’${bamboo.changeLogFile}/db-changelog-calculatorservice-master.xml’ --url=${bamboo.url} --username=${bamboo.username} --password=’${bamboo.password}’ clearChecksums

.\liquibase.bat --driver=${bamboo.driver} --classpath=${bamboo.classpath} --changeLogFile=’${bamboo.changeLogFile}/db-changelog-calculatorservice-master.xml’ --url=${bamboo.url} --username=${bamboo.username} --password=’${bamboo.password}’ update

I have defined all these variables in bamboo.

db-changelog-calculatorservice-master.xml

<?xml version="1.1" encoding="UTF-8" standalone="no"?>

<databaseChangeLog xmlns=“http://www.liquibase.org/xml/ns/dbchangelog” xmlns:ext=“http://www.liquibase.org/xml/ns/dbchangelog-ext” xmlns:pro=“http://www.liquibase.org/xml/ns/pro” xmlns:xsi=“http://www.w3.org/2001/XMLSchema-instance” xsi:schemaLocation=“http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd http://www.liquibase.org/xml/ns/pro http://www.liquibase.org/xml/ns/pro/liquibase-pro-3.8.xsd http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.8.xsd”>

I have created the different versions of the sql file and included in master db changelogand running the update command.

Do you mean I need to add the tag command after this step and also do I need to specify related to in masterdb changelog file?

Thanks and Regards,

Anantdev Pathak

When using formatted SQL changelogs, each change is basically a change, so you can’t use any of the other change types, including the change type. This is one of the downsides of using that changelog format. 

In your Bamboo build step, how are you running liquibase? If you are using the command line interface, you could have the build step first run liquibase update, the second would then run liquibase tag

You could do something similar if you were using the liquibase-maven-plugin for your builds. 

Steve Donie
Principal Software Engineer
Liquibase Community Engagement
Datical, Inc. http://www.datical.com/

Hard to tell what you are doing because most of the script is cut off in the screenshot. I can see that you are removing a changelog and then running liquibase, but I can’t tell what liquibase command you are running. Why are you removing dbchangelog.mysql.sql? Where does that file come from? What liquibase command are you running after that?

If that is the update command, then if you want to tag the database afterwards, you would run liquibase again with most of the same options, but then instead of the update command you would use the tag command, specifying a tag to apply. 

Also, in general, text is better than screenshots when talking about code.

Steve Donie Principal Software Engineer Liquibase Community Engagement Datical, Inc. http://www.datical.com/

Lots of things to discuss here.

It is not clear to me why you are running the generateChangelog command repeatedly. Typically this is only done once, when you first start using Liquibase, to generate an initial changelog. 

You should not need to repeatedly use the liquibase clearchecksums command either.

Then on your final bit - if you want to apply a tag to the database, then there are two ways to do it. You can add a element to your master changelog, OR after you run the liquibase update command, you can run the liquibase tag command. Doing it with the element in the changelog ensures that the tag is applied in the same way on every database that you run update on. Doing it with the tag command is a more ‘ad-hoc’ way of doing it, and requires that you run the command on every database you want to have the tag on. 

Steve Donie
Principal Software Engineer
Liquibase Community Engagement
Datical, Inc. http://www.datical.com/