首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Spring Boot -数据库升级-从代码级别运行CRUD操作

Spring Boot -数据库升级-从代码级别运行CRUD操作
EN

Stack Overflow用户
提问于 2022-08-15 19:26:35
回答 1查看 55关注 0票数 0

目前,我们正在尝试运行数据库升级,一旦应用程序成功启动,基于ApplicationReadyEvent

代码语言:javascript
复制
private void upgradeDatabase() {
    int currentVersion = // initially saved in db_version table - say 1
    if (currentVersion < 2) {
         // the code to upgrade from current version (1) to new version (2)
         // update version number in db_version table
    }
    if (currentVersion < 3) {
         // the code to upgrade from current version (2) to new version (3)
         // update version number in db_version table
    }
}

由于数据升级背后有一些业务逻辑,所以不能通过Liquibase或Flyway甚至SQL来处理这些业务逻辑。

Spring提供了更好的方法来处理数据库升级吗?

EN

回答 1

Stack Overflow用户

发布于 2022-08-16 00:12:23

有一个Liquibase Java,您可以随时使用它。看看这个文章

最直接地运行Liquibase的方法如下所示:

代码语言:javascript
复制
java.sql.Connection connection = openConnection(); //your openConnection logic here
Database database = DatabaseFactory.getInstance().findCorrectDatabaseImplementation(new JdbcConnection(connection));
Liquibase liquibase = new liquibase.Liquibase("path/to/changelog.xml", new ClassLoaderResourceAccessor(), database);
liquibase.update(new Contexts(), new LabelExpression());
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73365599

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档