84

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

gstackoverflow
  • 36,709
  • 117
  • 359
  • 710

5 Answers5

197

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.

Todd
  • 30,472
  • 11
  • 81
  • 89
75

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.

S. Pauk
  • 5,208
  • 4
  • 31
  • 41
Stanislav
  • 27,441
  • 9
  • 87
  • 82
  • If you just need the flyway not to swear that some migrations are not applied, you can use spring.flyway.out-of-order = true – roma2341 Jul 08 '21 at 11:28
7

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.
Jonathan JOhx
  • 5,784
  • 2
  • 17
  • 33
0

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

SachinKakkar
  • 65
  • 2
  • 10
-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
  ....
gstackoverflow
  • 36,709
  • 117
  • 359
  • 710
  • not really. https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-profiles.html what you are looking for is `spring.profiles: "enable_flyway_profile"` the `active` property is to define which profile is active – TecHunter Feb 18 '19 at 15:31
  • 1
    @TecHunter it might be surprise for you but that code works in production sucessfully – gstackoverflow Mar 18 '19 at 09:52
  • oh okay, good to know! i prefer the way you wrote it too :) more explicit – TecHunter Mar 18 '19 at 18:45