27

I'm using flyway with gradle, I've run 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?

fat
  • 6,435
  • 5
  • 44
  • 70
Iman
  • 382
  • 1
  • 4
  • 10

3 Answers3

21

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.

pards
  • 1,098
  • 15
  • 20
  • Sometime no need for inserting crafted `insert` (for example if your upgrade script failed on adding existing column or dropping already removed table). Just allow for Flyway to fail and fix latest line by setting `success = 1`. You can make safe failure with garbage at the beginning of update script (that prevents further possibly dangerous actions). Just remove garbage before `flyway:repair` – gavenkoa Nov 19 '17 at 14:23
7

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.
fat
  • 6,435
  • 5
  • 44
  • 70
Sagar Ahuja
  • 637
  • 10
  • 10
1

As of version 7, you can add it directly to your Maven or Grade file

Gradle - Skip

flyway {
     skipExecutingMigrations = true
}

Maven - Skip

<configuration>
     <skipExecutingMigrations>true</skipExecutingMigrations>
</configuration>

Documentation Reference Skip

Gradle - Cherry Pick

flyway {
     cherryPick = '2.0'
}

Maven - Cherry Pick

<configuration>
     <cherryPick>2.0</cherryPick>
</configuration>

Documentation Reference Cherry Pick

Justin Nimmo
  • 125
  • 12
  • 2
    Please note that the parameter "skipExecutingMigrations" is a Teams edition feature. That means you must pay to use this feature. – johnlinp Feb 11 '22 at 02:58
  • It works only in paid edition. In my opinion, Liquibase is a much better solution than Flyway. You do not have to pay for basic features. – Krzysztof Feb 11 '23 at 11:02
  • @Krzysztof Don't shoot the messenger. – Justin Nimmo Feb 26 '23 at 05:52
  • I am not shooting anyone. The person who asked did not specify Flyway version, so if a solution requires paid version, the answer should mention this requirement. – Krzysztof Mar 01 '23 at 09:53