Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
366 views
in Technique[技术] by (71.8m points)

java - 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
question from:https://stackoverflow.com/questions/65887115/delete-table-in-database-using-liquibase-does-not-work

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...