How to disable flyway in a certain spring profile?

spring flyway
spring boot flyway properties
flyway disable migration
spring.flyway.enabled not working
spring boot flyway not running
spring boot flyway java migration
flyway spring compatibility
flyway h2

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

This answer works with Spring Boot 1.X version. If you are looking for answer for Spring Boot 2.X, you should see the below answer.

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.

Disable Flyway on Spring Boot 2, flyway.enabled , and added that to my test application profile (as below). spring: datasource:  Sometimes we may need to disable Flyway migrations under certain circumstances. For example, it's a common practice to generate database schema based on the entities during tests. In such a situation, we can disable Flyway under the test profile. Let's see how easy it is in Spring Boot. 4.1. Spring Boot 1.x

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.

How to disable flyway in certain spring profile?, and don't use flyway. I tried smth to write like this in application.yaml spring: profiles: test jpa: generate-ddl: true hibernate: datasource:  When you use H2 for unit tests, Spring will automatically run the Flyway on H2 database when application starts. This approach will make sure your H2 database matches your application database. The recommended approach is to create two profiles in your application .yml file: one for development and one for testing, i.e.:

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

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

Add a way to disable running Flyway migrations automatically , I have a use case where I need to run Flyway migrations manually for testing. If I add flyway.enabled=false to application-test.properties,  Command-line: repair. Repairs the Flyway schema history table. This will perform the following actions: Remove any failed migrations on databases without DDL transactions (User objects left behind must still be cleaned up manually) Realign the checksums, descriptions and types of the applied migrations with the ones of the available migrations

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

Disable flyway in some spring profiles · Issue #2089 · flyway/flyway , I'm using flyway with spring boot, Is there a way to disable flyway in some spring profiles? I set spring.flyway.enable to false but doesn't work. Repair. Repairs the schema history table. Repair is your tool to fix issues with the schema history table. It has two main uses: Remove failed migration entries (only for databases that do NOT support DDL transactions) Realign the checksums, descriptions and types of the applied migrations with the ones of the available migrations; Command-line

Database Migrations with Flyway, I just announced the new Learn Spring course, focused on the Sometimes we may need to disable Flyway migrations under certain circumstances. In such a situation, we can disable Flyway under the test profile. Let's see  You can use flyway placeholder: Configure it on your enviroment config.properties: flyway.placeholders.tableName=MY_TABLE. flyway.placeholders.name='Mr. Test' Then, put it on your script: INSERT INTO ${tableName} (name) VALUES (${name}); I have used the flyway.locations too, but the placeholders is simpler than locations for simple changes.

“How-to” Guides - Project Metadata API Guide, spring.flyway.locations=classpath:db/ that can be used to disable the migrations or switch off the location checking. Also, you can use profile-specific configuration to  Spring Boot will automatically load the properties in an application.properties file for all profiles, and the ones in profile-specific .properties files only for the specified profile. For example, we can configure different data sources for dev and production profiles by using two files named application-dev.properties and application

Common Application properties - Project Metadata API Guide, Flag to explicitly request a specific type of web application. If not set Comma-​separated list of active profiles. spring.flyway.clean-disabled. Baseline is the flyway feature you need. If your case, baseline your database with flyway.baselineVersion=2 will tell flyway that your database is already at the version 2. Any subsequent flyway migrate will only process migrations greater than 2. Note: If previous migrations failed, it may be necessary to drop table flyway_schema_history first.

Comments
  • this doesn't go under spring. flyway: enabled: false
  • Sorry, I don't follow your comment.
  • @gstackoverflow See update, I added some commentary and a link on how to apply properties to specific profiles.
  • Glad it helped @gstackoverflow
  • alternatively, the following is perfectly valid in application.yml: spring.flyway.enabled: false. If it does not work, try putting 'false' in quotes...
  • 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 active
  • @TecHunter it might be surprise for you but that code works in production sucessfully
  • oh okay, good to know! i prefer the way you wrote it too :) more explicit