How to disable flyway in a certain spring profile?

JavaSpringSpring BootFlywaySpring Profiles

Java Problem Overview


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

Java Solutions


Solution 1 - Java

FYI, for anybody who comes here looking for this, the property name has changed for Spring Boot 2.0:

For application.properties format:

spring.flyway.enabled=false

For application.yml format:

spring:
    flyway:
        enabled: false

Update: To disable flyway in a specific profile, you can put that property in the properties file specific to that profile. For instance, if your profile is called "abc", you can put it in application-abc.properties. Check out Spring's documentation on Profile-specific properties for more clarity on how to name the files. Generally, the format is application-{profileName}.properties.

Solution 2 - Java

Doesn't for for Spring Boot 2.X ! Correct answer is here.

Continue reading if you need an answer for Spring Boot 1.X.

There is a property available for spring-boot to disable flyway if it's needed flyway.enabled which is true by default.

You can have a profile specific configuration, in your case it should be named as application-test.yml. This configuration can disable flyway if profile is active. You just have to declare it as follows:

flyway:
  enabled: false

And if you specify test profile in common configuration, just add it to it's root.

Solution 3 - Java

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.

Solution 4 - Java

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

Solution 5 - Java

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
  ....

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestiongstackoverflowView Question on Stackoverflow
Solution 1 - JavaToddView Answer on Stackoverflow
Solution 2 - JavaStanislavView Answer on Stackoverflow
Solution 3 - JavaJonathan JOhxView Answer on Stackoverflow
Solution 4 - JavaSachinKakkarView Answer on Stackoverflow
Solution 5 - JavagstackoverflowView Answer on Stackoverflow