javaspring-bootliquibase-hibernate

Delete table in database using liquibase does not work


I am developing a spring boot app with hibernate an liquibase on a postsgre db. When i start the spring boot app, the changelog is updated in the db and the log says, that the script run successfully, but the table is still in the schema.

This is my db.changelog.xml:

<changeSet author="stimpson" id="deletetablehans">
    <sqlFile dbms="postgre" encoding="UTF-8" endDelimiter=";"
        path="sql/00003_deleteTableHans.sql" relativeToChangelogFile="true"
        splitStatements="true" stripComments="true" />
</changeSet>

This is my script (deletetablehans.sql in the sql folder):

--liquibase formatted sql
--changeset stimpson:deleteTableHans
DROP TABLE HANS;
commit;
;

This is part of my logfile:

2021-01-25 15:43:50,438 INFO  liquibase.lockservice : Changelog-Protokoll erfolgreich gesperrt.
2021-01-25 15:43:50,686 INFO  liquibase.changelog : Reading from public.databasechangelog
2021-01-25 15:43:50,704 INFO  liquibase.changelog : ChangeSet db/dbchangelog.xml::deletetablehans::stimpson ran successfully in 0ms
2021-01-25 15:43:50,709 INFO  liquibase.lockservice : Successfully released change log lock

I do not care why the language changes, but when i look at the database, I see that the table named Hans is still there. But why? I did try with an explicit commit and the delimiter in its own line, but i do not understand the outcome? This is my liquibase.properties file:

changeLogFile=src/main/resources/db/dbchangelog.xml
url=jdbc:postgresql://localhost:5432/padsyhw3
username=dbuser
password=dbpass
driver=org.postgresql.Driver

This is the only data row in the databasechangelog table in DB:

 deletetablehans    stimpson    db/dbchangelog.xml  2021-01-25 15:49:05 1 EXECUTED  8:90e2fa99c6beeace580e429bd2bf9ae3  sqlFile         4.2.2

Solution

  • I have a working solution to your problem

    1. I wonder if the case difference between deletetablehans and deleteTableHans could have an impact on the execution of the changeset

    2. According to the liquibase supported databases, when using dbms for postgre you should use the value postgresql while you used postgre

    3. Do you have any specific reason to use a changeset inside of an SQL file to do the drop action ? I can see at least two alternatives if no one can bring you a valid solution

    Alternative 1: Use sql instead of sqlFile

    <changeSet author="stimpson" id="deletetablehans">
        <sql dbms="postgresql">
            DROP TABLE HANS;
        </sql>
    </changeSet>
    

    Alternative 2: Use liquibase dropTable

    <changeSet author="stimpson" id="deletetablehans">
        <dropTable tableName="HANS" />
    </changeSet>