Solucionado (ver solução)
Solucionado
(ver solução)
3
respostas

[Dúvida] Erro ao criar uma nova migration

Olá professor, meu código estava com o seguinte problema: `Detected failed migration to version 4 (alter-table-medicos-add-column-ativo). Please remove any half-completed changes then run repair to fix the schema history. Need more flexibility with validation rules? Learn more: https://rd.gt/3AbJUZE 2023-08-07T22:28:50.904-03:00 INFO 16228 --- [ restartedMain] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Shutdown initiated... 2023-08-07T22:28:50.945-03:00 INFO 16228 --- [ restartedMain] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Shutdown completed. 2023-08-07T22:28:50.948-03:00 INFO 16228 --- [ restartedMain] o.apache.catalina.core.StandardService : Stopping service [Tomcat] 2023-08-07T22:28:50.962-03:00 INFO 16228 --- [ restartedMain] .s.b.a.l.ConditionEvaluationReportLogger :

Error starting ApplicationContext. To display the condition evaluation report re-run your application with 'debug' enabled. 2023-08-07T22:28:50.983-03:00 ERROR 16228 --- [ restartedMain] o.s.boot.SpringApplication : Application run failed

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'flywayInitializer' defined in class path resource [org/springframework/boot/autoconfigure/flyway/FlywayAutoConfiguration$FlywayConfiguration.class]: Validate failed: Migrations have failed validation Detected failed migration to version 4 (alter-table-medicos-add-column-ativo). Please remove any half-completed changes then run repair to fix the schema history.`

e usei o delete from flyway_schema_history where success = 0; e continuou o problema. Daí usei o delete from flyway_schema_history; e estou com esse problema agora:

`Detected failed migration to version 1 (create-table-medicos). Please remove any half-completed changes then run repair to fix the schema history. Need more flexibility with validation rules? Learn more: https://rd.gt/3AbJUZE 2023-08-07T22:43:44.795-03:00 INFO 7140 --- [ restartedMain] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Shutdown initiated... 2023-08-07T22:43:44.822-03:00 INFO 7140 --- [ restartedMain] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Shutdown completed. 2023-08-07T22:43:44.825-03:00 INFO 7140 --- [ restartedMain] o.apache.catalina.core.StandardService : Stopping service [Tomcat] 2023-08-07T22:43:44.839-03:00 INFO 7140 --- [ restartedMain] .s.b.a.l.ConditionEvaluationReportLogger :

Error starting ApplicationContext. To display the condition evaluation report re-run your application with 'debug' enabled. 2023-08-07T22:43:44.861-03:00 ERROR 7140 --- [ restartedMain] o.s.boot.SpringApplication : Application run failed

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'flywayInitializer' defined in class path resource [org/springframework/boot/autoconfigure/flyway/FlywayAutoConfiguration$FlywayConfiguration.class]: Validate failed: Migrations have failed validation Detected failed migration to version 1 (create-table-medicos). Please remove any half-completed changes then run repair to fix the schema history. ` e eu estava com o código parado na hora de mexer nas migrations.

3 respostas

Olá Iago

Uma solução para esse problema é realizar uma reparação no history do schema do Flyway. Você já tentou executar o comando repair após remover as alterações incompletas? Por exemplo, você pode executar o seguinte comando no seu banco de dados:

delete from flyway_schema_history where success = 0;

Em seguida, execute o comando repair para corrigir a história do schema:

repair

Essa ação pode ajudar a corrigir os erros de validação nas migrations anteriores e permitir que você crie uma nova migration sem problemas.

solução!

Oi!

Apagar todas as migrations também não resolve, pois quando o Flyway for executar novamente as migrations as tabelas já estarão criadas no banco e ele vai falhar.

Apague e recrei o banco de dados inteiro:

drop database vollmed_api;
create database vollmed_api;

Obrigado pessoal!

Tive que excluir e criar um novo e voltou a funcionar.