Flyway의 "Migrations have failed validation"상세 내용 조사
12416 단어 Spring Bootflywaytech
개요
SpringBoot + Flyway 이벤트에서
Migrations have failed validation
오류가 발생하여 프로그램을 시작할 수 없습니다.스프링부트 로그에는 더 이상의 내용이 없어 조사가 어렵다.
이 응용 프로그램은 몇 가지 경관이 존재하지만 다른 환경에서는 이런 현상이 발생하지 않는다.
이 현상을 해결한 절차를 기록하다.
전제 조건
7.1.1
Amazon Linux 2
Flyway Command-line tool 다운로드
소스를 직접 편집할 수 없는 환경이므로 적절한 서버에서 다운로드
Flyway Command-line tool
했습니다.최신 버전은 다음 URL에서 다운로드할 수 있습니다.
하지만 이번에는 스프링부트가 사용하는 Version에 맞춰 마벤 센트럴 리포지토리에서 다운로드했다.
$ sudo amazon-linux-extras enable corretto8
$ sudo yum install java-1.8.0-amazon-corretto
$ wget https://repo1.maven.org/maven2/org/flywaydb/flyway-commandline/7.1.1/flyway-commandline-7.1.1-linux-x64.tar.gz
$ tar xvzf flyway-commandline-7.1.1-linux-x64.tar.gz
$ cd flyway-7.1.1
Flyway 설정
폴더는 다음과 같이 구성됩니다.
.
├── conf ← 設定ファイル
├── drivers
├── jars
├── jre
├── lib
├── licenses
└── sql ← migration sqlファイル
conf/flyway.conf
에 다음과 같은 내용을 보충한다.flyway.url=jdbc:postgresql://xxx/yyy
flyway.user=xxx_user
flyway.password=xxxxx
flyway.schemas=public
flyway.table=flyway_schema_history
또한 sql
폴더 아래에 이전된 파일을 설정합니다.이 상태에서
flyway info
를 실행하면 현재 상황을 확인할 수 있습니다.[ec2-user@xxx flyway-7.1.1]$ ./flyway info
Flyway Community Edition 7.1.1 by Redgate
Database: jdbc:postgresql://jdbc:postgresql://xxx/yyy (PostgreSQL 13.3)
Schema version: 1.01
+-----------+---------+-------------------+------+---------------------+---------+
| Category | Version | Description | Type | Installed On | State |
+-----------+---------+-------------------+------+---------------------+---------+
| Versioned | 1.00 | table init | SQL | 2021-10-12 15:41:34 | Success |
| Versioned | 1.01 | reformat_password | SQL | 2021-10-19 11:33:38 | Success |
| Versioned | 1.02 | fix field length | SQL | | Pending |
+-----------+---------+-------------------+------+---------------------+---------+
migrate 실행
이 상태에서migrate를 실행합니다.
[ec2-user@xxx flyway-7.1.1]$ ./flyway migrate
Flyway Community Edition 7.1.1 by Redgate
Database: jdbc:postgresql://jdbc:postgresql://xxx/yyy (PostgreSQL 13.3)
ERROR: Validate failed: Migrations have failed validation
SpringBoot의 로그에서 내보낸 것과 동일한 메시지를 표시합니다.지금부터 왜
Validate failed
로 변했는지 조사를 시작하겠습니다.validate 실행
VALIDATE_ERROR
관련 Flyway 문서Caused by: Some migrations have failed validation
Solution: Inspect the list invalidMigrations on the validate result to see the required actions
구성하다.
validate를 실행하면 원인을 규명할 수 있을 거라고 생각했지만 출력 내용은 변하지 않았습니다.
[ec2-user@xxx flyway-7.1.1]$ ./flyway validate
ERROR: Unexpected error
org.flywaydb.core.api.exception.FlywayValidateException: Validate failed: Migrations have failed validation
at org.flywaydb.core.Flyway$2.execute(Flyway.java:274)
at org.flywaydb.core.Flyway$2.execute(Flyway.java:266)
at org.flywaydb.core.Flyway.execute(Flyway.java:538)
at org.flywaydb.core.Flyway.validate(Flyway.java:266)
at org.flywaydb.commandline.Main.executeOperation(Main.java:245)
at org.flywaydb.commandline.Main.main(Main.java:151)
validate의 outputType=json 추가 실행
그래서 validate의 Flyway에 대한 문서를 확인했습니다.
실행 중인 파라미터가
-outputType=json
있는 것을 발견했습니다.invalidMigrations
는 이미 알고 있는 것 같아서 이 인자를 추가하고 다시 실행합니다.[ec2-user@xxx flyway-7.1.1]$ ./flyway validate -outputType=json
{
"validationError": "Migrations have failed validation",
"errorDetails": {
"errorCode": "VALIDATE_ERROR",
"errorMessage": "Migrations have failed validation"
},
"invalidMigrations": [
{
"version": "1.01",
"description": "reformat_password",
"filepath": "/xxx/flyway-7.1.1/sql/V1.01__reformat_password.sql",
"errorDetails": {
"errorCode": "DESCRIPTION_MISMATCH",
"errorMessage": "Migration description mismatch for migration version 1.01\n-> Applied to database : reformat_password\n-> Resolved locally : reformat password. Either revert the changes to the migration, or run repair to update the schema history."
}
},
{
"version": "1.02",
"description": "fix field length",
"filepath": "/xxx/flyway-7.1.1/sql/V1.02__fix_field_length.sql",
"errorDetails": {
"errorCode": "RESOLVED_VERSIONED_MIGRATION_NOT_APPLIED",
"errorMessage": "Detected resolved migration not applied to database: 1.02. To fix this error, either run migrate, or set -ignorePendingMigrations=true."
}
}
],
"validationSuccessful": false,
"validateCount": 0,
"flywayVersion": "7.1.1",
"database": "yyy",
"warnings": [],
"operation": "validate"
}
상기 출력을 보았을 때version:1.01이DESCRIPTION_MISMATCH
인 것을 발견했다.개발자에게 확인해보니 수동으로 변경된 부분이 있었다.총결산
migration 오류가 발생하여 애플리케이션 로그에서 원인을 판단할 수 없는 경우 Flyway Command-line tool을 이용하면 해결할 수 있을 것입니다.
Reference
이 문제에 관하여(Flyway의 "Migrations have failed validation"상세 내용 조사), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://zenn.dev/adito/articles/dc8389395804db텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)