12일차
오늘은 Part2. 게시판 서비스 강의의 `데이터베이스 접근 로직 테스트 정의1` 부분을 학습하였다.
데이터베이스 접근 로직 테스트 정의에서는 도메인 설계 내용을 바탕으로 DB와 연동하기 위한 방법을 구상하고, 세팅을 하고, 테스트를 작성한다.
먼저, 데이터베이스를 선택할 때 여러가지 판단 기준을 가지고 선택해야하는데 어떤 데이터베이스가 가장 많이 쓰이는지도 기준이 될 수 있다.
https://db-engines.com/en/
DB-Engines - Knowledge Base of Relational and NoSQL Database Management Systems
DB-Engines DB-Engines is an initiative to collect and present information on database management systems (DBMS). In addition to established relational DBMS, systems and concepts of the growing NoSQL area are emphasized. The DB-Engines Ranking is a list of
db-engines.com
위 사이트에서 데이터베이스 사용 순위를 볼 수 있다. 현재 1위는 Oracle, 2위는 MySQL, 3위는 Microsoft SQL Server 이다. 1 2 3위가 모두 관계형 모델이었다. 이번 게시판 프로젝트에서는 데이터베이스를 MySQL로 선택하였다.
Workbench를 따로 설치하지 않고, IntelliJ 내에서 DB를 다루기 위해서 IntelliJ에 내장되어 있는 기능을 사용할 수 있다. 아마도 유료 버전에만 있는 기능같다. 연동 방법은 구글에 검색하면 많이 나온다!
데이터베이스 환경을 셋팅하고 다음으로 게시판 테이블을 생성하고, 계정을 생성하고 게시판 테이블에 대한 권한을 주었다. 쿼리는 다음과 같이 짰다.
create database board;
create user 'sarang'@'localhost' indentified by 'testpw';
select `user` from `mysql`.`user`;
show grants for 'sarang'@'localhost';
grant all on `board`.* to 'sarang'@'localhost' with grant option;
프로젝트에서 JPA와 데이터베이스를 사용하기 위해서 build.gradle에 JPA와 Mysql 드라이버, H2 Database 의존성을 추가해주었다.
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
runtimeOnly 'com.h2database:h2'
runtimeOnly 'mysql:mysql-connector-java'