1
votes

As per the liquibase documentation:

Each changeSet tag is uniquely identified by the combination of the “id” tag, the “author” tag, and the changelog file classpath name.

This seems to be a very poor design choice. The identity of a changeset shouldn't be linked to its location. If the changelog is run via automatic application deployment the changeset would come from a classpath location within a JAR file. If I want to run the same changesets from commandline manually, the location might be the current directory.

In this case instead of recognizing the changeset as same based on its ID liquibase will try to apply it twice. Is there a way to change this behavior and have it identify changesets only basis specified ID?

3

3 Answers

3
votes

I would suggest using the logicalFilePath attribute of databaseChangeLog tag.

This gives you more freedom to change the directory structure of your project. Also it prevents the file name from being stored as an absolute path (which might happen in some circumstances).

1
votes

@binoternary's answer works. But the problem is that logicalFilePath is only available in XML changesets whereas I was using SQL changesets. The work around is to create a XML changeset and then include SQL into it like this:

<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-3.4.xsd">

    <changeSet id="new-tables" author="kshitiz" logicalFilePath="new_tables.sql">
        <sqlFile path="new_tables.sql" relativeToChangelogFile="true" />
    </changeSet>
</databaseChangeLog>
0
votes

Only if you manipulate the sourcecode and recompile your own version of liquibase.

Actually the design is fine, you just use it wrongly. If you e. g. have a big team where each team maintains their changesets in a separate liquibase file, it would be fatal to not take the filename into account, as different teams could use the same ID.

Just make sure you are calling Liquibase always the same way and the identities of the changesets will not change.