Skip to content

7.4. Flyway 설정

7.4.1. application.yml

yaml
spring:
  flyway:
    enabled: true
    locations: classpath:db/migration
    baseline-on-migrate: false
    validate-on-migrate: true
    out-of-order: false
설정설명
enabledtrueFlyway 자동 실행 활성화
locationsclasspath:db/migration마이그레이션 파일 위치
baseline-on-migratefalse기존 DB에 baseline 자동 적용 비활성화
validate-on-migratetrue마이그레이션 파일 무결성 검증
out-of-orderfalse순서를 벗어난 마이그레이션 금지

7.4.2. 프로파일별 설정

yaml
# application-local.yml
spring:
  flyway:
    clean-disabled: false    # 로컬에서만 clean 허용
yaml
# application-prod.yml
spring:
  flyway:
    clean-disabled: true     # 프로덕션에서 clean 절대 금지
    baseline-on-migrate: false

필수

프로덕션 환경에서 flyway:clean절대 실행하면 안 됩니다. clean-disabled: true를 반드시 설정합니다.

7.4.3. Maven 플러그인

CI/CD에서 마이그레이션을 독립적으로 실행하거나, jOOQ codegen 전에 스키마를 적용할 때 사용합니다.

xml
<plugin>
  <groupId>org.flywaydb</groupId>
  <artifactId>flyway-maven-plugin</artifactId>
  <configuration>
    <url>jdbc:postgresql://localhost:5432/flowin</url>
    <user>flowin</user>
    <password>flowin1234</password>
    <locations>
      <location>filesystem:src/main/resources/db/migration</location>
    </locations>
  </configuration>
  <dependencies>
    <dependency>
      <groupId>org.postgresql</groupId>
      <artifactId>postgresql</artifactId>
      <version>${postgresql.version}</version>
    </dependency>
    <dependency>
      <groupId>org.flywaydb</groupId>
      <artifactId>flyway-database-postgresql</artifactId>
      <version>${flyway.version}</version>
    </dependency>
  </dependencies>
</plugin>
bash
# 마이그레이션 실행
mvn flyway:migrate

# 마이그레이션 상태 확인
mvn flyway:info

# 마이그레이션 검증
mvn flyway:validate

TIENIPIA QUALIFIED STANDARD