Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- spring.flyway.locations=classpath:db/migration/{vendor}
- package com.flyway.demo.configuration;
- import org.apache.commons.dbcp.BasicDataSource;
- import org.flywaydb.core.Flyway;
- import org.springframework.cache.annotation.EnableCaching;
- import org.springframework.context.annotation.*;
- import org.springframework.data.jpa.repository.config.EnableJpaAuditing;
- import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
- import org.springframework.transaction.annotation.EnableTransactionManagement;
- import javax.sql.DataSource;
- /**
- * @author ftaher
- * @since 4/2/2018
- */
- @Configuration
- @Profile("mysql")
- @EnableJpaRepositories(basePackages = "com.flyway.demo")
- @EnableJpaAuditing
- @EnableTransactionManagement(proxyTargetClass = true)
- @EnableCaching
- public class FlywayConfigurationSQL {
- @Bean(name = "flyway")
- @DependsOn(value = "dataSource")
- public Flyway flyWay() {
- Flyway flyway = new Flyway();
- flyway.setDataSource(dataSource());
- flyway.setBaselineVersionAsString("0");
- flyway.setBaselineOnMigrate(true);
- flyway.setSchemas("test");
- flyway.setLocations("classpath:db/migration/{vendor}");
- flyway.setTable("DEMOSQL_SCHEMA_VERSION");
- flyway.migrate();
- return flyway;
- }
- @Bean(name = "dataSource")
- @Primary
- public DataSource dataSource() {
- BasicDataSource dataSource = new BasicDataSource();
- dataSource.setUrl("jdbc:mysql://localhost:3306/test");
- dataSource.setUsername("root");
- dataSource.setPassword("root");
- dataSource.setTestOnReturn(true);
- dataSource.setTestWhileIdle(true);
- return dataSource;
- }
- }
Add Comment
Please, Sign In to add comment