Spring Boot Flyway迁移占位符

use*_*765 3 spring flyway spring-boot application.properties

有人可以显示正确的格式以用于在Flyway迁移中使用application.properties配置。

我想在我的application.properties文件中使用数据源配置的用户名来授予数据库表的权限(使用Flyway进行数据库迁移,用户名最终会因环境而异),但是我找不到语法的示例。

示例application.properties:

#  Database
spring.datasource.driver-class-name=org.postgresql.Driver
spring.datasource.url=jdbc:postgresql://localhost:5432/example_db
spring.datasource.username=example_db_application
spring.datasource.password=examplePassword1
Run Code Online (Sandbox Code Playgroud)

移民:

CREATE TABLE token
(
  id TEXT,
  value TEXT,
);

GRANT SELECT, INSERT, UPDATE, DELETE ON token TO ${spring.datasource.username};
Run Code Online (Sandbox Code Playgroud)

我尝试了各种迭代(flyway.placeholders.spring.datasource.username,尝试不指定前缀:spring.flyway.placeholder-prefix =),但是没有运气。

fat*_*ddy 5

Spring-Boot为路径下的飞行路线迁移占位符值提供了通用的应用程序属性 spring.flyway.placeholders.*=

用法

# application.properties
# -> placeholder value `user`
spring.flyway.placeholders.user=joe
Run Code Online (Sandbox Code Playgroud)
-- db/migration/V3__Migration_With_Placeholder.sql`:

CREATE TABLE ${user} (
   ...
)
Run Code Online (Sandbox Code Playgroud)

  • spring.datasource.hikari.username=myuser spring.flyway.placeholders.user=${spring.datasource.hikari.username} (3认同)