Java – liquibase attempts to apply all changesets, even if the database exists

I use spring - liquibase to perform any migration required to stage the database

applicationContext. XML looks like

<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>

When I deploy the war file, I see that the error in the log is

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,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 [DefaultTestContext@3ba0fcf

Question – why apply all change sets when the database is populated and the databasechangelog file exists in the database? – How can I solve this problem?

thank you

Solution

The problem is usually because part of the unique identifier of each changeset is the path to the changelog file It looks like it is currently considered "liquibase / 2014 / 1-1. XML"

If you run select * from databasechangelog, where id = '05192014.1525', what is the existing path in the database?

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>