我通过flyway初始化数据库,之后,如果应用程序在本地运行,我需要运行带有测试数据的脚本。Flyway 工作正常,但测试脚本存在一些困难——它们不起作用。初始化属性如下所示:
# data source properties
# ��������� �� - ��. DatasourceConfig
database.port=5482
#spring.datasource.url=jdbc:postgresql://127.0.0.1:${database.port}}/
#spring.datasource.username=postgres
#spring.datasource.password=
spring.datasource.initialize=true
spring.datasource.character=utf-8
spring.datasource.embedded-directory = target
#spring.datasource.schema=classpath:db/migration/common/V001__schema.sql
spring.datasource.data=classpath:db/migration/dev/init.sql
# JPA properties
spring.jpa.database-platform=org.hibernate.dialect.PostgreSQL9Dialect
spring.jpa.show-sql=true
spring.jpa.generate-ddl=false
spring.jpa.hibernate.ddl-auto=none
spring.jpa.open-in-view=false
spring.jpa.properties.hibernate.temp.use_jdbc_metadata_defaults=false
# migration properties
spring.flyway.enabled=true
spring.flyway.check-location=false
spring.flyway.baseline-on-migrate=true
spring.flyway.baseline-version=0
spring.flyway.locations=classpath:db/migration/common
根据初始化逻辑,应该执行变量可访问的脚本
spring.datasource.data=classpath:db/migration/dev/init.sql
但基地是空的。告诉我出了什么事?
为了推出演示数据,我使用相同的 Flyway 和单独的 Spring 配置文件(例如dev):在一个文件夹中有通用脚本(用于开发和销售),在另一个文件夹中有演示数据的脚本。或多或少是这样的:
设置文件,common 和 dev:
应用程序.yml:
应用程序-dev.yml:
这是版本控制迁移文件的一个棘手时刻 - 如果您指定一个颠覆(通过点或下划线),那么 Flyway 将以正确的顺序滚动脚本,无论它们存储在哪个目录中:1.1、1.2、2.0 等.
更多的:
PS 至于属性
spring.datasource.data
,我可以假设如果 Flyway 被激活,Booth 不会使用它。