pbount
pbount

Reputation: 1803

Flyway - Cannot find migrations location in

I can't seem to let flyway know where to look for my migrations. My file structure is the default generated from spring initializr. My migrations are in: ./demo/src/main/kotlin/db/migration My migrations are java based

My application.properties file looks like this:

spring.datasource.driverClassName=org.postgresql.Driver
spring.jpa.database-platform=org.hibernate.dialect.PostgreSQLDialect
spring.datasource.url=jdbc:postgresql://${JDBC_DATABASE_URL}/jpaTestDatabase
spring.datasource.username=${JDBC_DATABASE_USERNAME}
spring.datasource.password=${JDBC_DATABASE_PASSWORD}

spring.flyway.baseline-on-migrate=true
spring.flyway.locations=classpath:demo/src/main/kotlin/db/migration

spring.jpa.generate-ddl=true
spring.jpa.hibernate.ddl-auto=validate
spring.session.store-type=none

I tried several classpaths:

/demo/src/main/kotlin/db/migration
demo/src/main/kotlin/db/migration
/src/main/kotlin/db/migration
src/main/kotlin/db/migration

None of the above seem to work.

How can I let flyway know where the migrations are?

Upvotes: 31

Views: 49392

Answers (13)

Nirodha
Nirodha

Reputation: 16

I got the same error with FlyWay and found that it was due to the incorrect path configuration inside. Added file path as follows in application.properties

spring.flyway.locations=filesystem:src/main/resources/db/migration/

Issue was resolved. File name convention used as __.sql (Ex - V1__init.sql)

Upvotes: 0

Rasul Akhmeddibirov
Rasul Akhmeddibirov

Reputation: 1

In my case, I am using a modular structure (hexagonal).

-> project
   └> api-rest
   └> application
   └> boot
      └> application.yaml (with flyway config)
   └> domain
   └> infrastructure
      └> db/migation

To specify the db/migration path from application.yaml I just need to add the following sentence.

flyway:
   locations: filesystem:.\infrastructure\src\main\resources\db\migration\

Pay attention in dot before \infrastructure. This will take a relative path from project root.

Upvotes: 0

Hao Feng
Hao Feng

Reputation: 61

I am on Mac M1 chip, and things are a little different. After numerous attempts, I found two methods to solve this issue.

Option 1, replace flyway.locations=filesystem: relative path with flyway.locations=filesystem: absolute path

Option 2, upgrade gradle from 6.8.1 to 7.3

Upvotes: 0

YOSEPH NOH
YOSEPH NOH

Reputation: 97

In case all of settings are default, try rebuild module.

Upvotes: 0

José Júnior
José Júnior

Reputation: 611

In my case the fix was in src/myFlywayConfig.conf file. I added the following line:

flyway.locations=filesystem:src/main/resources/db/migration

Upvotes: 2

PHA
PHA

Reputation: 21

Also make sure that your folder path is correct.

Mine was: src/main/resources/db.migration/...
instead of: src/main/resources/db/migration/...

I got the same error as migration files weren't retrieved.

Upvotes: 2

skyho
skyho

Reputation: 1903

    <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-r2dbc</artifactId>
        </dependency>
    <dependency>
            <groupId>org.flywaydb</groupId>
            <artifactId>flyway-core</artifactId>
            <version>9.16.1</version>
        </dependency>
database:
  url: postgresql://localhost:5433/db_name
spring:
  flyway:
    baseline-description: true
    baseline-on-migrate: true
    create-schemas: true
    default-schema: public
    enabled: true
    locations: classpath:db/migration
    password: ${spring.r2dbc.password}
    schemas: public
    url: jdbc:${database.url}
    user: ${spring.r2dbc.username}
    validate-on-migrate: true
  r2dbc:
    password: postgres
    url: r2dbc:postgresql://localhost:5433/db_name
    username: postgres
  • V2__create_car.sql (example)

Start numbering with V2, the script with V1 version is ignored. I don't understand why, but that's exactly how it works for me.

Upvotes: 0

Stanislau Listratsenka
Stanislau Listratsenka

Reputation: 690

in my case i had - (dash character) in the name of migration like V20220508-1900__init.sql. removing - fixed the problem

Upvotes: 0

Nestor Milyaev
Nestor Milyaev

Reputation: 6595

In my case, the trick was: once Flyway has succeeded in running the update script, it creates the table flyway_schema_history, that recorded that I have already run the create script successfully once.

I was playing back and forward with the implementation, changing spring.jpa.hibernate.ddl-auto to validate and then create-drop, and then back.

So, when I tried to run the script second time, that was rejected but since the originally created table (in my case called 'bike') was deleted when the app shut down when run in spring.jpa.hibernate.ddl-auto=create-drop mode previous time, I was getting the

SchemaManagementException: Schema-validation: missing table [bike] Exception.

Solution is: drop the flyway_schema_history table or remove the records corresponding to the previous run and roll again!

Upvotes: 1

Oleksandr.Bezhan
Oleksandr.Bezhan

Reputation: 2168

I had a different problem, my migration file name was V1_Base_version.sql instead of V1__Base_version.sql. Flyway requires double underscore __ in name prefix.

Upvotes: 52

Guido Orellana
Guido Orellana

Reputation: 41

you must agregate or uncomment the line flyway.locations with

flyway.localtions=filesystem:.

into flyway.conf configuration file.

Upvotes: 0

acdcjunior
acdcjunior

Reputation: 135832

In my case, I got that error message because I created the folders via copy-paste in the IDE (and not manually, as one usually does).

I actually had (which didn't work):

src/main/resources/db.migration/

instead of the correct (which worked):

src/main/resources/db/migration/

The db.migration version obviously does not work, but it is hard to spot on the IDE.

Upvotes: 63

Alien
Alien

Reputation: 15908

By default Flyway will look for migrations on the classpath under db/migration, which on a Maven project means src/main/resources/db/migration.

Ensure that you have directory like this.

Refer flyway-db-migration-folder

Upvotes: 25

Related Questions