liquibase 无法在数据库中执行变更集

问题描述 投票:0回答:2

我无法弄清楚为什么没有任何变更集被执行并反映在数据库中。

我也提到了这个链接,不幸的是,它有同样的问题,没有答案post

总而言之,没有执行任何变更集,并且我的数据库中没有表(DATABASCHANGELOG 除外)。

请参考以下代码。

类“DataVersioningController.java”有 main 方法,它调用“liquiebaseRun()”方法。

public static void main(String args[]) throws LiquibaseException, SQLException {
       new DataVersioningController().liquiebaseRun();

    }

    public void  liquiebaseRun() throws SQLException, LiquibaseException {

       JdbcConnection jdbcConnection = new JdbcConnection(DataVersioningController.getConnection());
       DatabaseChangeLog dbChangeLog = new DatabaseChangeLog("D:\\ChangeSet.xml");
       Database database = DatabaseFactory.getInstance().findCorrectDatabaseImplementation(jdbcConnection);

       ClassLoaderResourceAccessor classLoaderAccessor = new ClassLoaderResourceAccessor();

       CommandLineResourceAccessor clAccessor = new CommandLineResourceAccessor(getClass().getClassLoader());

        CompositeResourceAccessor ref = new CompositeResourceAccessor(new ResourceAccessor[] { clAccessor, classLoaderAccessor });
       database.setDefaultSchemaName("test");
       database.setLiquibaseSchemaName("test");
       Liquibase liquibase = new Liquibase(dbChangeLog, ref, database);
       liquibase.update(new Contexts("test"), new LabelExpression());

       System.out.println("Completed ");
  }

ChangeSet.xml

<?xml version="1.0" encoding="UTF-8"?>
<databaseChangeLog
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
        xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
        xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.1.xsd
    http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd">

    <changeSet author="admin" id="1" context="test">
        <createTable tableName="person">
            <column autoIncrement="true" name="id" type="INT">
                <constraints primaryKey="true"/>
            </column>
            <column name="name" type="VARCHAR(255)">
                <constraints nullable="false"/>
            </column>
            <column name="address" type="VARCHAR(255)"/>
        </createTable>

    </changeSet>
</databaseChangeLog>
java liquibase changeset database-versioning
2个回答
0
投票

您不需要手动调用liquibase。 如果您使用 SpringBoot 和 Maven,则添加该依赖项:

<!-- https://mvnrepository.com/artifact/org.liquibase/liquibase-core -->
        <dependency>
            <groupId>org.liquibase</groupId>
            <artifactId>liquibase-core</artifactId>
            <version>3.6.2</version>
        </dependency>

并将该属性添加到您的应用程序中。属性:

spring.liquibase.change-log=//path to your changeset

0
投票

我遇到了类似的问题,当我将

SpringLiquibase
schema per tenant
一起使用时,未应用变更集。

我需要设置

liquibase.setLabelFilter(schemaName)
来解决更改日志缓存问题。

© www.soinside.com 2019 - 2024. All rights reserved.