[MAVEN] Carbon Five Database migration 플러그인
Carbon Five Database migration 플러그인
- 레퍼런스
1. 최초 세팅
- 기존에 database 가 존재했었다면
. db-migration:new 로 src/main/db/migrations 폴더에 ***.sql 파일 생성
. database를 sql 형태로 export 하여 백업.
. 해당 database drop (수동으로 drop 시켜줘야함. 안그러면 Can't create database 'db_event_dev'; database exists 와 같은 에러발생
. export한 쿼리를 ***.sql 파일에 복사한 후 저장
. db-migration:create 실행 -> database 생성 확인. 플러그인 설정시 세팅해준 데이터베이스만 생성되어있음.
. db-migration:migrate 실행
- 기존에 database 가 존재하지 않았다면
. db-migration:new 로 src/main/db/migrations 폴더에 ***.sql 파일 생성
. ***.sql 파일에 스키마 쿼리 작성 후 저장
. db-migration:create 실행 -> database 생성 확인. 플러그인 설정시 세팅해준 데이터베이스만 생성되어있음.
. db-migration:migrate 실행
2. 스키마 변경 후
. db-migration:new 를 실행하여 새로운 *****.sql 생성
. *****.sql에 변경할 쿼리 작성
. db-migration:migrate 실행
. 변경사항 확인
tip)
db-migration:new 을 실행시 -Dname=[suffix] 와 같이 뒤에 붙여주면
파일명이 ***_[suffix].sql과 같이 생성된다.
- pom.xml setting
<project>
[...]
<pluginRepositories>
<pluginRepository>
<id>c5-public-repository</id>
</pluginRepository>
</pluginRepositories>
</project>
<plugin> <groupId>com.carbonfive.db-support</groupId> <artifactId>db-migration-maven-plugin</artifactId> <version>[버전적어줘야함.]</version> <configuration> <url>jdbc:mysql://localhost/myapp_test</url> <username>dev</username> <password>dev</password> </configuration> <dependencies> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>5.1.6</version> </dependency> </dependencies> </plugin> |
- 레퍼런스
- Key Maven Plugin Goals
Goal Description
db-migration:create Create a new, empty database
db-migration:migrate Apply all pending migrations
db-migration:reset Drop the existing database, create a new one, and apply all pending migrations
db-migration:new Create a new, empty migration script
db-migration:check Check for pending migrations, fail the build if the db is not up to date
Goal Description
db-migration:create Create a new, empty database
db-migration:migrate Apply all pending migrations
db-migration:reset Drop the existing database, create a new one, and apply all pending migrations
db-migration:new Create a new, empty migration script
db-migration:check Check for pending migrations, fail the build if the db is not up to date
- 사용법
1. 최초 세팅
- 기존에 database 가 존재했었다면
. db-migration:new 로 src/main/db/migrations 폴더에 ***.sql 파일 생성
. database를 sql 형태로 export 하여 백업.
. 해당 database drop (수동으로 drop 시켜줘야함. 안그러면 Can't create database 'db_event_dev'; database exists 와 같은 에러발생
. export한 쿼리를 ***.sql 파일에 복사한 후 저장
. db-migration:create 실행 -> database 생성 확인. 플러그인 설정시 세팅해준 데이터베이스만 생성되어있음.
. db-migration:migrate 실행
- 기존에 database 가 존재하지 않았다면
. db-migration:new 로 src/main/db/migrations 폴더에 ***.sql 파일 생성
. ***.sql 파일에 스키마 쿼리 작성 후 저장
. db-migration:create 실행 -> database 생성 확인. 플러그인 설정시 세팅해준 데이터베이스만 생성되어있음.
. db-migration:migrate 실행
2. 스키마 변경 후
. db-migration:new 를 실행하여 새로운 *****.sql 생성
. *****.sql에 변경할 쿼리 작성
. db-migration:migrate 실행
. 변경사항 확인
tip)
db-migration:new 을 실행시 -Dname=[suffix] 와 같이 뒤에 붙여주면
파일명이 ***_[suffix].sql과 같이 생성된다.
todo) 한글깨짐. -> 방법을 찾아봐야되듯.
댓글
댓글 쓰기