Spring 启动 : Executing the Newer version of SQL file each time we rebuild the application

标签 spring postgresql hibernate spring-boot jpa

我有一个带有 PostgreSQLspring-boot 应用程序。一些表是使用模型创建的,而其他表必须在应用程序启动之前或启动应用程序时创建。这可以通过在启动时运行 SQL 文件来完成。

但是数据库往往会随着时间的推移而改变,我们可能不得不改变一些表,添加一些新表而不影响表中现有的数据等。

有没有办法在每次重建和重新运行时添加新的 SQL 文件,并只运行 spring-boot 应用程序中未运行的 SQL 文件?如果一切都已执行,则不要在启动时运行任何 SQL 文件?

最佳答案

对于您的场景,liquibase 是最佳解决方案。您可以在 spring boot 应用程序上合并 liquibase。

例如:https://javadeveloperzone.com/spring-boot/spring-boot-liquibase-example/

关于 Spring 启动 : Executing the Newer version of SQL file each time we rebuild the application,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58501829/

相关文章:

Java:为示例数据库应用程序构建 webapp UI

hibernate - 避免 Grails/Hibernate 中的 N+1 选择

java - Spring 3.0 Java REST返回PDF文档

PostgreSQL 计数

java - 如果缺少参数,Spring 4.1.5 MVC @RequestParam(required = false, value = "somevalue") 失败

sql - 如果找到几行,如何只删除一行?

SQL:如何更新 ltree 中的值?

java - hibernate SQL 错误 : 1064, SQLState: 42000

java - 使用 Spring Framework 为 OPTIONS 请求启用 CORS

java - Spring 数据 JPA : Sorting and paging with joined tables