2020년 4월 16일

Docker 기반 Schemaspy 를 이용한 ERD 생성하기

웹 개발에 있어 별도의 엔터티 관계 다이어그램 (이하, ERD) 생성 도구가 없는 경우 데이터베이스 테이블의 관계를 확인하기 어려움이 있다. 직접 데이터베이스 도구를 통하여 확인할 수 도 있지만 오픈소스 Schemaspy 를 사용하여 쉽게 데이터베이스 ERD 을 생성할 수 있다.

Docker Desktop


Schemaspy 를 Docker 컨테이너에서 실행할 예정이기 때문에 Docker 를 설치한다. 설치 절차는 아래와 같다.

  1. Get Started with Docker 사이트 방문 (그림1) 
  2. Docker Desktop installer 다운로드, dmg 파일을 더블 클릭하여 설치 프로그램을 실행하고 설명과 같이 Drag&Drop 하여 프로그램을  설치.(그림2) 
  3. 마지막으로 Docker 프로그램을 실행하고 최초 권한을 부여하면 설치 완료.

그림 1. Docker 설치 파일 다운로드 


그림2. macOS 에 Docker Desktop 설치


Docker 를 사용할 준비가 되었으며 터미널에서 간단하게 아래 명령을 입력하여 버전을 확인해 볼 수 있다.

docker --version


Schemaspy

아래 명령으로 최신 Docke Schemaspy 이미지를 가져온다.

docker pull schemaspy/schemaspy

다음으로 schemaspy.properties  설정을 아래와 같이 만든다. 
참고로 다음과 같은 환경에 따른 설정이다. 
  • Database : Mysql
  • Mysql JDBC driver : /my_project/schema/jdbc/mysql-connector-java-8.0.16.jar
  • 설정 파일 : /my_project/schema/schemaspy.properties 
  • 레포트 생성 위치 : /my_project/schema/output
☛ Schemaspy docker image 는 mysql 드라이버를 포함하고 있지만 8.x 버전 mysql 연결시 아래와 같은 오류가 있어 JDBC 드라이버를 지정하여 사용하였다.

Thu Apr 16 04:50:50 GMT 2020 WARN: Establishing SSL connection without server's identity verification is not recommended.
According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set.
For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'.
You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification. 


☛ Schemaspy는 Docker 컨테이너에서 동작하기 때문에 schemaspy.properties 설정에서 로컬 자원을 직접 접근할 수 없다.  이런 이유에서 schemaspy.dp, schemaspy.o 설정을 사용하지 않고 Docker 실행시에 자원을 지정해주었다.

schemaspy.properties
schemaspy.t=mysql
#optional path to alternative jdbc drivers. 
#schemaspy.dp=
# database properties: host, port number, name user, password
schemaspy.host=xxx.xxx.xx.xxx
schemaspy.port=3306
schemaspy.db=studiodb
schemaspy.u=test
schemaspy.p=test
# output dir to save generated files
# schemaspy.o=
# db scheme for which generate diagrams
schemaspy.s=studiodb
# Uncoment to generate diagrams for all schemas in database
#schemaspy.all
# Uncoment to skip creating diagrams for views
#schemaspy.noviews

마지막으로 Docker Schmaspy 이미지를 아래와 같이 실행하여 데이터베이스 ERD 레포트를 생성한다.
  
docker run -v "/my_project/schema/schemaspy.properties:/schemaspy.properties" 
-v "/my_project/schema/jdbc:/drivers"  
-v "/my_project/schema/output:/output" 
schemaspy/schemaspy

그림 3. 생성된 ERD

댓글 없음:

댓글 쓰기