Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Liquibase: how to run programmatically only those changesets which haven't been applied yet?

Tags:

java

liquibase

I try to update existing DB with luquibase Java API in this way:

Database database = DatabaseFactory.getInstance()
    .findCorrectDatabaseImplementation( 
        new JdbcConnection( connection ) 
    );
Liquibase liquibase = new Liquibase( 
    "db.changelog.xml", 
    new FileSystemResourceAccessor(), 
    database 
);
liquibase.update( "" );

But it tries to apply all change sets including those which have been already applied earlier. What do I do wrong?

like image 908
Borodin.Mik Avatar asked Oct 31 '22 16:10

Borodin.Mik


1 Answers

The code looks correct, my guess is that you have a different classpath than when you ran it before. Liquibase identifies each changeset with an id+author+filepath combination, so if you are currently referencing db.changelog.xml as "db.changelog.xml" but previously used "output/db.changelog.xml" or "com/example/db.changelog.xml" it will see it as different.

If you "select * from databasechangelog" you will see what is stored as the path for each changeSet.

like image 111
Nathan Voxland Avatar answered Nov 15 '22 04:11

Nathan Voxland