Skip to content
Advertisement

Flyway did not create tables

I have been trying to create a web application using spring boot and flyway. The build tool is Gradle. However, when I try to run the program Flyway creates just one table named flyway_schema_hystory but doesn’t create a table from SQL script. Script V1__Create_all_tables.sql is on correct package src/main/resources/db/migration. Dependency in build.gradle was added, flyway properties were added in app.properties as well. Spring boot runs without errors.

build.gradle dependencies

dependencies {
    testImplementation 'org.junit.jupiter:junit-jupiter-api:5.6.0'
    testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine'

    compileOnly 'org.projectlombok:lombok:1.18.16'
    annotationProcessor 'org.projectlombok:lombok:1.18.16'

    compile group: 'org.springframework.boot', name: 'spring-boot', version: '2.4.2'
    compile group: 'org.springframework.boot', name: 'spring-boot-starter-data-jpa', version: '2.4.2'
    compile group: 'org.springframework.boot', name: 'spring-boot-starter-jdbc', version: '2.4.2'
    compile group: 'org.springframework.boot', name: 'spring-boot-starter-web', version: '2.4.2'

    annotationProcessor('org.hibernate:hibernate-jpamodelgen:6.0.0.Alpha5')

    compile group: 'org.postgresql', name: 'postgresql', version: '42.2.18'

    compile group: 'org.flywaydb', name: 'flyway-core', version: '7.5.3'
}

app.properties

#Databse
spring.jpa.database-platform=org.hibernate.dialect.PostgreSQLDialect
spring.datasource.driver-class-name=org.postgresql.Driver
spring.datasource.url=jdbc:postgresql://localhost:5432/db_mydatabase
spring.datasource.username=postgres
spring.datasource.password=***
spring.jpa.generate-ddl=false
spring.jpa.hibernate.ddl-auto=none

#Flyway
spring.flyway.baselineOnMigrate=true
spring.flyway.check-location=true
spring.flyway.locations=classpath:db/migration
spring.flyway.schemas=public
spring.flyway.enabled=true

Example of sql script for creating a table (I’m using postgresql):

create table my_table (
                       id serial not null constraint cover_pkey primary key,
                       name varchar(30) not null ,
                       is_deleted boolean not null
);

flyway_schema_hystory

What’s can be a problem?

Advertisement

Answer

Try changing the name, I think v1 is reserved for the flyway’s initial migration. Try something like V1_1__create_all_tables.sql

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement