2

To fix vulnerabilities I upgraded docker image version in my dockerfile:

old:

FROM liquibase/liquibase:4.4

new:

FROM liquibase/liquibase:4.20

But I started to get error:

addAfterColumn is not allowed on postgresql

I started to investigate this error and found out that in some changesets addAfterColumn is used.

<changeSet author="***" id="***">
    <addColumn tableName="my_table" >
      <column afterColumn="existing_column"
        name="new_column"
        type="varchar(255)" >
        <constraints nullable="true"/>
      </column>
    </addColumn>
  </changeSet>
</databaseChangeLog>

I also found this topic:

https://github.com/liquibase/liquibase/issues/3091

So I just removed afterColumn but I am not sure what side effects could I experience ? I am not familiar about reason to use afterColumn but if it is removed it could be useless but I can't find any useful information.

Are there any other options to fix the issue ? because editing liquibase scripts will break checksums for existing databases

gstackoverflow
  • 36,709
  • 117
  • 359
  • 710
  • Columns are always added "at the end" in Postgres. So if Liquibase accepted that attribute in a previous version it must have ignored it. –  Mar 29 '23 at 09:48
  • @a_horse_with_no_name but why ? people say that it makes sense https://stackoverflow.com/questions/1243547/how-to-add-a-new-column-in-a-table-after-the-2nd-or-3rd-column-in-the-table-usin/14775092#14775092 – gstackoverflow Mar 29 '23 at 10:11
  • Why? Because no one has implemented such a feature. –  Mar 29 '23 at 10:13
  • @a_horse_with_no_name so it was a bug in previous version of liquibase ? – gstackoverflow Mar 29 '23 at 10:13

3 Answers3

1

As this pull request shows, previously liquibase did not warn that column ordering might not be applied, because the database does not support it. So it failed silently in older versions, but now it shows an error. Quoting the most important line:

Breaking change: Because I fixed the validation logic, anyone who has a beforeColumn or afterColumn or position attribute on addColumn for a database that doesn't support that will now get a validation error vs. it just being ignored.

meskobalazs
  • 15,741
  • 2
  • 40
  • 63
0

You can try to do suggestion with modifySql from here: https://github.com/liquibase/liquibase/issues/3094#issuecomment-1195961510

<changeSet id="***" author="***">
    <addColumn tableName="my_table">
        <column name="new_column" type="varchar(255)"/>
    </addColumn>
    <modifySql dbms="postgresql">
        <append value=" position 4"/>
    </modifySql>
</changeSet>

It looks like in liquibase 4.13 https://github.com/liquibase/liquibase/pull/2943 they fixed something that doesn't need to be fixed as in https://github.com/liquibase/liquibase/issues/3091 they are trying to enhance/fix their own fix. In addition to breaking backward compatibility (as @gstackoverflow wrote in the comment), it breaks the logic when the product has support for many types of databases (no error for mySQL and error for Oracle/MsSQL/PostgreSQL).

Grygorii
  • 162
  • 2
  • 6
0

remove "afterColumn" so it works in fresh ENV. to avoid Validation failure in an ENV where the change set is already executed, adding the original checksum works:

  <changeSet>
    <validCheckSum>9:6a4c63a04890c57dd610abc39389b4ce</validCheckSum>
        or
    <validCheckSum>ANY</validCheckSum>
Wenke
  • 1
  • 1