Gus
Gus

Reputation: 6871

UpdateSQL apparently ignoring contents of databasechangelog table

I have been developing the initial version of an application, and database changes were frequent, and there was no production data to protect, so I had installed LiquibaseServletListener and it's been nicely updationg/recreating the DB when needed on application install. Now however we're in production and I need to remove that from the web.xml so I can be sure to carefully test scripts, and can track emergency updates, without needing to redeploy the whole application, etc.

My build is in gradle, and I've been using the liquibase-gradle plugin, but I'm now perplexed by the fact that updateSQL seems to want to write out the entire script to create the database from scratch.

The SQL that is output does not include creation of the liquibase tables, and the task fails if I shut down the database, so it seems that it is indeed reading the DB and aware of the table, but I can't seem to get an sql output with only the most recent change.

I would expect it to either complain about differences, or recognize the 254 existing changes...

Is there some way in which the changes made by ServletListener are not equivalent to the gradle task?

Upvotes: 0

Views: 1267

Answers (1)

user330315
user330315

Reputation:

Not sure if that applies here: Liquibase checks if a changeSet was already executed by checking the columns id, author and filename.

Unless you use the attribute logicalFilePath in the databaseChangeLog tag, the actual filename that Liquibase uses, depends on the current working directory of the process running Liquibase.

It might be that your filenames are stored as e.g. v1.0/filename.xml when executed through Gradle. But when you run it from the ServletListener the actual filename that Liquibase "sees" might be e.g. changelog/v1.0/filename.xml

You could verify my theory by looking at the generated INSERT statements for the databasechangelog that are part of the updateSQL output if I'm not mistaken.

We have taken the habit to always specify a logicalFilePath to make sure Liquibase always uses the same filename regardless of the way it's started:

E.g. for a file named changelog_1.0.xml you would need to use:

<databaseChangeLog logicalFilePath="changelog_1.0.xml" ..... >
   .............
</databaseChangeLog>

Upvotes: 4

Related Questions