简体   繁体   English

基于 java 应用程序的 spring-boot 的版本控制工具,Flyway 等

[英]Version control tool for spring-boot based java application, Flyway like

Problem description问题描述
I have a spring-boot based application that creates entities on a 3rd party environment.我有一个基于 spring-boot 的应用程序,它在第 3 方环境中创建实体。
The application is deployed on prod.该应用程序部署在产品上。
I've discovered a bug whose fix required changes on the already created entities on the 3rd party prod entities.我发现了一个错误,其修复需要对 3rd 方 prod 实体上已创建的实体进行更改。
Expected solution预期的解决方案
The the 3rd party prod environment entities are fix running a java based script.第 3 方 prod 环境实体正在修复运行基于 java 的脚本。
I want that script to be run in prod only the first time the application version with the fix is deployed.我希望该脚本仅在第一次部署具有修复程序的应用程序版本时在 prod 中运行。
I'm looking for the same functionality Flyway provided for database entities.我正在寻找为数据库实体提供的相同功能 Flyway。 I could use Flayway but since my application does not uses a database, I don't want to use a database versioning control tool on a non database application, in order to do not couple the database versioning concept to a non database application.我可以使用 Flayway,但由于我的应用程序不使用数据库,因此我不想在非数据库应用程序上使用数据库版本控制工具,以免将数据库版本控制概念耦合到非数据库应用程序。
Question问题
Is there a library/tool that provides the functionality I'm looking for?是否有提供我正在寻找的功能的库/工具?

There are many ways to execute code upon startup in a spring application.在 spring 应用程序中启动时执行代码的方法有很多。 Take a look here for some of them.看看这里的一些。 The code would be run every single time the application starts, so in order to apply the fix only once you could:该代码将在应用程序每次启动时运行,因此为了只应用一次修复,您可以:

Just let it run once让它运行一次

The simplest solution would be to deploy the version with the fix, let the code run automatically and then deploy the next version with the fix removed.最简单的解决方案是部署带有修复的版本,让代码自动运行,然后部署删除修复的下一个版本。 Though not very elegant and not recommended it would only execute once in a simple setup.虽然不是很优雅且不推荐,但它只会在简单的设置中执行一次。 Depending on the deployment and runtime setup there might be some risks to that though, or even impossible.但是,根据部署和运行时设置,可能会有一些风险,甚至是不可能的。

You seem to be looking for some protection against multiple execution of that fix.您似乎正在寻找一些针对多次执行该修复程序的保护措施。 For instance because the application is started again after being deployed, which essentially boils done to either making multiple executions possible or prevent them by remembering state:例如,因为应用程序在部署后再次启动,这基本上是为了使多个执行成为可能,或者通过记住 state 来阻止它们:

Make the changes idempotent使更改具有幂等性

You won't need any tool if you're able to make the fix operation idempotent, changing the entities in question only on its initial application.如果您能够使修复操作具有幂等性,您将不需要任何工具,仅在其初始应用程序中更改相关实体。 Say you created users with a faulty email address, you'd check for a faulty email address and only apply the fix if you found your fix not already applied.假设您使用错误的 email 地址创建了用户,您将检查错误的 email 地址,并且仅在发现尚未应用修复时才应用修复。 That way the fix can run multiple times without causing any harm.这样,修复程序可以多次运行而不会造成任何伤害。 Not all operations can be made idempotent though.但是,并非所有操作都可以做到幂等。

Preserve state between runs在运行之间保留 state

The idea behind this is to remember the successfull execution of your fix.这背后的想法是记住修复的成功执行。 Flyway does this for database migrations. Flyway 为数据库迁移执行此操作。 Again it depends on the execution environment to determine what kind of storage is sufficient here.同样,它取决于执行环境来确定哪种存储在这里是足够的。

  • Use a file on the filesystem to mark the completion.使用文件系统上的文件来标记完成。 Only execute the fix if the file's missing and create it afterwards.只有在文件丢失时才执行修复,然后再创建它。 This solution might fail in a containerized enviroment when the container is recreated or in a cluster setup.当重新创建容器或在集群设置中时,此解决方案可能会在容器化环境中失败。
  • Use a database to mark the completition.使用数据库来标记完成。 You can create fi a H2 database, create an empty table with flyway and check for the empty table before executing your fix, then insert a row into the table afterwards.您可以创建一个 H2 数据库,使用 flyway 创建一个空表并在执行修复之前检查空表,然后在表中插入一行。 Using a h2 database safes you from having another service running, but is subject to the same limitations the file solution is.使用 h2 数据库可以保护您免于运行其他服务,但会受到与文件解决方案相同的限制。
  • Use an external service like redis to protect against multiple execution of your script.使用 redis 之类的外部服务来防止脚本的多次执行。 You could also protect the fix against multiple concurrent executions using this one.您还可以使用这个来保护修复免受多个并发执行的影响。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM