2015-03-31 63 views
2

我遵循了幾個教程,並配置了用於數據庫初始化的Flyway。Flyway在Spring MVC中沒有選擇遷移文件

我從MYSQL(沒有數據)採取模式轉儲並命名文件V1__initialSchema.sql。所以這是充滿了特定的創建表,外鍵等由mysql轉儲。

然後,我已經配置了豆:

遷飛Initiailser

@Bean(initMethod = "migrate") 
protected Flyway flyway() { 
    Flyway flyway = new Flyway(); 
    flyway.setBaselineOnMigrate(true); 
    //flyway.setLocations("classpath:db/migration"); 
    flyway.setDataSource(dataSource()); 

    return flyway; 
} 

JPA初始化器

@Bean 
@DependsOn(value = "flyway") 
public LocalContainerEntityManagerFactoryBean entityManagerFactory() { 
    LocalContainerEntityManagerFactoryBean factory = new LocalContainerEntityManagerFactoryBean(); 
    HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter(); 
    factory.setDataSource(dataSource()); 
    factory.setJpaVendorAdapter(vendorAdapter); 
    factory.setPackagesToScan("com.ideafactory.mvc", "com.ideafactory.plugins"); 


    Properties jpaProperties = new Properties(); 
    jpaProperties.put("hibernate.dialect", "org.hibernate.dialect.MySQLDialect"); 
    //jpaProperties.put("hibernate.hbm2ddl.auto","create-drop"); 
    jpaProperties.put("hibernate.show_sql", false); 
    jpaProperties.put("hibernate.format_sql", false); 
    jpaProperties.put("hibernate.use_sql_comments", false); 
    jpaProperties.put("hibnerate.connection.CharSet", "utf8"); 
    jpaProperties.put("hibernate.connect.characterEncoding", "utf8"); 
    jpaProperties.put("hibernate.connection.useUnicode", true); 

    jpaProperties.put("jadira.usertype.autoRegisterUserTypes", true); 

    factory.setJpaProperties(jpaProperties); 
    factory.afterPropertiesSet(); 
    factory.setLoadTimeWeaver(new InstrumentationLoadTimeWeaver()); 
    return factory; 
} 

我打開日誌,我可以看到它是 「跳過」 我INITIALISE文件,我不知道爲什麼。架構尚未創建。

l.util.logging.slf4j.Slf4jLog 40 debug - Scanning for classpath resources at 'db/migration' (Prefix: 'V', Suffix: '.sql') 
16:35:08.272 DEBUG org.flywaydb.core.internal.util.logging.slf4j.Slf4jLog 40 debug - Scanning URL: file:/Users//Documents/Projects/MerchantX/target/java_ecommerce/WEB-INF/classes/db/migration/ 
16:35:08.273 DEBUG org.flywaydb.core.internal.util.logging.slf4j.Slf4jLog 40 debug - JBoss VFS v2 available: false 
16:35:08.273 DEBUG org.flywaydb.core.internal.util.logging.slf4j.Slf4jLog 40 debug - Scanning starting at classpath root in filesystem: /Users//Documents/Projects/MerchantX/target/java_ecommerce/WEB-INF/classes/ 
16:35:08.273 DEBUG org.flywaydb.core.internal.util.logging.slf4j.Slf4jLog 40 debug - Scanning for resources in path: /Users//Documents/Projects/MerchantX/target/java_ecommerce/WEB-INF/classes/db/migration (db/migration) 
16:35:08.273 DEBUG org.flywaydb.core.internal.util.logging.slf4j.Slf4jLog 40 debug - Found resource: db/migration/V1__initialSchema.sql 
16:35:08.279 DEBUG org.flywaydb.core.internal.util.logging.slf4j.Slf4jLog 40 debug - Scanning for classes at 'db/migration' (Implementing: 'org.flywaydb.core.api.migration.jdbc.JdbcMigration') 
16:35:08.279 DEBUG org.flywaydb.core.internal.util.logging.slf4j.Slf4jLog 40 debug - Scanning URL: file:/Users//Documents/Projects/MerchantX/target/java_ecommerce/WEB-INF/classes/db/migration/ 
16:35:08.279 DEBUG org.flywaydb.core.internal.util.logging.slf4j.Slf4jLog 40 debug - JBoss VFS v2 available: false 
16:35:08.280 DEBUG org.flywaydb.core.internal.util.logging.slf4j.Slf4jLog 40 debug - Scanning starting at classpath root in filesystem: /Users//Documents/Projects/MerchantX/target/java_ecommerce/WEB-INF/classes/ 
16:35:08.280 DEBUG org.flywaydb.core.internal.util.logging.slf4j.Slf4jLog 40 debug - Scanning for resources in path: /Users//Documents/Projects/MerchantX/target/java_ecommerce/WEB-INF/classes/db/migration (db/migration) 
16:35:08.280 DEBUG org.flywaydb.core.internal.util.logging.slf4j.Slf4jLog 40 debug - Filtering out resource: db/migration/V1__initialSchema.sql (filename: V1__initialSchema.sql) 
16:35:08.281 DEBUG org.flywaydb.core.internal.util.logging.slf4j.Slf4jLog 40 debug - Scanning for classes at 'db/migration' (Implementing: 'org.flywaydb.core.api.migration.spring.SpringJdbcMigration') 
16:35:08.281 DEBUG org.flywaydb.core.internal.util.logging.slf4j.Slf4jLog 40 debug - Scanning URL: file:/Users//Documents/Projects/MerchantX/target/java_ecommerce/WEB-INF/classes/db/migration/ 
16:35:08.282 DEBUG org.flywaydb.core.internal.util.logging.slf4j.Slf4jLog 40 debug - JBoss VFS v2 available: false 
16:35:08.282 DEBUG org.flywaydb.core.internal.util.logging.slf4j.Slf4jLog 40 debug - Scanning starting at classpath root in filesystem: /Users//Documents/Projects/MerchantX/target/java_ecommerce/WEB-INF/classes/ 
16:35:08.282 DEBUG org.flywaydb.core.internal.util.logging.slf4j.Slf4jLog 40 debug - Scanning for resources in path: /Users//Documents/Projects/MerchantX/target/java_ecommerce/WEB-INF/classes/db/migration (db/migration) 
16:35:08.282 DEBUG org.flywaydb.core.internal.util.logging.slf4j.Slf4jLog 40 debug - Filtering out resource: db/migration/V1__initialSchema.sql (filename: V1__initialSchema.sql) 

我以前沒有使用Flyway,任何人都可以解釋爲什麼它過濾了我的初始化文件?

+0

你在開始時是否有空模式? – sodik 2015-03-31 09:09:11

回答

2

AFAIK baselineOnMigrate根據DB中的實際模式創建第一個(V1)版本。只有以下版本才能應用(V1.1,V2,...)。

因此,要麼不使用baselineOnMigrate,但您需要從空數據庫模式開始,或者從(如。)V2開始索引您的版本。

+0

好的謝謝,這是一個不錯的和簡單的修復。我只是將文件重命名爲V2。乾杯。 – 2015-03-31 11:34:34

+0

絕對正確! – 2016-07-22 15:38:20