How to disable flyway in a particular Spring profile?
Asked Answered
I

5

88

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

Invest answered 31/5, 2017 at 14:43 Comment(0)
I
76

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.

Insertion answered 31/5, 2017 at 15:58 Comment(1)
If you just need the flyway not to swear that some migrations are not applied, you can use spring.flyway.out-of-order = trueHarley
L
209

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.

Laurasia answered 15/12, 2017 at 17:38 Comment(6)
this doesn't go under spring. flyway: enabled: falseGalactic
Sorry, I don't follow your comment.Laurasia
@Invest See update, I added some commentary and a link on how to apply properties to specific profiles.Laurasia
Glad it helped @InvestLaurasia
alternatively, the following is perfectly valid in application.yml: spring.flyway.enabled: false. If it does not work, try putting 'false' in quotes...Meed
I had to add to spring.flyway.enabled and flyway.enabled to jvm parameters for this to work. Not both are required, whatever works for you.Getupandgo
I
76

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.

Insertion answered 31/5, 2017 at 15:58 Comment(1)
If you just need the flyway not to swear that some migrations are not applied, you can use spring.flyway.out-of-order = trueHarley
Q
8

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.
Quarrier answered 9/11, 2018 at 4:13 Comment(0)
F
1

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

Forlorn answered 2/7, 2021 at 14:40 Comment(0)
I
-1

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
  ....
Invest answered 11/11, 2018 at 21:6 Comment(3)
not really. docs.spring.io/spring-boot/docs/current/reference/html/… what you are looking for is spring.profiles: "enable_flyway_profile" the active property is to define which profile is activeWeisbart
@Weisbart it might be surprise for you but that code works in production sucessfullyInvest
oh okay, good to know! i prefer the way you wrote it too :) more explicitWeisbart

© 2022 - 2024 — McMap. All rights reserved.