I'm new to flyway and I'm trying to create a migration of my database. I created V1_1__CREATE_TABLES.sql
file in /resources/migrations
, and started the app, but it just doesn't works. I also fiend a lot of threads on this topic, but all the answers I senn was useless for me. So here you can see my code:
Here's my maven dependencies:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.7.4</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.diary</groupId>
<artifactId>diary</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>diary</name>
<description>School electronic diary</description>
<properties>
<java.version>17</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-oauth2-client</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-maven-plugin</artifactId>
<version>4.0.3</version>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<excludes>
<exclude>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
</project>
Here's application.properties
file
#spring
spring.datasource.url=jdbc:postgresql://localhost:5432/diary
spring.datasource.username=postgres
spring.datasource.password=4122
spring.jpa.hibernate.ddl-auto=update
spring.datasource.driver-class-name=org.postgresql.Driver
logging.level.org.hibernate.SQL=debug
logging.level.org.hibernate.type.descriptor.sql=trace
#flyway
spring.flyway.locations=classpath:migrations
spring.flyway.url=jdbc:postgresql://localhost:5432/diary
spring.flyway.user=postgres
spring.flyway.password=4122
spring.flyway.schemas=public
spring.flyway.enabled=true
And here's my sql file:
CREATE TABLE users (
id BIGINT NOT NULL,
login VARCHAR(255) NOT NULL ,
phoneNumber VARCHAR(16) NOT NULL,
email VARCHAR(255) NOT NULL,
name VARCHAR(255) NOT NULL,
surname VARCHAR(255) NOT NULL,
patronymic VARCHAR(255),
roleId BIGINT NOT NULL,
CONSTRAINT userRoles FOREIGN KEY (roleId) REFERENCES roles(id)
primary key (id)
);
CREATE TABLE roles (
id BIGINT NOT NULL,
name VARCHAR(255) NOT NULL,
primary key (id)
);
If you know what can be a problem, please, tell me, I'd really apreciate it!