How to skip a specific migration with flyway?

2019-04-05 01:40发布

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 ?

标签: flyway
2条回答
对你真心纯属浪费
2楼-- · 2019-04-05 02:06

Not Recommended But if you still want to :

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.
4) Done, flyway will now start with the next version of migration.

查看更多
神经病院院长
3楼-- · 2019-04-05 02:13

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.

查看更多
登录 后发表回答