[스프링 부트] chapter 31. 스프링 데이터 7부 데이터베이스 초기화
스프링 데이터 7부 데이터베이스 초기화
JPA를 사용한 데이터베이스 초기화
- spring.jpa.hibernate.ddl-auto=
- update : 기존 스키마에 새롭게 추가된 부분을 업데이트 한다. (기존 것 유지)
- validate : 스키마에 있는 테이블과 Bean Factory에 올라갈 Entity를 비교하여 체크한다. (다른 부분이 있을 경우 오류)
- create-drop : 어플리케이션 기동시 스키마 생성, 종료시 삭제한다.
- create : 어플리케이션 기동시 테이블 삭제후 생성한다.
-
spring.jpa.generate-dll=true
- spring.jpa.show-sql=true ( sql문을 로그로 찍는다.)
SQL 스크립트를 사용한 데이터베이스 초기화
- schema.sql 또는 schema-${platform}.sql (resource에 생성)
drop table account if exists
drop sequence if exists hibernate_sequence
create sequence hibernate_sequence start with 1 increment by 1
create table account (id bigint not null, password varchar(255), username varchar(255), primary key (id))
-
data.sql 또는 data-${platform}.sql
-
${platform}값은 spring.datasource.platform으로 설정 가능