2016-03-18 48 views
1

我使用liquibase与maven-3。第一次运行按预期工作。虽然连续运行(即使sql文件包含更改)也会失败,因为它们被视为与liquibase等效并被忽略(校验和)。liquibase Maven插件禁用校验

都在我的SQL脚本的SQL行动已经考虑到了之前的运行,所以我不希望这种行为。有了这个设置,你看下面,我怎么能强迫liquibase到总是执行我的剧本,不管变化?

正如你可以看到下面我已经尝试设置clearCheckSums作为追求的目标,事实上它清除哈希值,但仍没有运气(因此注释掉)。 这是我创建

<profile> 
    <id>liquibase-executions</id> 
    <build> 
     <defaultGoal>process-resources</defaultGoal> 
     <plugins> 
      <plugin> 
       <groupId>org.liquibase</groupId> 
       <artifactId>liquibase-maven-plugin</artifactId> 
       <version>3.4.2</version> 
       <dependencies> 
        <dependency> 
         <groupId>org.postgresql</groupId> 
         <artifactId>postgresql</artifactId> 
         <version>${postgres.version}</version> 
        </dependency> 
       </dependencies> 
       <executions> 
        <execution> 
         <id>update-schema</id> 
         <phase>process-resources</phase> 
         <goals> 
          <goal>update</goal> 
          <!--<goal>clearCheckSums</goal>--> 
         </goals> 
         <configuration> 
          <driver>org.postgresql.Driver</driver> 
          <url>jdbc:postgresql://${db.url}</url> 
          <promptOnNonLocalDatabase>false</promptOnNonLocalDatabase> 
          <changeLogFile>${basedir}/src/main/resources/liquibase.sql</changeLogFile> 
         </configuration> 
        </execution> 
        <execution> 
         <id>update-data</id> 
         <phase>process-resources</phase> 
         <goals> 
          <goal>update</goal> 
          <!--<goal>clearCheckSums</goal>--> 
         </goals> 
         <configuration> 
          <driver>org.postgresql.Driver</driver> 
          <url>jdbc:postgresql://${db.url}</url> 
          <promptOnNonLocalDatabase>false</promptOnNonLocalDatabase> 
          <changeLogFile>${basedir}/src/main/resources/liquibase-populate.sql</changeLogFile> 
         </configuration> 
        </execution> 
       </executions> 
      </plugin> 
     </plugins> 
    </build> 
</profile> 

的形象和我这是怎么执行它

mvn process-resources -Pliquibase-executions -Ddb.url=POSTGRES_IP:5432/POSTGRES_DB -Dliquibase.username=POSTGRES_USERNAME 

回答

1

的Liquibase Maven插件expects一个changelog file,没有纯.sql文件。这个文件应该包含你想让Liquibase执行的changeSets。每次运行Liquibase时,都可以指示这些changeSets被运行(默认情况下,它们只能执行一次)。所以不需要篡改校验和。例如你的更新日志文件可能是这个样子:

<databaseChangeLog 
    xmlns="http://www.liquibase.org/xml/ns/dbchangelog" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog 
     http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.1.xsd"> 

    <changeSet id="your-id" author="msp" runAlways="true"> 
    ... 
    </changeSet> 
</databaseChangeLog> 

达到您的预期行为的重要组成部分,是设置在liquibase变更的runAlways="true"属性。

+0

我没有在我的设置中使用'changeSet'任何地方。我正在使用的是'changeLogFile'。是否可以根据我的文章中提供的设置提供解决方案?如果我必须引入'changeSet'才能使用这个属性,那么完成的最终结果是什么? – alkis

+0

否'changeSet'? Liquibase解析'changeLogFile'中的databaseChangeLog标签,检查前提条件,如果没有失败,则执行changeSets。恕我直言,这是Liquibase不可分割的一部分,我认为你错用了它。 – msparer

+0

那里没有参数。这是我第一次使用这个插件,所以我试图获得它的要点。你能否提供一个包含'changeSet'的解决方案(考虑到上面的设置),并将你的评论移到你的文章中供将来参考? – alkis