2016-03-18 45 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