Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to skip a specific migration with flyway?

Tags:

I'm using flyway with gradle, I've ran one of the migrations manually inside the database console, I want to run flyway, but tell it to ignore one specific migration version in between all the others. Can this be done ?

like image 475
Iman Avatar asked Mar 12 '15 14:03

Iman


People also ask

What is Flyway exception?

it means that you ran migrate before and it failed at 1.0 for some reason. You need to identify why the previous migration failed at 1.0 and solve it if you have already not done so. Once solved you need to run flyway repair to tell flyway that whatever failed is now out of the way. Then run flyway migrate again.

What is repeatable migration in Flyway?

Repeatable migrations are very useful for managing database objects whose definition can then simply be maintained in a single file in version control. Instead of being run just once, they are (re-)applied every time their checksum changes. They are typically used for. (Re-)creating views/procedures/functions/packages/ ...

Does Flyway auto commit?

Flyway does not handle implicity committed statements when flyway process crashes. Bookmark this question.

Which is better Flyway or Liquibase?

While both tools are based on Martin Fowler's Evolutionary Database, there are many differences in what these tools offer. Here's where Liquibase and Flyway differ. The bottom line is that Liquibase is more powerful and flexible — covering more database change and deployment use cases than Flyway.

What should I do when flywaymigrate fails?

1) Run flywayMigrate, let the migration fail. 2) Manually, update the flyway meta table (success column) for that specific version of migration. 3) Run flywayMigrate again.

What is skipexecutingmigrations in Flyway?

This is where skipExecutingMigrations comes in. On prod instead of running a normal migrate, instead run migrate -skipExecutingMigrations=true. Now Flyway will not actually try to execute the contents of the migration on this environment, instead just updating the schema history to say it’s been applied.

How to get database migration right in Flyway?

Here are some thoughts about how to get database migration right. Flyway tries to enforce incremental database changes. That means we shouldn’t update already applied migrations, except repeatable ones. By default, we should use versioned migrations that will only be run once and will be skipped in subsequent migrations.

Is there a way to reverse migrate in Flyway?

The solution I've seen for this (in general, with migrations, not specific to Flyway which I have no idea what it is) is to have "reverse migrations" that must be applied down downgrading. @torek, But it worked fine with older version of Flyway.


1 Answers

You would have to hack it a bit to get it to work, so I don't recommend this approach, but it would work in a pinch.

I've only tested this with Maven, but I'm pretty sure it'd work with Gradle too.

  1. Migrate up until the version before the one you applied manually

    # Assuming you applied 01.002 manually
    $ mvn flyway:migrate -Dflyway.target=01.001
    
  2. Insert a row for the script you applied

    -- Make sure these vals closely replicate those from other rows
    insert into schema_version( installed_rank, version, description, type, script, checksum, installed_by, installed_on, execution_time, success) 
    values ( 2, '01.002', 'static_data', 'SQL', 'V01/V01.002__static_data.sql', null, 'username', current_timestamp, 0, true );
    
  3. Repair the schema_version checksum

    $ mvn flyway:repair
    
  4. Apply the other migrations

    $ mvn flyway:migrate -Dflyway.validateOnMigrate=false -Dflyway.outOfOrder=true
    

The two -D properties there may not be necessary, depending on whether you got the insert correct or not. Flyway may disagree with your script description, for example, even if the checksum is now correct.

like image 140
pards Avatar answered Sep 19 '22 22:09

pards