-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathFlywayConfig.java
More file actions
38 lines (30 loc) · 1.16 KB
/
FlywayConfig.java
File metadata and controls
38 lines (30 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package com.kernelsquare.domainmysql.config;
import jakarta.annotation.PostConstruct;
import org.flywaydb.core.Flyway;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.orm.jpa.JpaVendorAdapter;
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
import javax.sql.DataSource;
@Configuration
public class FlywayConfig {
@Autowired
private DataSource dataSource;
@PostConstruct
public void migrateFlyway() {
Flyway flyway = Flyway.configure()
.dataSource(dataSource)
.load();
flyway.repair();
flyway.migrate();
}
@Bean
public LocalContainerEntityManagerFactoryBean entityManagerFactory(DataSource dataSource, JpaVendorAdapter jpaVendorAdapter) {
LocalContainerEntityManagerFactoryBean emfb = new LocalContainerEntityManagerFactoryBean();
emfb.setDataSource(dataSource);
emfb.setPackagesToScan("com.kernelsquare.domainmysql");
emfb.setJpaVendorAdapter(jpaVendorAdapter);
return emfb;
}
}