How to skip a specific migration with flyway?

谁说胖子不能爱 提交于 2020-01-12 06:42:31

问题


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 ?


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/29012034/how-to-skip-a-specific-migration-with-flyway

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!