java liquibase无法在DB中执行更改

jmp7cifd  于 5个月前  发布在  Java
关注(0)|答案(2)|浏览(50)

我不明白为什么没有一个更改集被执行并反映在DB中。
我也提到了这个link,它也有同样的问题,不幸的是,这个post没有答案。
总之,没有执行任何变更集,我的数据库中没有表(除了数据库)。


的数据
请参考下面的代码。
类“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>

sgtfey8w

sgtfey8w1#

您不需要手动调用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>

字符串
并将该属性发送到您的application.properties:

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

0s0u357o

0s0u357o2#

我遇到了一个类似的问题,当我使用SpringLiquibaseschema per tenant时,没有应用更改。
我需要设置liquibase.setLabelFilter(schemaName)来解决更改日志缓存问题。

相关问题