Liquibase:如何仅以编程方式运行那些尚未应用的变更集?

Bor*_*Mik 5 java liquibase

我尝试以这种方式使用 luquibase Java API 更新现有数据库:

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

但它会尝试应用所有更改集,包括之前已经应用的更改集。我做错了什么?

Nat*_*and 2

代码看起来是正确的,我的猜测是您的类路径与之前运行它时的类路径不同。Liquibase 使用 id+author+filepath 组合来标识每个变更集,因此,如果您当前将 db.changelog.xml 引用为“db.changelog.xml”,但之前使用“output/db.changelog.xml”或“c​​om/example/ db.changelog.xml”它将认为它有所不同。

如果您“从数据库变更日志中选择*”,您将看到存储为每个变更集的路径的内容。