feat: add Flyway and migration generation support
This commit is contained in:
@@ -19,6 +19,7 @@ repositories {
|
||||
|
||||
dependencies {
|
||||
implementation 'org.springframework.boot:spring-boot-starter'
|
||||
implementation 'org.flywaydb:flyway-core'
|
||||
compileOnly 'org.projectlombok:lombok'
|
||||
developmentOnly 'org.springframework.boot:spring-boot-devtools'
|
||||
// developmentOnly 'org.springframework.boot:spring-boot-docker-compose'
|
||||
@@ -26,6 +27,7 @@ dependencies {
|
||||
|
||||
implementation 'org.springframework.boot:spring-boot-starter-cache'
|
||||
annotationProcessor 'org.springframework.boot:spring-boot-configuration-processor'
|
||||
annotationProcessor 'org.hibernate.orm:hibernate-jpamodelgen:6.4.4.Final'
|
||||
annotationProcessor 'org.projectlombok:lombok'
|
||||
testImplementation 'org.springframework.boot:spring-boot-starter-test'
|
||||
//testImplementation 'org.springframework.boot:spring-boot-testcontainers'
|
||||
@@ -55,3 +57,27 @@ dependencies {
|
||||
tasks.named('test') {
|
||||
useJUnitPlatform()
|
||||
}
|
||||
|
||||
tasks.register('generateMigration', JavaExec) {
|
||||
dependsOn 'classes'
|
||||
|
||||
classpath = sourceSets.main.runtimeClasspath
|
||||
mainClass = 'org.hibernate.tool.Main'
|
||||
|
||||
args = [
|
||||
'--hbm2ddl-auto', 'update',
|
||||
'--properties', 'application.properties',
|
||||
'--output', 'src/main/resources/db/migration/V' + getNextMigrationVersion() + '__auto_generated.sql'
|
||||
]
|
||||
}
|
||||
|
||||
static def getNextMigrationVersion() {
|
||||
def existing = file('src/main/resources/db/migration').listFiles()?.collect {
|
||||
(it.name =~ /V(\d+)__/)[0][1]
|
||||
}?.max() ?: 0
|
||||
return String.format("%03d", existing.toInteger() + 1)
|
||||
}
|
||||
|
||||
flyway {
|
||||
locations = ['classpath:db/migration']
|
||||
}
|
||||
|
||||
@@ -13,6 +13,12 @@ spring.jpa.hibernate.ddl-auto=update
|
||||
spring.jpa.generate-ddl=true
|
||||
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect
|
||||
|
||||
# Flyway Configuration
|
||||
spring.flyway.enabled=true
|
||||
spring.flyway.locations=classpath:db/migration
|
||||
spring.flyway.baseline-on-migrate=true
|
||||
spring.flyway.validate-on-migrate=true
|
||||
|
||||
# ?????????? SQL-???????
|
||||
spring.jpa.show-sql=true
|
||||
spring.jpa.properties.hibernate.format_sql=false
|
||||
@@ -23,4 +29,4 @@ logging.level.org.hibernate.type.descriptor.sql.BasicBinder=TRACE
|
||||
logging.level.io.hypersistence.utils.hibernate.query=DEBUG
|
||||
|
||||
# ??????????? ????
|
||||
logging.level.org.springframework.cache=INFO
|
||||
logging.level.org.springframework.cache=INFO
|
||||
|
||||
Reference in New Issue
Block a user