Any way to “compress” Flyway migrations?

前端 未结 3 859
慢半拍i
慢半拍i 2020-12-08 19:18

We are using Flyway to migrate the database schema and we already have more than 100 migration scripts.

Once we \"squashed\" multiple migrations into a single first-

3条回答
  •  萌比男神i
    2020-12-08 19:48

    Isn't that what re-baselining would do?

    I'm still new to flyway, but this is how I think it would work. Please test the following first before taking my word for it.

    Delete the schema_version table. Delete your migration scripts.

    Run flyway baseline (this recreates the schema_version table and adds a baseline record as version 1)

    Now you're good to go. Bear in mind that you will not be able to 'migrate' to any prior version as you've removed all of your migration scripts, but this might not be a problem for you.

    Step by step solution:

    1. drop table schema_version;
    2. Export database structure as a script via MySQL Workbench, for example. Name this script V1__Baseline.sql
    3. Delete all migration scripts and add V1__Baseline.sql to your scripts folder, so it is the only script available for Flyway
    4. Run Flyway's "baseline" command
    5. Done

提交回复
热议问题