【发布时间】:2017-12-21 01:31:05
【问题描述】:
概览
我将使用以下配置将 flyway db 迁移添加到现有项目:
- 项目类型:Spring Boot
- 数据库:MariaDB
application-local.yaml(Flyway 和数据源配置):
...
flyway:
enabled: true
locations: classpath:db.migration
baselineOnMigrate: true
spring:
jackson:
serialization:
indent_output: true
devtools:
restart:
enabled: false
livereload:
enabled: false
datasource:
type: com.zaxxer.hikari.HikariDataSource
url: jdbc:mariadb://localhost:3306/migration
username: root
password: testing1
hikari:
data-source-properties:
leakDetectionThreshold: 2000
cachePrepStmts: true
prepStmtCacheSize: 250
prepStmtCacheSqlLimit: 2048
useServerPrepStmts: true
jpa:
database-platform: org.hibernate.dialect.MySQL5Dialect
database: MYSQL
show-sql: false
hibernate.id.new_generator_mappings: true
properties:
hibernate.cache.use_second_level_cache: false
hibernate.cache.use_query_cache: false
hibernate.generate_statistics: false
hibernate.hbm2ddl.import_files: schema-mysql.sql
hibernate.hbm2ddl.import_files_sql_extractor: org.hibernate.tool.hbm2ddl.MultipleLinesSqlCommandExtractor
open-in-view: false
hibernate:
ddl-auto: create-drop
naming:
physical-strategy: org.springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy
implicit-strategy: org.springframework.boot.orm.jpa.hibernate.SpringImplicitNamingStrategy
...
问题:
当应用程序停止时,数据库表不会被删除。但是当我使用ddl-auto: create-drop 时,预计表会被删除。
注意: 我知道将 Flyway 用于 volatile DB 似乎有点奇怪。因为有一些配置类可以在启动时插入初始数据。如果应用程序停止时db没有被删除,它会在下次启动时出现抱怨[例如:违反唯一约束],因为初始值已经插入。
如果有人能帮助我提供真正的解决方案,我将不胜感激。
【问题讨论】:
标签: java spring-boot gradle mariadb flyway