是否可以将Flyway,Liquibase等数据库迁移工具与应用程序代码库集成在一起? [英] Is it okay to integrate database migration tools like Flyway, Liquibase with the application code base?

查看:74
本文介绍了是否可以将Flyway,Liquibase等数据库迁移工具与应用程序代码库集成在一起?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的意思是允许应用程序修改数据库是一种好习惯吗?还是应该在应用程序代码库的外部进行数据库迁移?

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.

我们正在使用java和gradle来构建应用程序.

We are using java and gradle to build the application.

推荐答案

Flyway 的作者.

是的!归根结底,有两种重要的作用在发挥作用:

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

  1. 您的架构确实与您的应用程序代码紧密关联:您的应用程序希望存在某些表和列,以便可以读取和查看&给他们写信.从应用程序的一个版本到下一个版本,哪个版本完全不同.
  2. 您不想在应用程序/服务之间进行基于数据库的集成,因为这会破坏所有封装.数据库是服务的私有实现细节.与其他服务的集成应通过具有适当验证和业务规则实施的API层进行.
  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.

这篇关于是否可以将Flyway,Liquibase等数据库迁移工具与应用程序代码库集成在一起?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆