2014-06-11 20 views
3

我正在使用Spring-Liquibase執行臨時數據庫上所需的任何遷移。Liquibase嘗試應用所有更改集,即使數據庫存在

applicationContext.xml看起來像

<beans xmlns="http://www.springframework.org/schema/beans" 
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" 
     xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"> 
    <context:component-scan base-package="com.yahoo.comma"/> 
    <bean id="liquibase" class="liquibase.integration.spring.SpringLiquibase"> 
     <property name="dataSource" ref="dataSource"/> 
     <property name="changeLog" value="classpath:liquibase/changelog.xml"/> 
     <property name="defaultSchema" value="pryme_dev"/> 
    </bean> 
</beans> 

當我部署WAR文件,我看到在日誌中的錯誤作爲

INFO 6/11/14 9:32 AM:liquibase: Successfully acquired change log lock 
INFO 6/11/14 9:32 AM:liquibase: Reading from pryme_dev.DATABASECHANGELOG 
INFO 6/11/14 9:32 AM:liquibase: Reading from pryme_dev.DATABASECHANGELOG 
INFO 6/11/14 9:32 AM:liquibase: Reading from pryme_dev.DATABASECHANGELOG 
INFO 6/11/14 9:32 AM:liquibase: liquibase/changelog.xml: liquibase/2014/1-1.xml::05192014.1525::harith: Reading from pryme_dev.DATABASECHANGELOG 
SEVERE 6/11/14 9:32 AM:liquibase: liquibase/changelog.xml: liquibase/2014/1-1.xml::05192014.1525::harith: Change Set liquibase/2014/1-1.xml::05192014.1525::harith failed. Error: Error executing SQL CREATE TABLE pryme_dev.network (id INT NOT NULL, network_id BIGINT UNSIGNED NOT NULL, name VARCHAR(255) NOT NULL, display_name VARCHAR(255) NOT NULL, active TINYINT(1) DEFAULT 1 NOT NULL, created_at TIMESTAMP DEFAULT NOW() NOT NULL, updated_at TIMESTAMP DEFAULT '1970-01-01 00:00:01' NOT NULL, created_by VARCHAR(50) DEFAULT 'pryme_user' NULL, updated_by VARCHAR(50) DEFAULT 'pryme_user' NULL, CONSTRAINT PK_NETWORK PRIMARY KEY (id)): Table 'network' already exists 
liquibase.exception.DatabaseException: Error executing SQL CREATE TABLE pryme_dev.network (id INT NOT NULL, network_id BIGINT UNSIGNED NOT NULL, name VARCHAR(255) NOT NULL, display_name VARCHAR(255) NOT NULL, active TINYINT(1) DEFAULT 1 NOT NULL, created_at TIMESTAMP DEFAULT NOW() NOT NULL, updated_at TIMESTAMP DEFAULT '1970-01-01 00:00:01' NOT NULL, created_by VARCHAR(50) DEFAULT 'pryme_user' NULL, updated_by VARCHAR(50) DEFAULT 'pryme_user' NULL, CONSTRAINT PK_NETWORK PRIMARY KEY (id)): Table 'network' already exists 
    at liquibase.executor.jvm.JdbcExecutor.execute(JdbcExecutor.java:61) 
    at liquibase.executor.jvm.JdbcExecutor.execute(JdbcExecutor.java:106) 
    at liquibase.database.AbstractJdbcDatabase.execute(AbstractJdbcDatabase.java:1189) 
    at liquibase.database.AbstractJdbcDatabase.executeStatements(AbstractJdbcDatabase.java:1172) 
    at liquibase.changelog.ChangeSet.execute(ChangeSet.java:352) 
    at liquibase.changelog.visitor.UpdateVisitor.visit(UpdateVisitor.java:40) 
    at liquibase.changelog.ChangeLogIterator.run(ChangeLogIterator.java:64) 
    at liquibase.Liquibase.update(Liquibase.java:202) 
    at liquibase.Liquibase.update(Liquibase.java:181) 
    at com.yahoo.comma.persistence.DataSetupTest.liquibaseUpdate(DataSetupTest.java:53) 
    at com.yahoo.comma.integration.IT1DataSetup.generateDataSet(IT1DataSetup.java:46) 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
    at java.lang.reflect.Method.invoke(Method.java:606) 
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47) 
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) 
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44) 
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17) 
    at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:74) 
    at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:83) 
    at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:72) 
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:232) 
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:89) 
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238) 
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63) 
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236) 
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53) 
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229) 
    at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61) 
    at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:71) 
    at org.junit.runners.ParentRunner.run(ParentRunner.java:309) 
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:175) 
    at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:236) 
    at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:134) 
    at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:113) 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
    at java.lang.reflect.Method.invoke(Method.java:606) 
    at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:189) 
    at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:165) 
    at org.apache.maven.surefire.booter.ProviderFactory.invokeProvider(ProviderFactory.java:85) 
    at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:103) 
    at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:74) 
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'network' already exists 
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) 
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57) 
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) 
    at java.lang.reflect.Constructor.newInstance(Constructor.java:526) 
    at com.mysql.jdbc.Util.handleNewInstance(Util.java:406) 
    at com.mysql.jdbc.Util.getInstance(Util.java:381) 
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1030) 
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956) 
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3491) 
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3423) 
    at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1936) 
    at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2060) 
    at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2536) 
    at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2465) 
    at com.mysql.jdbc.StatementImpl.execute(StatementImpl.java:734) 
    at org.apache.commons.dbcp.DelegatingStatement.execute(DelegatingStatement.java:264) 
    at org.apache.commons.dbcp.DelegatingStatement.execute(DelegatingStatement.java:264) 
    at liquibase.executor.jvm.JdbcExecutor$ExecuteStatementCallback.doInStatement(JdbcExecutor.java:294) 
    at liquibase.executor.jvm.JdbcExecutor.execute(JdbcExecutor.java:54) 
    ... 44 more 
INFO 6/11/14 9:32 AM:liquibase: liquibase/2014/1-1.xml::05192014.1525::harith: Successfully released change log lock 
09:32:14.299 [main] DEBUG o.s.t.c.s.DirtiesContextTestExecutionListener - After test method: context [[email protected] 

問題
- 爲什麼將所有的變更時,數據庫已經填充並且該數據庫有DATABASECHANGELOG文件存在?
- 我該如何解決此問題?

由於

+0

看着堆棧跟蹤,這不是液化石油氣,而是更多的方式來設置你的測試用例。 –

回答

9

問題往往是因爲對於每個變更集的唯一標識符的一部分是路徑到更改日誌文件。看起來它目前看作是「liquibase/2014/1-1.xml」。

如果您運行select * from databasechangelog where id='05192014.1525'數據庫中已存在的路徑是什麼?

+0

在我的情況下,不知何故'DATABASECHANGELOG'表本身是空的。不過,其他表格也是如此 – daydreamer

4

只需爲問題發生的原因添加新的更直接的信息。

Liquibase DATABASECHANGELOG Documentation

Liquibase使用DATABASECHANGELOG表來跟蹤其變更已經跑了。

表跟蹤每個變更爲行,由「ID」,「作者」和存儲的路徑,更新日誌文件中的「文件名」列的組合來標識。

請注意,文件名列存儲更改日誌的路徑。這可能是絕對路徑或相對路徑,具體取決於更新日誌是如何傳遞給Liquibase的。 爲獲得最佳效果,它應該是相對路徑

如果移動數據庫(如遷移的情況),並且文件名列包含完整路徑,則Liquibase可能無法識別DATABASECHANGELOG表中的變更集。

相關問題