【问题标题】:Javers - How to drop and create Javers tables in Spring Boot?Javers - 如何在 Spring Boot 中删除和创建 Javers 表?
【发布时间】:2018-02-18 05:32:17
【问题描述】:

如何在每次运行Spring Boot Application时从头开始创建jv_snapshot等Javers表?

【问题讨论】:

    标签: spring spring-boot javers


    【解决方案1】:

    如果表不存在,JaVers 会创建它的表,并且永远不会删除它们。在 Hibernate 中没有 create-drop 选项。对于测试,我们建议使用内存数据库 (H2) 并在新的空数据库实例上运行每个测试。

    【讨论】:

      【解决方案2】:

      是的,它将自动创建。

      在此处查看演示: https://github.com/yhjhoo/javers-demo

      【讨论】:

        【解决方案3】:

        我遇到了同样的问题,因为我想使用 postgres 在开发环境中每次启动 Spring Boot 应用程序时清除 JaVers 中的所有数据。

        我在我的application.properties 中设置如下:

        spring:
          profiles: dev
          jpa:
            hibernate:
              ddl-auto: create-drop
          datasource:
            initialization-mode: always
            continue-on-error: true
        

        由于initialization-mode现在处于活动状态,Spring boot会查看src/main/ressources下的文件data.sql并运行里面的SQL。

        TRUNCATE jv_commit CASCADE;
        TRUNCATE jv_commit_property CASCADE;
        TRUNCATE jv_global_id CASCADE;
        TRUNCATE jv_snapshot CASCADE;
        

        即使表不存在,由于 continue-on-error 设置,Spring Boot 仍然会启动。

        【讨论】:

          猜你喜欢
          • 2018-12-17
          • 1970-01-01
          • 1970-01-01
          • 2017-04-29
          • 1970-01-01
          • 1970-01-01
          • 2017-04-29
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多