Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flyway migration in Development and Production

I searching for an way to do a different migration in production and development.

I want to create a Spring Webapplication with Maven. In development i want to update database schema AND load test data. In production when a new version of the application is deployed i want only change the schema and don't load test data.

My first idea was to save the schema update and insert statements into different folders.

I think every body has solved this problem and can help me, thank you very much.

like image 631
user3361807 Avatar asked Mar 21 '23 10:03

user3361807


1 Answers

Basically, you have two options:

You could use different locations for your migrations in your flyway.locations property, i.e.:

for Test

flyway.locations=sql/structure,sql/test

for Production

flyway.locations=sql/structure

That way, you include your test data in the sql/test folder. You would have to take care with numbering, of course.

The second option (the one I prefer), is don't include test data in your migrations at all.

Rather, create your testdata any way you want and create an sql-dump of this data, which you keep separate from your migrations.

This works best if you have a separate database (instance, schema, whatever) containing your pristine testdata, where you apply each migration as part of your build process. This build job could then create a dump always matching the current migration.

When preparing your test machine, you first apply your migrations, then you load the contents of the matching dump.

I think this is a lot cleaner than the first version, especially because your test data can be prepared using other tools (your application) and has not to be handcoded.

like image 72
blackbuild Avatar answered Apr 25 '23 01:04

blackbuild