[英]liquibase is not able execute changeset in DB
我無法弄清楚為什么非變更集正在執行並反映在DB中。
我也提到了這個鏈接 ,它有同樣的問題,遺憾的是這篇文章沒有答案。
總之,沒有執行任何更改集,並且我的數據庫中沒有表(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>
你不需要手動調用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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.