2017-04-10 74 views
0

發佈這個自我回答,所以當我在幾個月內再次打破時,答案會實際上在谷歌出現。Proguard休息Flyway數據庫遷移

Flyway API用於遷移數據庫模式的簡單Java項目。遵循V1__init.sql,V2__updateCustomerTable.sql約定的sql腳本資源目錄用於檢查schema_version元數據表並根據需要進行遷移。

一切工作正常,直到jar被編程。 SQL腳本肯定是打包成jar文件,但他們都沒有找到:

2017-04-10 17:17:13,612 [main] DEBUG (?:?) - Validating migrations ... 
2017-04-10 17:17:13,884 [main] DEBUG (?:?) - Scanning for classpath resources at 'classpath:db/migration/postgres' (Prefix: '', Suffix: '.sql') 
2017-04-10 17:17:13,885 [main] DEBUG (?:?) - Determining location urls for classpath:db/migration/postgres using ClassLoader [email protected] ... 
2017-04-10 17:17:13,885 [main] WARN (?:?) - Unable to resolve location classpath:db/migration/postgres 
2017-04-10 17:17:13,899 [main] DEBUG (?:?) - Scanning for classpath resources at 'classpath:db/migration/postgres' (Prefix: 'V', Suffix: '.sql') 
2017-04-10 17:17:13,900 [main] DEBUG (?:?) - Scanning for classpath resources at 'classpath:db/migration/postgres' (Prefix: 'R', Suffix: '.sql') 

一個沒有proguarded罐子發現他們具有以下日誌消息(請注意,它看起來在jar文件現在):

2017-04-10 17:07:16,612 [main] DEBUG (?:?) - Validating migrations ... 
2017-04-10 17:07:16,613 [main] DEBUG (?:?) - Scanning for classpath resources at 'classpath:db/migration/postgres' (Prefix: 'V', Suffix: '.sql') 
2017-04-10 17:07:16,614 [main] DEBUG (?:?) - Scanning URL: jar:file:/C:/Dev/Sanbox/myjar.jar!/db/migration/postgres 
2017-04-10 17:07:16,614 [main] DEBUG (?:?) - JBoss VFS v2 available: false 
2017-04-10 17:07:16,615 [main] DEBUG (?:?) - Filtering out resource: db/migration/postgres/ (filename:) 
2017-04-10 17:07:16,615 [main] DEBUG (?:?) - Found resource: db/migration/postgres/V1__init.sql 
2017-04-10 17:07:16,616 [main] DEBUG (?:?) - Found resource: db/migration/postgres/V2__updateCustomerTable.sql 

回答

0

罪魁禍首是您需要告訴proguard將您的db/migrations目錄放在您的配置文件中(或者將您的遷移腳本放在任何位置),否則flyway將無法找到您的腳本,即使它們看起來像在罐子裏的正確位置。這是我需要在我的ProGuard配置行:

-keepdirectories db/migration/** 

如果你改變,你把你的SQL腳本在路上,這個配置也需要進行更新。