spring-boot - 内容被附加到通过 JPA 脚本生成生成的 DDL 文件中,而不是被替换
问题描述
自从更新到 Spring Boot 2 后,我注意到使用 spring.jpa.properties.javax.persistence.schema-generation.scripts.* 选项时生成 DDL 文件的方式发生了变化。
以前,在 Spring Boot 1.5 中,每次我运行我的应用程序或测试(我也有检查这些文件内容的集成测试)时,都会重新生成 DDL 文件,例如:
drop table testSchema.App if exists
drop table testSchema.AppMetadata if exists
drop table testSchema.Server if exists
drop table testSchema.User if exists
drop table testSchema.UserRole if exists
drop table testSchema.UserToken if exists
现在,在升级到 Spring Boot 2.0.5 之后,每次我运行我的测试或应用程序时,内容都会以这种方式附加到 DDL 文件中:
drop table testSchema.App if exists
drop table testSchema.AppMetadata if exists
drop table testSchema.Server if exists
drop table testSchema.User if exists
drop table testSchema.UserRole if exists
drop table testSchema.UserToken if exists
drop table testSchema.App if exists
drop table testSchema.AppMetadata if exists
drop table testSchema.Server if exists
drop table testSchema.User if exists
drop table testSchema.UserRole if exists
drop table testSchema.UserToken if exists
drop table testSchema.App if exists
drop table testSchema.AppMetadata if exists
drop table testSchema.Server if exists
drop table testSchema.User if exists
drop table testSchema.UserRole if exists
drop table testSchema.UserToken if exists
不确定这是框架的新行为还是我现在才出现的配置问题。这是我的 test.properties 文件(如前所述,正常运行应用程序时会发生同样的问题,但配置相对相似)。
# ========= DATA SOURCE : DB connection ========
spring.datasource.url=jdbc:h2:mem:myDb;INIT=CREATE SCHEMA IF NOT EXISTS testSchema
spring.datasource.username=________
spring.datasource.password=________
# ========= JPA / HIBERNATE =========
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.H2Dialect
spring.jpa.properties.hibernate.default_schema=testSchema
# DDL operations via Hibernate =========
spring.jpa.hibernate.ddl-auto = none
spring.jpa.generate-ddl = false
spring.jpa.show-sql=false
spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
# DDL operations via JPA =========
spring.jpa.properties.javax.persistence.schema-generation.database.action=drop-and-create
spring.jpa.properties.javax.persistence.schema-generation.scripts.action=drop-and-create
spring.jpa.properties.javax.persistence.schema-generation.drop-source=metadata
spring.jpa.properties.javax.persistence.schema-generation.create-source=metadata
spring.jpa.properties.javax.persistence.schema-generation.scripts.drop-target=./src/test/resources/test_data/dbCreationTestFiles/jpaGenerated_drop_test_sys_db.ddl
spring.jpa.properties.javax.persistence.schema-generation.scripts.create-target=./src/test/resources/test_data/dbCreationTestFiles/jpaGenerated_create_test_sys_db.ddl
我的配置有问题吗?如何设置以便在每次运行时都重写 DDL 文件?
谢谢。
解决方案
推荐阅读
- node.js - discord.js v13 我将使用什么代码从 MessageCollector 收集第一个附件(图像或视频)?
- sql - Postgresql函数,有条件地做不同的JOIN
- r - R将对象打印到文件
- amazon-web-services - DynamoDb 查询 API 与 PartiQL - RCU 的
- sql - 为什么 SQL JOIN 查询会从错误的表中给出结果?
- docker - 无法卸载 docker-compose
- vb.net - 使用 VB.net 打开所有格式标记可见的 Word 文档
- javascript - 如何过滤当月的提醒日期?
- go - Go 通道写入顺序保证
- javascript - 通过 module.exports 从 NodeJS 中的外部文件导入?