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

How to make migration task fail for missing migrations? #32

Open
micheal-hill opened this issue Oct 19, 2018 · 4 comments
Open

How to make migration task fail for missing migrations? #32

micheal-hill opened this issue Oct 19, 2018 · 4 comments

Comments

@micheal-hill
Copy link

I'm trying to have flyway/sbt produce an error (rather than a warning) when migrations are missing, but I haven't been able to find any options that would present this behavior. Specifically, I would like sbt to exit with a non-zero exit status if a migration is missing - the same behavior as when a migration has been modified after apply.

Is there some setting/configuration that I can change to do this?

> sbt flyway/flywayMigrate
[info] Loading settings for project global-plugins from idea.sbt ...
[info] Loading global plugins from __user__/.sbt/1.0/plugins
[info] Loading project definition from __user__/flyway_spike/project/project
[info] Loading settings for project flyway_spike-build from plugins.sbt ...
[info] Loading project definition from __user__/flyway_spike/project
[info] Loading settings for project flyway from build.sbt ...
[info] Loading settings for project flyway_spike from build.sbt ...
[info] Set current project to flyway_spike (in build file:__user__/flyway_spike/)
[info] Flyway Community Edition 5.2.0 by Boxfuse
[info] Database: jdbc:postgresql://localhost:5432/postgres (PostgreSQL 10.5)
[info] Successfully validated 1 migration (execution time 00:00.014s)
[info] Current version of schema "public": 20181018
[warn] Schema "public" has version 20181018, but no migration could be resolved in the configured locations !
[info] Schema "public" is up to date. No migration necessary.
[success] Total time: 0 s, completed 19/10/2018 12:58:17 PM
@davidmweber
Copy link
Collaborator

Not that I know of. Do you have a test migration (preferably for H2) that I can use?

@micheal-hill
Copy link
Author

Working with a single migration, with the option flywayIgnoreMissingMigrations explicitly set to false (which appears to be the default, anyway).

In file V20181018__create_foo.sql:

CREATE TABLE test_user (
  name VARCHAR(25) NOT NULL,
  PRIMARY KEY(name)
);

Running the migration works without issue. However, if I delete the migration file after it has been run and try to run the migrations again, I only receive a warning and the migration task passes without error.


Researching this issue; it appears that the flyway option ignoreFutureMigrationsproduces the behavior I'm looking for when I use the CLI tool. However, I couldn't get the sbt version of this option to work as I expected (it didn't seem to have any affect). For now, I will use the flyway CLI tool as it appears to do what I need.

@davidmweber
Copy link
Collaborator

Thanks! I'll make a test case and dig in to it.

@davidmweber
Copy link
Collaborator

I have refactored the logic for setting migration parameters. Seems that ignoreFutureMigrations setting got lost in some deprecation. Can you check if the fail-on-error branch fixes this? You can sbt publishLocal and use 5.2.1-SNAPSHOT for the plugin version. If this fails, I will set up a more complex test case against a persistent database.

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

No branches or pull requests

2 participants