Generator-jhipster: Change Test database type

Created on 2 May 2019  路  3Comments  路  Source: jhipster/generator-jhipster

Overview of the feature request


Hi everyone,
All Jhipster projects using h2 as a database, for some reasons I need to use SQL DB like Postgres.
I've changed .properties file in test/resources but still give me errors in H2 with liquibase
for ex:

Caused by: liquibase.exception.ValidationFailedException: Validation Failed:
     5 changes have validation failures
          columnDataType is required for dropNotNullConstraint on H2

for now :
1- I think developers should choose the type of DB in testing mode.
2- I need a way to change it also for my previous microservice project.

Motivation for or Use Case
Related issues or PR
  • [x] Checking this box is mandatory (this is just to show you read everything)
area

Most helpful comment

If you are okay with using docker during your integration tests, have a look at https://github.com/testcontainers/testcontainers-java

You can just define a special jdbc url: https://www.testcontainers.org/modules/databases/#database-containers-launched-via-jdbc-url-scheme

(not yet tried it myself)

This is the relevant change in test/application.properties:

spring:
  application:
    name: jhipster
  datasource:
    type: com.zaxxer.hikari.HikariDataSource
    url: jdbc:tc:postgresql:11.2://localhost:5432/jhipster
    name:
    username:
    password:
    hikari:
      auto-commit: false
    driver-class-name: org.testcontainers.jdbc.ContainerDatabaseDriver
  jpa:
    database-platform: io.github.jhipster.domain.util.FixedPostgreSQL95Dialect
    database: POSTGRESQL

All 3 comments

Have you tried changing
url: jdbc:h2:mem:mydb;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE
to something like
url: jdbc:postgresql://localhost:5432/mydb

I haven't try this method but it should work i think.

Also keep in mind that since it is not an in-memory db, Integration tests may fail because the previous data won't be cleared and hence giving false results.

If you are okay with using docker during your integration tests, have a look at https://github.com/testcontainers/testcontainers-java

You can just define a special jdbc url: https://www.testcontainers.org/modules/databases/#database-containers-launched-via-jdbc-url-scheme

(not yet tried it myself)

This is the relevant change in test/application.properties:

spring:
  application:
    name: jhipster
  datasource:
    type: com.zaxxer.hikari.HikariDataSource
    url: jdbc:tc:postgresql:11.2://localhost:5432/jhipster
    name:
    username:
    password:
    hikari:
      auto-commit: false
    driver-class-name: org.testcontainers.jdbc.ContainerDatabaseDriver
  jpa:
    database-platform: io.github.jhipster.domain.util.FixedPostgreSQL95Dialect
    database: POSTGRESQL

As suggested by @atomfrede, you are free to customize your generated application to use testcontainers.

There is already a module developed by @ecostanzi

You should have a look and try to help the author.

For the generator, we didn't propose it by default, as there are a lot of users who are still with Windows and it didn't work well for them.
I don't think it's a good idea to maintain 2 options for tests: h2 + testcontainers

Was this page helpful?
0 / 5 - 0 ratings

Related issues

dronavallisaikrishna picture dronavallisaikrishna  路  3Comments

cbornet picture cbornet  路  4Comments

marcelinobadin picture marcelinobadin  路  3Comments

DanielFran picture DanielFran  路  3Comments

lsadehaan picture lsadehaan  路  3Comments