sada-dream / sada-dream_server_v2

개인간 해외 직구 중계 플랫폼 사다드림입니다.
MIT License
0 stars 0 forks source link

JPA가 만들어내는 DDL은 신뢰할 수 없는 문제 #67

Open dongwooklee96 opened 3 years ago

dongwooklee96 commented 3 years ago

https://www.inflearn.com/questions/17359

KIMHWANSEUNG commented 3 years ago

해당 이슈는 다음과 같이 해결할 수 있다.

구현체로 Hibernate를 사용하기 때문에 spring.jpa.hibernate.ddl-auto 옵션을 통해서 보다 상세한 데이터베이스 초기화 전략을 설정할 수 있다.

다음 목록중 하나를 spring.jpa.hibernate.ddl-auto 옵션의 값으로 지정할 수 있다.

위 초기화 전략을 기반으로 문제점을 해결 할 수 있을것 같다.

참고 자료 : https://pravusid.kr/java/2018/10/10/spring-database-initialization.html

dongwooklee96 commented 3 years ago

@KIMHWANSEUNG 그렇다면, 배포 환경에 따라서 spring.jpa.hibernate.ddl-auto 설정 값이 달라지도록 설정하면 좋을 것 같습니다.

KIMHWANSEUNG commented 3 years ago

@dongwooklee96 해결방법은 spring.profiles.active를 활용하면 됩니다.

application.yml에 devprod 환경을 각각 코드로 써놓고 ---로 나누며 직접적으로 프로젝트에 적용할 환경을 코드에서spring.profiles.active= {$적용할 환경} 으로 선언하여 설정하면 됩니다.

KIMHWANSEUNG commented 3 years ago

예시로 아래와 같이 코드를 쓰면 될것 같습니다 !

spring:
  profiles:
    active: dev

---
spring:
  profiles: dev
  datasource:
    hikari:
      maximum-pool-size: 4
    url: jdbc:postgresql://localhost:5432/postgres
    username: postgres
    password: pass
    platform: postgres
  jpa:
    hibernate:
      ddl-auto: update
    properties:
      hibernate:
        default_schema: db

jwt:
  secret: "12345678901234567890123456789010"

---
spring:
  profiles: PROD
  datasource:
    hikari:
      maximum-pool-size: 4
    url: jdbc:postgresql://localhost:5432/postgres
    username: postgres
    password: pass
    platform: postgres
  jpa:
    hibernate:
      ddl-auto: none
    properties:
      hibernate:
        default_schema: db

jwt:
  secret: "12345678901234567890123456789010"
dongwooklee96 commented 3 years ago

예시로 아래와 같이 코드를 쓰면 될것 같습니다 !


spring:
  profiles:
    active: dev

---

@KIMHWANSEUNG 환경변수를 위에 주입할 수 있는지 조사해주세요

dongwooklee96 commented 3 years ago

https://leveloper.tistory.com/38