Run LB at server startup: table already exists

Hello,

pls correct me if i’m wrong here, but this is what i understand LB does when used as servlet listener:

On server start (or republish) it checks if the changes in the changelog.xml equal the DATABASECHANGELOG table.

If both are the same, everything is fine. If the xml has some new changes, they are applied to the db.


So my problem is the following: i have a fresh db with some new tables.

I generate a changelog -> both LB tables are not created here, so i clear the db and run the LB update using the newly created changelog.xml. Now i have the LB tables. I then put the changelog.xml inside my web project and edit the web.xml as in the documentation. Starting the server it states that the first changelog item cannot be applied because the table already exists. But i expect it to stay quiet, since the changes in the changelog.xml and the db should be alike.


Thank you very much

Liquibase doesn’t attempt to figure out if a changeSet has been ran by looking at what it does vs. what is in the database. It just checks to see if the databasechangelog table says it has already ran.


So, if you do a generateChangeLog for an existing database, you need to have some way to tell liquibase what should be run and what shouldn’t. There are a few tools, but what works best depends a lot on you. The changelogsync/changelogsyncSQL command will execute/generate the commands to mark all the changesets in the changelog file as ran. If you run that against an existing database liquibase will now think they have been ran and just run any new changeSets. 


Alternatively, you can use contexts or preconditions to check at runtime if a changeSet should run or not.


Nathan