How to disable flyway in a certain spring profile?

Viewed 69411

Now I have a spring-boot app which uses MsSQL server. And we use flyway for migrations.

I want to add an additional profile for tests. I want to generate tables from entity classes instead of using flyway.

I tried smth to write like this in application.yaml

spring:
  profiles: test
  jpa:
      generate-ddl: true
      hibernate:
  datasource:
    url: jdbc:h2:mem:test_db;MODE=MSSQLServer
    username: sa
    password:

but flyway starts anyway

5 Answers

JIC the official documentation with current spring boot 2.x : Data migration properties and take a look on tag # FLYWAY you will find many properties that can help you.

spring.flyway.enabled=false # Whether to enable flyway.

I am having multiple profiles e.g.

  1. application-integration.yml
  2. application.yml

in application.yml

spring:
  profiles:
    active: ${ENVIRONMENT_NAME:local}
  flyway:
    enabled: true
    user: ${ORACLE_DB_USER:#{null}}
    password: ${ORACLE_DB_PASS:#{null}}
    locations: classpath:db/migration
    url: ${DB_URL:#{null}}
    driver-class-name: oracle.jdbc.OracleDriver
    #    skipExecutingMigrations: true
    tablespace: MY_TABLESPACE_NAME
    baselineOnMigrate: true
    schemas: MY_SCHEMA_NAME

in application-integration.yml

spring:
  flyway:
    enabled: false

when I am running it, its not disabling flyway migration. I am using SpringBoot2.3.4

Here eample of application.yaml It defines 2 profiles:
1. enable_flyway_profile - enables flyway
2. disable_flyway_profile - disables flyway

spring:
  profiles:
    active: "enable_flyway_profile"
  flyway:
    enable: true
  ....

---

spring:
  profiles:
    active: "disable_flyway_profile"
  flyway:
    enable: false
  ....
Related