Alkis Kalogeris
Alkis Kalogeris

Reputation: 17765

Liquibase maven update fails on second attempt

I'm trying to create a table (if not exists) to a remote database (postgres in docker container). The sql command is located in a sql file. When I execute

mvn liquibase:update

by hand (bash terminal) everything works great. The build is a success and the message for the creation of the table is displayed. Now if I delete the table and execute the same command, then although I'm seeing a success message for the completion of the task, the table is not created (of course the message about the creation of the table is not displayed either).

As I've mentioned the database is in a docker container. So it is a remote database. I've already included the below command in my pom.xml

<promptOnNonLocalDatabase>false</promptOnNonLocalDatabase>

Why is this happening?

Upvotes: 0

Views: 554

Answers (2)

dbf
dbf

Reputation: 6499

Is this changeset run with "runAllways" mode? If not, than when you are running it first time change is applied and recorded as applied and it is not executed second time at all (and there is no difference how you are running it).

Upvotes: 3

SteveDonie
SteveDonie

Reputation: 9016

Liquibase keeps track of the changes it has applied in a separate table called DATABASECHANGELOG. If you manually delete the table (let's call this one "MyTable") as described above, and then re-run Liquibase, it just checks the DATABASECHANGELOG table to see if the change mentioned has been run, and if it has, it will not re-run it. If you want to see the table get re-created you would have to manually remove the row from DATABASECHANGELOG, or else (as the comment above suggests) mark the changeset in the changelog as "runAlways". Typically you do NOT want runAlways to be set because then Liquibase will try to do things like create a table that already exists.

Upvotes: 1

Related Questions