Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fail validate if an already applied migration couldn't be found #988

Closed
timbuethe opened this issue Apr 10, 2015 · 20 comments
Closed

Fail validate if an already applied migration couldn't be found #988

timbuethe opened this issue Apr 10, 2015 · 20 comments

Comments

@timbuethe
Copy link

Validate currently fails if the hash of a applied migration differs from the hash of the same migration found in the classpath. However, it doesn't fail if the applied migration could not be found on the classpath.

I would like to see an option for this. Actually I thought that would be the default behaviour, so I would even suggest to activate that option per default, maybe in the next major release.

The option would help in cases where:

  1. a migration wasn't just edited but removed all together
  2. one uses an older version of the software and the database schema contains newer migrations

Related stackoverflow question:
http://stackoverflow.com/questions/29541845

@marbot
Copy link

marbot commented May 19, 2015

+1

We've ran into this issue as well, which in our opinion could also be a bug, because the behavior of flyway:migrate and flyway:validate are not consistent.

flyway:validate will fail with an error, which is the behavior we'd expect:

 [ERROR] Failed to execute goal org.flywaydb:flyway-maven-plugin:3.2.1:validate (default-cli) on project staging-dbbuild: org.flywaydb.core.api.FlywayException: Validate failed. Detected applied migration not resolved locally: 1.6.10.015 -> [Help 1]

but flyway:migrate will run just fine:

[INFO] Flyway 3.2.1 by Boxfuse
[INFO] Database: jdbc:oracle:thin:@sicdb01-e:1521:DSIC01 (Oracle 11.2)
[INFO] Validated 101 migrations (execution time 00:00.391s)
[INFO] Current version of schema "E_TKMBN_STAGING": 1.6.10.016
[INFO] Migrating schema "E_TKMBN_STAGING" to version 1.7.0.000 - create rep lkp access path

Calling flyway:validate before flyway:migrate will "fix" this, but it is not a good solution, as the configuration parameter "validateOnMigrate" (for flyway:migrate) strongly suggests that a validation will be done in front of every flyway:migrate, but this isn't really the case.

I'd be happy to provide a pull request to implement this issue, if needed.

@xam7766
Copy link

xam7766 commented Jul 7, 2015

+1

We are experiencing the same problem.

Should we trigger a manual validation before or this will be fixed?

@blootac
Copy link

blootac commented Jul 16, 2015

+1

This could be quite a serious issue. We don't know whether a file is legitimately missing or accidentally removed so at the point of deployment should be alerted that a file we've already applied is no longer present

@PeeZu
Copy link

PeeZu commented Jul 17, 2015

+1

1 similar comment
@hikoma
Copy link

hikoma commented Nov 2, 2015

+1

@axelfontaine axelfontaine added this to the Flyway 4.0 milestone Nov 2, 2015
@mrniko
Copy link

mrniko commented Nov 10, 2015

+1

1 similar comment
@aanand7
Copy link

aanand7 commented Jan 7, 2016

+1

axelfontaine pushed a commit that referenced this issue Feb 3, 2016
@axelfontaine axelfontaine changed the title Introduce option to fail validate if an already applied migration couldn't be found Fail validate if an already applied migration couldn't be found Feb 3, 2016
@axelfontaine
Copy link
Contributor

Fixed. No new config option. Missing migrations now always trigger an exception.

axelfontaine pushed a commit to flyway/flywaydb.org that referenced this issue Feb 3, 2016
@davidkarlsen
Copy link

@axelfontaine Is there no way to skip this check?
I had a version 8 that I now have removed and no longer want applied, which was working on 3.x, but on 4 I get:

 Validate failed: Detected applied migration not resolved locally: 8

@axelfontaine
Copy link
Contributor

@davidkarlsen You can either set validateOnMigrate to false or drop your schema_version table and (re-)baseline your schema.

@mhartwig
Copy link

We are using for every featrue a new branch, so it appears, that the following situation appears:

Branch 1 has migration script "V20160317_1__Unique_User_Names"
Branch 2 has migration Script "V20160318_1__Add_Filter_Names"

So, if I started in Branch 1 everything is alright. Ich I switch to Branch 2, I will get this Error:
"Validate failed: Detected applied migration not resolved locally: 20160317.1"

The only chance I have is to NOT validate or using version 3.

Is there a way, to handle this in version 4?

@peterjurkovic
Copy link

peterjurkovic commented Jun 21, 2016

I am facing the same issue.

Is there a way, to handle this in version 4?

+1

@AndreiArion
Copy link

AndreiArion commented Jun 21, 2016

Same problem here on v4.0.1,
The flag validateOnMigrate doesn't seem to prevent the validation.

@AndreiArion
Copy link

AndreiArion commented Jun 21, 2016

Checked again on v4.0.3 and the validateOnMigrate=false does not prevent the error:

[aar@localhost db-migrations]$ mvn clean install flyway:info  flyway:migrate flyway:info -Dflyway.password="migrate"   -Dflyway.url=jdbc:mysql://localhost:3306/olap_quotation   -Polap,grants-preprod2  -DvalidateOnMigrate=false
[INFO] Scanning for projects...
Downloading: http://nexus.lan.courtanet.net/content/repositories/snapshots/org/flywaydb/flyway-maven-plugin/4.0.3/flyway-maven-plugin-4.0.3.pom
Downloading: http://nexus.lan.courtanet.net/content/groups/public/org/flywaydb/flyway-maven-plugin/4.0.3/flyway-maven-plugin-4.0.3.pom
Downloaded: http://nexus.lan.courtanet.net/content/groups/public/org/flywaydb/flyway-maven-plugin/4.0.3/flyway-maven-plugin-4.0.3.pom (5 KB at 16.7 KB/sec)
Downloading: http://nexus.lan.courtanet.net/content/repositories/snapshots/org/flywaydb/flyway-parent/4.0.3/flyway-parent-4.0.3.pom
Downloading: http://nexus.lan.courtanet.net/content/groups/public/org/flywaydb/flyway-parent/4.0.3/flyway-parent-4.0.3.pom
Downloaded: http://nexus.lan.courtanet.net/content/groups/public/org/flywaydb/flyway-parent/4.0.3/flyway-parent-4.0.3.pom (31 KB at 171.6 KB/sec)
Downloading: http://nexus.lan.courtanet.net/content/repositories/snapshots/org/flywaydb/flyway-maven-plugin/4.0.3/flyway-maven-plugin-4.0.3.jar
Downloading: http://nexus.lan.courtanet.net/content/groups/public/org/flywaydb/flyway-maven-plugin/4.0.3/flyway-maven-plugin-4.0.3.jar
Downloaded: http://nexus.lan.courtanet.net/content/groups/public/org/flywaydb/flyway-maven-plugin/4.0.3/flyway-maven-plugin-4.0.3.jar (30 KB at 453.7 KB/sec)
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building Devtools - DB Migrations 3.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
Downloading: http://nexus.lan.courtanet.net/content/groups/public/org/flywaydb/flyway-core/4.0.3/flyway-core-4.0.3.pom
Downloaded: http://nexus.lan.courtanet.net/content/groups/public/org/flywaydb/flyway-core/4.0.3/flyway-core-4.0.3.pom (19 KB at 189.6 KB/sec)
Downloading: http://nexus.lan.courtanet.net/content/groups/public/org/flywaydb/flyway-commandline/4.0.3/flyway-commandline-4.0.3.pom
Downloaded: http://nexus.lan.courtanet.net/content/groups/public/org/flywaydb/flyway-commandline/4.0.3/flyway-commandline-4.0.3.pom (9 KB at 92.2 KB/sec)
Downloading: http://nexus.lan.courtanet.net/content/groups/public/org/mariadb/jdbc/mariadb-java-client/1.4.5/mariadb-java-client-1.4.5.pom
Downloaded: http://nexus.lan.courtanet.net/content/groups/public/org/mariadb/jdbc/mariadb-java-client/1.4.5/mariadb-java-client-1.4.5.pom (16 KB at 93.0 KB/sec)
Downloading: http://nexus.lan.courtanet.net/content/groups/public/org/flywaydb/flyway-core/4.0.3/flyway-core-4.0.3.jar
Downloading: http://nexus.lan.courtanet.net/content/groups/public/org/flywaydb/flyway-commandline/4.0.3/flyway-commandline-4.0.3.zip
Downloading: http://nexus.lan.courtanet.net/content/groups/public/org/mariadb/jdbc/mariadb-java-client/1.4.5/mariadb-java-client-1.4.5.jar
Downloaded: http://nexus.lan.courtanet.net/content/groups/public/org/flywaydb/flyway-core/4.0.3/flyway-core-4.0.3.jar (345 KB at 1840.2 KB/sec)
Downloaded: http://nexus.lan.courtanet.net/content/groups/public/org/mariadb/jdbc/mariadb-java-client/1.4.5/mariadb-java-client-1.4.5.jar (363 KB at 1329.6 KB/sec)
Downloaded: http://nexus.lan.courtanet.net/content/groups/public/org/flywaydb/flyway-commandline/4.0.3/flyway-commandline-4.0.3.zip (11623 KB at 3629.9 KB/sec)
[INFO] 
[INFO] --- maven-clean-plugin:2.6.1:clean (default-clean) @ db-migrations ---
[INFO] Deleting /ssd/lesfurets/devtools/db-migrations/target
[INFO] 
[INFO] --- git-commit-id-plugin:2.1.15:revision (default) @ db-migrations ---
[INFO] 
[INFO] --- maven-resources-plugin:2.7:copy-resources (copy-grants-benefit) @ db-migrations ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 1 resource
[INFO] 
[INFO] --- maven-resources-plugin:2.7:copy-resources (copy-grants-olap) @ db-migrations ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 1 resource
[INFO] 
[INFO] --- maven-resources-plugin:2.7:resources (default-resources) @ db-migrations ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 9 resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.3:compile (default-compile) @ db-migrations ---
[INFO] No sources to compile
[INFO] 
[INFO] --- maven-resources-plugin:2.7:testResources (default-testResources) @ db-migrations ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /ssd/lesfurets/devtools/db-migrations/src/test/resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.3:testCompile (default-testCompile) @ db-migrations ---
[INFO] No sources to compile
[INFO] 
[INFO] --- maven-surefire-plugin:2.18.1:test (default-test) @ db-migrations ---
[INFO] No tests to run.
[INFO] 
[INFO] --- maven-jar-plugin:2.6:jar (default-jar) @ db-migrations ---
[INFO] Building jar: /ssd/lesfurets/devtools/db-migrations/target/db-migrations-3.1-SNAPSHOT.jar
[INFO] 
[INFO] --- maven-install-plugin:2.5.2:install (default-install) @ db-migrations ---
[INFO] Installing /ssd/lesfurets/devtools/db-migrations/target/db-migrations-3.1-SNAPSHOT.jar to /home/aar/.m2/repository/net/courtanet/devtools/db-migrations/3.1-SNAPSHOT/db-migrations-3.1-SNAPSHOT.jar
[INFO] Installing /ssd/lesfurets/devtools/db-migrations/pom.xml to /home/aar/.m2/repository/net/courtanet/devtools/db-migrations/3.1-SNAPSHOT/db-migrations-3.1-SNAPSHOT.pom
[INFO] 
[INFO] --- flyway-maven-plugin:4.0.3:info (default-cli) @ db-migrations ---
[INFO] Flyway 4.0.3 by Boxfuse
[INFO] Database: jdbc:mysql://localhost:3306/olap_quotation (MySQL 5.5)
[INFO] 
+---------+--------------------------------------+---------------------+---------+
| Version | Description                          | Installed on        | State   |
+---------+--------------------------------------+---------------------+---------+
| 2.1     | base olap quotation bo 20160620      | 2016-06-21 17:31:25 | Success |
| 2.2     | base olap quotation REFS bo 20160620 | 2016-06-21 17:31:25 | Missing |
| 4       | grants bo4 20151112                  | 2016-06-21 17:31:25 | Success |
| 2.22    | base olap quotation REFS bo 20160620 |                     | Pending |
+---------+--------------------------------------+---------------------+---------+

[INFO] 
[INFO] --- flyway-maven-plugin:4.0.3:migrate (default-cli) @ db-migrations ---
[INFO] Database: jdbc:mysql://localhost:3306/olap_quotation (MySQL 5.5)
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 9.717 s
[INFO] Finished at: 2016-06-21T17:34:39+02:00
[INFO] Final Memory: 23M/309M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.flywaydb:flyway-maven-plugin:4.0.3:migrate (default-cli) on project db-migrations: org.flywaydb.core.api.FlywayException: Validate failed: Detected applied migration not resolved locally: 2.2 -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
[aar@localhost db-migrations]$ 

Should we fill a new bug report ?

Thanks,
Andrei

@axelfontaine
Copy link
Contributor

@AndreiArion Yes, please open a new issue with all the relevant details on how to reproduce this.

@pik0
Copy link

pik0 commented Jun 24, 2016

These needs to be controlled by a configuration option!! This requirement assumes that schema updates are all handled by one repository and process. That's just not realistic! In our shop, we have so many projects that all feed in to each customer's databases, depending on what modules they license. Each module, has it's own specific schema update necessary to make that module work. They all need to co-mingle, and turning off the validateOnMigrate feature just won't cut it. Migrations still need to be validate in case we start to use the new Repeatable option or if an older Validated migration is changed by mistake.

With this new requirement, we're stuck at 3.2.1... :(

@axelfontaine
Copy link
Contributor

@AndreiArion It appears @pik0 was faster and opened #1352

@pik0
Copy link

pik0 commented Jun 24, 2016

Yeah, the powers-that-be were breathing down my neck for answers. Had to revert back to 3.2.1 and advise them of the status. Decided to file the bug since I already had gathered the report for them. Looks like this won't be fixed until 4.1 at the earliest based on other issue reports I'm seeing... :-/

@vayalaivadivel
Copy link

Hi, I getting below error while running spring boot with flyway and postgres sql. Any one can please help on to fix this issue,

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'flywayInitializer' defined in class path resource [org/springframework/boot/autoconfigure/flyway/FlywayAutoConfiguration$FlywayConfiguration.class]: Invocation of init method failed; nested exception is org.flywaydb.core.api.FlywayException: Validate failed: Detected resolved migration not applied to database: 1.0
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1578)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:545)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:772)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:839)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:538)
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:118)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:766)
at org.springframework.boot.SpringApplication.createAndRefreshContext(SpringApplication.java:361)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:307)
at org.springframework.boot.test.SpringApplicationContextLoader.loadContext(SpringApplicationContextLoader.java:98)
at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:98)
at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:116)
... 25 more
Caused by: org.flywaydb.core.api.FlywayException: Validate failed: Detected resolved migration not applied to database: 1.0
at org.flywaydb.core.Flyway.doValidate(Flyway.java:1000)
at org.flywaydb.core.Flyway.access$100(Flyway.java:72)
at org.flywaydb.core.Flyway$2.execute(Flyway.java:974)
at org.flywaydb.core.Flyway$2.execute(Flyway.java:971)
at org.flywaydb.core.Flyway.execute(Flyway.java:1361)

Thanks and Regards,
VADIVEL

@JavaNeed
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests