From ec8f49ea004582a87bc5e7e5e38b7fa601a6e38c Mon Sep 17 00:00:00 2001 From: KamilM1205 Date: Sun, 29 Jun 2025 21:05:03 +0400 Subject: [PATCH] Added: migrations Fix: removed password field from entity and dto. --- build.gradle.kts | 72 +++++++++++-------- .../ProfileserviceApplication.java | 6 +- .../controller/schemes/CreateUserRequest.java | 1 - .../persistence/entity/UserEntity.java | 7 +- .../profileservice/service/UserDTO.java | 1 - src/main/resources/application.properties | 8 ++- .../db/migration/V1_0_0__CreateUser.sql | 7 ++ 7 files changed, 61 insertions(+), 41 deletions(-) create mode 100644 src/main/resources/db/migration/V1_0_0__CreateUser.sql diff --git a/build.gradle.kts b/build.gradle.kts index 74dc88a..5a31b41 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,49 +1,63 @@ plugins { - java - id("org.springframework.boot") version "3.5.3" - id("io.spring.dependency-management") version "1.1.7" + java + id("org.springframework.boot") version "3.5.3" + id("io.spring.dependency-management") version "1.1.7" + id("org.flywaydb.flyway") version "11.10.0" } group = "ru.team58" version = "0.0.1-SNAPSHOT" +flyway { + url = "jdbc:postgresql://localhost:5432/userdb" + user = "userdb" + password = "1205" + driver = "org.postgresql.Driver" +} + java { - toolchain { - languageVersion = JavaLanguageVersion.of(17) - } + toolchain { + languageVersion = JavaLanguageVersion.of(17) + } } configurations { - compileOnly { - extendsFrom(configurations.annotationProcessor.get()) - } + compileOnly { + extendsFrom(configurations.annotationProcessor.get()) + } } repositories { - mavenCentral() + mavenCentral() +} + +buildscript { + dependencies { + classpath("org.flywaydb:flyway-database-postgresql:11.10.0") + } } dependencies { - implementation("org.springframework.boot:spring-boot-starter-data-jpa") - implementation("org.springframework.boot:spring-boot-starter-security") - implementation("org.springframework.boot:spring-boot-starter-web") - implementation("org.flywaydb:flyway-core") - implementation("org.mapstruct:mapstruct:1.6.3") - implementation("org.postgresql:postgresql") - implementation("org.flywaydb:flyway-database-postgresql") - implementation("org.apache.logging.log4j:log4j-api:2.22.1") - implementation("org.apache.logging.log4j:log4j-core:2.22.1") - implementation("org.slf4j:slf4j-api:2.0.13") - implementation("org.springdoc:springdoc-openapi-starter-webmvc-ui:2.8.6") - runtimeOnly("org.apache.logging.log4j:log4j-slf4j-impl:2.22.1") - annotationProcessor("org.mapstruct:mapstruct-processor:1.6.3") - compileOnly("org.projectlombok:lombok") - annotationProcessor("org.projectlombok:lombok") - testImplementation("org.springframework.boot:spring-boot-starter-test") - testImplementation("org.springframework.security:spring-security-test") - testRuntimeOnly("org.junit.platform:junit-platform-launcher") + implementation("org.springframework.boot:spring-boot-starter-data-jpa") + implementation("org.springframework.boot:spring-boot-starter-security") + implementation("org.springframework.boot:spring-boot-starter-web") + implementation("org.flywaydb:flyway-core") + implementation("org.flywaydb:flyway-database-postgresql:11.10.0") + implementation("org.mapstruct:mapstruct:1.6.3") + implementation("org.postgresql:postgresql") + implementation("org.apache.logging.log4j:log4j-api:2.22.1") + implementation("org.apache.logging.log4j:log4j-core:2.22.1") + implementation("org.slf4j:slf4j-api:2.0.13") + implementation("org.springdoc:springdoc-openapi-starter-webmvc-ui:2.8.6") + runtimeOnly("org.apache.logging.log4j:log4j-slf4j-impl:2.22.1") + annotationProcessor("org.mapstruct:mapstruct-processor:1.6.3") + compileOnly("org.projectlombok:lombok") + annotationProcessor("org.projectlombok:lombok") + testImplementation("org.springframework.boot:spring-boot-starter-test") + testImplementation("org.springframework.security:spring-security-test") + testRuntimeOnly("org.junit.platform:junit-platform-launcher") } tasks.withType { - useJUnitPlatform() + useJUnitPlatform() } diff --git a/src/main/java/ru/team58/profileservice/ProfileserviceApplication.java b/src/main/java/ru/team58/profileservice/ProfileserviceApplication.java index b997433..eb1924b 100644 --- a/src/main/java/ru/team58/profileservice/ProfileserviceApplication.java +++ b/src/main/java/ru/team58/profileservice/ProfileserviceApplication.java @@ -1,7 +1,6 @@ package ru.team58.profileservice; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import lombok.extern.slf4j.Slf4j; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration; @@ -9,9 +8,8 @@ import org.springframework.data.jpa.repository.config.EnableJpaRepositories; @SpringBootApplication(exclude = { SecurityAutoConfiguration.class }) @EnableJpaRepositories +@Slf4j public class ProfileserviceApplication { - private static final Logger log = LoggerFactory.getLogger(ProfileserviceApplication.class); - public static void main(String[] args) { SpringApplication.run(ProfileserviceApplication.class, args); } diff --git a/src/main/java/ru/team58/profileservice/controller/schemes/CreateUserRequest.java b/src/main/java/ru/team58/profileservice/controller/schemes/CreateUserRequest.java index e809b58..9205b1d 100644 --- a/src/main/java/ru/team58/profileservice/controller/schemes/CreateUserRequest.java +++ b/src/main/java/ru/team58/profileservice/controller/schemes/CreateUserRequest.java @@ -5,5 +5,4 @@ public class CreateUserRequest { String firstName; String lastName; String email; - String hashedPassword; } diff --git a/src/main/java/ru/team58/profileservice/persistence/entity/UserEntity.java b/src/main/java/ru/team58/profileservice/persistence/entity/UserEntity.java index 15f940c..62c3236 100644 --- a/src/main/java/ru/team58/profileservice/persistence/entity/UserEntity.java +++ b/src/main/java/ru/team58/profileservice/persistence/entity/UserEntity.java @@ -7,7 +7,7 @@ import ru.team58.profileservice.service.UserDTO; import java.util.UUID; @Entity -@Table(name = "user") +@Table(name = "users") @NoArgsConstructor @AllArgsConstructor @Builder @@ -22,7 +22,7 @@ public class UserEntity { @Column(name = "username", nullable = false) String username; - @Column(name = "firstname", nullable = false) + @Column(name = "firstName", nullable = false) String firstName; @Column(name = "lastName", nullable = false) @@ -30,7 +30,4 @@ public class UserEntity { @Column(name = "email", nullable = false) String email; - - @Column(name = "hashed_password", nullable = false) - String hashed_password; } diff --git a/src/main/java/ru/team58/profileservice/service/UserDTO.java b/src/main/java/ru/team58/profileservice/service/UserDTO.java index 952d4c9..d0834f6 100644 --- a/src/main/java/ru/team58/profileservice/service/UserDTO.java +++ b/src/main/java/ru/team58/profileservice/service/UserDTO.java @@ -20,5 +20,4 @@ public class UserDTO { String firstName; String lastName; String email; - String hashedPassword; } \ No newline at end of file diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index efdb856..294cc22 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -3,4 +3,10 @@ spring.application.name=profileservice ## PostgreSQL spring.datasource.url=jdbc:postgresql://localhost:5432/userdb spring.datasource.username=userdb -spring.datasource.password=1205 \ No newline at end of file +spring.datasource.password=1205 + +spring.jpa.hibernate.ddl-auto=update + +## Flyway +spring.flyway.enabled=true +spring.flyway.locations=classpath:db.migration \ No newline at end of file diff --git a/src/main/resources/db/migration/V1_0_0__CreateUser.sql b/src/main/resources/db/migration/V1_0_0__CreateUser.sql new file mode 100644 index 0000000..aa8091d --- /dev/null +++ b/src/main/resources/db/migration/V1_0_0__CreateUser.sql @@ -0,0 +1,7 @@ +CREATE TABLE IF NOT EXISTS "users" ( + "id" uuid PRIMARY KEY, + "username" varchar, + "firstName" varchar, + "lastName" varchar, + "email" varchar +); \ No newline at end of file