Search code examples
postgresqlspring-bootjavers

Javers on a separate database?


From another post, it would seem that javers can store changesets on another database. As @Bartek Walacik said:

Advantages? You can choose where to store audit data. By default JaVers uses the same database as application does, but you can point another database. For example, SQL for application and MongoDB for JaVers or centralized JaVers database shared for all applications in your company).

The above is what I want to do: I want to store the changesets (jv_commit, jv_commit_property, jv_global_id and jv_snapshots) on a separate database from the main one. How would I do that?

I have the following on my application yaml:

javers:
mappingStyle: FIELD
algorithm: SIMPLE
prettyPrint: true
typeSafeValues: false
newObjectSnapshot: false
packagesToScan:
auditableAspectEnabled: true
springDataAuditableRepositoryAspectEnabled: true

I looked through the Javer's Builder doc, but couldn't find anything that would allow me to specify a datasource.

Help, please?


Solution

  • If you are using JaVers' Spring Boot Starter, you can to override this bean:

    @Bean
    @ConditionalOnMissingBean
    public ConnectionProvider jpaConnectionProvider() {
        return new JpaHibernateConnectionProvider();
    }
    

    ConnectionProvider should return connections to that separate DB.