如何跳过DDL更新中的某些实体

huangapple go评论85阅读模式
英文:

How to skip some of the entity from ddl update

问题

我有几个javax.persistence.Entity,其中大部分是为当前模块创建的,所以保持
spring.jpa.hibernate.ddl-auto = update

由于某些表已经存在,我想知道如何跳过更新一些已经存在的实体的DDL。

另外,我可以接受应用在运行时失败,但出现损坏的表。

英文:

have several javax.persistence.Entity

most of them are created for the current module, so keeping
spring.jpa.hibernate.ddl-auto = update

Since some of the tables are already there. I was wondering how can I skip updating the DDL for a few of the already existing entities.

also, I am okay letting the application fail on runtime but have a corrupted table.

答案1

得分: 2

根据评论中的建议,这是一个使用迁移工具像fylway/liquibase会非常有帮助的情况。

https://www.baeldung.com/database-migrations-with-flyway

通过指定(如指南中所示)CREATE TABLE IF NOT EXISTS ...,只有在表尚不存在时才会创建表,这正是您想要的。

英文:

Like advised in the comment it is a situation where a migration tool like fylway/liquibase would be most helpful.

https://www.baeldung.com/database-migrations-with-flyway

By specifying (like shown in the guide) CREATE TABLE IF NOT EXISTS ... your tables will only be created if they don't exist already which is exactly what you wanted

huangapple
  • 本文由 发表于 2020年8月1日 19:27:57
  • 转载请务必保留本文链接:https://go.coder-hub.com/63204684.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定