Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to test flyway migration?

Usually migration script is simple like adding new column or so and if applications if deployed then everything is ok. but sometimes there is some complex logic involved that should be tested. what is the recommended approach?

like image 437
piotrek Avatar asked Mar 19 '23 18:03

piotrek


1 Answers

Have a separate DB for testing. Migrate it as part of every build and run tests against it. You can also populate it with extra test data as you desire by including a second location for test data migrations.

Main Location:

  • V1__Initial.sql
  • V2__More_changes.sql
  • V3__Complex_logic.sql

Test data location:

  • V2.1__Test_data.sql

You can then call flyway.clean() and flyway.migrate() in a test before asserting whether the test data got transformed correctly.

like image 95
Axel Fontaine Avatar answered Mar 29 '23 10:03

Axel Fontaine