Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it okay to integrate database migration tools like Flyway, Liquibase with the application code base?

I mean is it good practice to allow application to modify the db? Or should database migration be done externally to the application code base?

New to this, so any input will be appreciated.

We are using java and gradle to build the application.

like image 976
ashishjmeshram Avatar asked Jan 20 '16 09:01

ashishjmeshram


1 Answers

Flyway author here.

Yes! At the end of the day, there are two important forces at play:

  1. Your schema is really tightly coupled to your application code: Your application expects certain tables and columns to be present so it can read & write to them. Which ones exactly varies from one release of your application to the next.
  2. You don't want to do database-based integration between applications/services as this breaks all encapsulation. A database is a private implementation detail of a service. Integration with other services should happen via an API layer with proper validation and business rules enforcement.

And so in light of all this, just keep together what belongs together.

By letting the application migrate the database on startup, you ensure the database schema is always in sync with the application's expectations of what it should find there.

like image 171
Axel Fontaine Avatar answered Oct 22 '22 18:10

Axel Fontaine