Javers - How to drop and create Javers tables in Spring Boot?

763 views Asked by At

How to create the Javers tables such as jv_snapshot, from scratch every time the Spring Boot Application is run?

3

There are 3 answers

0
Bartek Walacik On BEST ANSWER

JaVers creates its tables if they not exist and never drops them. There is no create-drop option like in Hibernate. For testing we recommend using in-memory db (H2) and running each test on a new and empty db instance.

0
Ali On

I had the same issue as I wanted to clear all the data from JaVers for every start of my Spring Boot application in my dev environment using postgres.

I set up in my application.properties as follow:

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

Since initialization-mode is now active, Spring boot will look at the file data.sql under src/main/ressources and run the SQL inside.

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

Even if the tables don't exist, Spring Boot will still start thanks to the continue-on-error setting.

0
王子1986 On

Yes, it will be auto created.

See a demo here: https://github.com/yhjhoo/javers-demo