spring boot

bank app 19 - (마이그레이션)

alarim 2023. 4. 21. 11:04
학습 목표

1. migration 작업 이란
2 .yml 파일 수정하기
3. my sql 설정
마이그레이션이란 데이터베이스 스키마의 변경 내역을 버전 관리하여, 변경에 대한 이력을 남기고, 데이터베이스를 이전 버전에서 최신 버전으로 옮기는 일련에 과정들을 의미합니다. 즉, 일반적으로 마이그레이션은 스키마를 변경하거나 새로운 테이블이나 컬럼을 추가하는 등에 작업을 포함하고 따라서 우리가 할 작업 H2 데이터베이스에서 MySQL 로 변경할 때 도 마이그레이션을 수행 한다고 할 수 있습니다. 이러한 경우에 테이터 스키마를 변경하거나 데이터를 이전하는 작업등이 포함 될 수 있습니다.

 

이전 yml 설정 기록

server:
  port: 8080
  servlet:
    encoding:
      charset: utf-8
      force: true

      
      
spring:
  mvc:
    view:
      prefix: /WEB-INF/view/
      suffix: .jsp
  datasource:
    url: jdbc:h2:mem:testdb;MODE=MySQL
    driver-class-name: org.h2.Driver
    username: sa
    password: 
  sql:
    init:
      schema-locations:
      - classpath:db/table.sql
      data-locations:
      - classpath:db/data.sql
  
  h2:
    console:
      enabled: true
  output:
    ansi:
      enabled: always
      
      
mybatis:
  mapper-locations:
  - classpath:mapper/**.xml
  configuration:
    map-underscore-to-camel-case: true

 

수정한 yml

server:
  port: 8080
  servlet:
    encoding:
      charset: utf-8
      force: true

      
      
spring:
  mvc:
    view:
      prefix: /WEB-INF/view/
      suffix: .jsp
  datasource:
    url: jdbc:mysql://localhost:3306/bank2?serverTimezone=Asia/Seoul
    driver-class-name: com.mysql.cj.jdbc.Driver
    username: root
    password: 1234
#  sql:
#    init:
#      schema-locations:
#      - classpath:db/table.sql
#      data-locations:
#      - classpath:db/data.sql
  
#  h2:
#    console:
#      enabled: true
#  output:
#    ansi:
#      enabled: always
      
      
mybatis:
  mapper-locations:
  - classpath:mapper/**.xml
  configuration:
    map-underscore-to-camel-case: true

 

 

제거하고 커넥터 j 라이브러리가 정상 작동하도록 build.gradle에 추가해준다.

runtimeOnly 'com.h2database:h2'

 

dependencies {

	implementation 'org.apache.tomcat.embed:tomcat-embed-jasper'
	implementation 'javax.servlet:jstl'
	implementation 'org.mybatis.spring.boot:mybatis-spring-boot-starter:2.3.0'
	

	implementation 'org.springframework.boot:spring-boot-starter-web'
	compileOnly 'org.projectlombok:lombok'
	developmentOnly 'org.springframework.boot:spring-boot-devtools'
	annotationProcessor 'org.projectlombok:lombok'
	testImplementation 'org.springframework.boot:spring-boot-starter-test'
	
	// 커넥터 J
	runtimeOnly 'com.mysql:mysql-connerctor-j'
}