사용자 도구

사이트 도구


java:database:migration:flyway

차이

문서의 선택한 두 판 사이의 차이를 보여줍니다.

차이 보기로 링크

양쪽 이전 판 이전 판
다음 판
이전 판
java:database:migration:flyway [2018/07/31 14:14]
kwon37xi [config 파일 이용]
java:database:migration:flyway [2023/06/08 10:20] (현재)
kwon37xi [migration history는 생성됐으나 success = 0]
줄 19: 줄 19:
     configFiles = ['/path/to/file']     configFiles = ['/path/to/file']
 } }
-// 이 얘기는 공통 설정 파일나와, 프로필별 접속 정보 설정파일을 따로 두고 아래 처럼 할 수도 있다는 얘기+// 이 얘기는 공통 설정 프로필은 gradle에 지정고 프로필별 접속 정보 설정파일을 따로 두고 아래 처럼 할 수도 있다는 얘기
 flyway { flyway {
-    configFiles = ['/path/to/common.config','/path/to/profile.config']+    driver = 'org.mariadb.jdbc.Driver' 
 +    locations = ["filesystem:${file('src/migrations').absolutePath}"
 +    encoding = 'UTF-8' 
 +    // .... 
 +    configFiles = ['/path/to/profile.config'
 +
 + 
 +// 혹은 -Pprofile=local 형태로 프로필을 지정하고 
 +flyway { 
 +    driver = 'org.mariadb.jdbc.Driver' 
 +    // ... 
 +    configFiles = ["${file('src/migrations/confs/flyway-'profile + '.conf').absolutePath}"]
 } }
 </code> </code>
줄 87: 줄 98:
         enabled: false         enabled: false
 </code> </code>
 +  * 가급적 **''spring.flyway.enabled: false''**로 항상 끄자.
  
 ===== Version Number ===== ===== Version Number =====
줄 93: 줄 105:
     * ''outOfOrder = true'' Migration 시에 숫자 증분을 하지 않아도 되게 한다.     * ''outOfOrder = true'' Migration 시에 숫자 증분을 하지 않아도 되게 한다.
   * [[https://plugins.jetbrains.com/plugin/8597-flyway-migration-creation|Flyway Migration Creation]] IntelliJ IDEA 플러그인으로 쉽게 마이그레이션을 생성할 수 있다.   * [[https://plugins.jetbrains.com/plugin/8597-flyway-migration-creation|Flyway Migration Creation]] IntelliJ IDEA 플러그인으로 쉽게 마이그레이션을 생성할 수 있다.
 +
 +===== SpringBoot & Flyway =====
 +  * [[springframework:springboot|SpringBoot]]의 ''spring.flyway.enabled=true''가 기본값이다. 이 때문에 실수로 ''spring.flyway.enabled'' 값을 지정을 안해도 무조건 작동하게 된다. production DB에서도 작동할 경우 DB 날리는 일이 된다.
 +  * 따라서 SpringBoot application에서는 아예 flyway 에 대한 의존성을 걸지 않는 것을 추천한다.
 +
 +===== 특정 migration 실패 대응 =====
 +migration 을 실행했으나, 이미 누군가가 수동으로 마이그레이션을 진행한 상황이라서 migration history 가 실패했거나 존재하지않는 상황일 때 대응하는 방법
 +
 +==== migration history는 생성됐으나 success = 0 ====
 +<code sql>
 +-- 먼저 데이터 확인
 +select * from flyway_schema_history WHERE version = <실패한MIGRATION버전>;
 +
 +-- 성공으로 강제 update
 +update flyway_schema_history SET success = 1 WHERE version = <실패한MIGRATION버전>;
 +</code>
 +
 +==== migration history 자체가 생성이 안 됨 ====
 +  * migration history 가 생성이 안 됐다면, local DB 등에서 migration 을 전체 실행하고 실패한 version 관련 정보를 강제로 넣어준다.
 +
 +<code sql>
 +-- MySQL 기준임.
 +-- local db 에서
 +select concat(
 +    'SET @max_rank = (select MAX(installed_rank) from flyway_schema_history);\n',
 +    'INSERT INTO flyway_schema_history ',
 +    'SET',
 +    ' installed_rank = @max_rank + 1',
 +    ', version = ', fsh.version,
 +    ', description = ''', fsh.description, '''',
 +    ', type = ''', fsh.type, '''',
 +    ', script = ''', fsh.script, '''',
 +    ', checksum = ''', fsh.checksum, '''',
 +    ', installed_by = CURRENT_USER()',
 +    ', installed_on = now()',
 +    ', execution_time = ', fsh.execution_time,
 +    ', success = ', fsh.success,
 +    ';')
 +from flyway_schema_history fsh where version = <실패한MIGRATION버전>;
 + 
 +-- 실제 flyway를 적용할 DB에서 위 쿼리를 실행해서 나온 SQL 문을 실행해주면 된다.
 +</code>
 +
 +==== migration history 자체가 생성이 안 됨 - skipExecutingMigrations ====
 +  * [[https://flywaydb.org/documentation/configuration/parameters/skipExecutingMigrations#configuration-file|flyway.skipExecutingMigrations - Skip Executing Migrations - Flyway by Redgate • Database Migrations Made Easy.]]
 +  * [[https://flywaydb.org/blog/skipexecutingmigrations|Skip Executing Migrations Examples - Flyway]]
 +  * 마이그레이션을 누군가 수동으로 진행했을 때 마이그레이션을 실행하지 않고, 빠져있는 migration history 만 채워넣는다.
 +  * 유료버전 기능.
 +
 +<code gradle>
 +flyway {
 +    skipExecutingMigrations = true
 +}
 +</code>
 +  * 이 기능을 사용할 수 없으면, local 에서 실행한 history 를 그대로 복사해서 넣거나 해야한다.
 +
 +
java/database/migration/flyway.1533014090.txt.gz · 마지막으로 수정됨: 2018/07/31 14:14 저자 kwon37xi