irobot8
irobot8

Reputation: 21

tagDatabase in Formatted SQL changeset

I'm trying to tag a Formatted SQL changeset so a matching ID and tag are written to the DATABASECHANGELOG table (for rollback purposes - see changeset fragment below). The Phing liquibase task is being used to apply the 'update' command for a single changelog.

Although the 'tagDatabase' attribute isn't listed for Formatted SQL changelogs (http://www.liquibase.org/documentation/sql_format.html), neither is logicalFilePath, and that seems to be working OK!

Can someone let me know definitively if tagDatabase is not supported for a Formatted SQL changeset?

Many thanks in advance,

IR8

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

--changeset id:123 logicalFilePath:path-independent ALTER TABLE test1 ADD COLUMN text_column text NULL;

--rollback ALTER TABLE test1 DROP COLUMN text_column;

--changeset id:tag123 tagDatabase:123;

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Unexpected error running Liquibase: No SQL for changeset ../db/changelog/databaseChangeLog.sql::tag123::id

Execution of target "migrate" failed for the following reason: C:\data\htdocs\TestLiquibase\deploy\build.xml:49:1: Liquibase exited with code -1

Upvotes: 2

Views: 3359

Answers (2)

Sivaram Rasathurai
Sivaram Rasathurai

Reputation: 6333

So this is not implemented yet. From the official document,

When you run the updateToTag command or the Maven update goal with the liquibase.toTag attribute, and there is a row in the DATABASECHANGELOG table corresponding to the tagDatabase changeset in the changelog, the updateToTag command or the update Maven goal deploys all changesets starting with the first changeset at the top of the changelog file and moving down to the changeset up to the tag specified by the tagDatabase Change Type.

We can do one thing that is, after you executing all the SQL format changesets, we can create a new database tag changeset and update with liquibase

<?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.3.xsd">
    <changeSet author="sivaramr" id="7">
        <tagDatabase tag="v_1.0.0"/>
    </changeSet>
</databaseChangeLog>

If you are using any liquibase command tool or liquibase plugins, then you can perform tag command to add the tag to the last changelog as follow

Here It is illustrated with gradle plugin.

./gradlew tag -PliquibaseCommandValue=v1.0.0

Before executing the above tag command, you can check the tag is already exist or not by tagexists command

./gradlew tagExists -PliquibaseCommandValue=v1.0.0

Upvotes: 0

Jens
Jens

Reputation: 6383

I think it's not included.

The java class FormattedSqlChangeLogParser takes care of parsing the formatted sql file and has a couple of Patterns defined for this. There is a logicalFilePathPattern but nothing for tagDatabase.

Upvotes: 1

Related Questions