2017-04-10 73 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脚本在路上,这个配置也需要进行更新。