#Postgres for production, H2 to test, rand() function.
20 messages · Page 1 of 1 (latest)
⌛ This post has been reserved for your question.
Hey @buoyant sequoia! Please use
/closeor theClose Postbutton above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.
I think you need to use random() in postgres
yeah, but then i'll get an error in the h2 tests
use random() if you are in prod and rand() if you are in tests?
Can I do that?
or maybe there's a compatibility mode with H2
use an if statement
chexk if you are in tests?
I couldn't do that, because the query is an annotation:
@Query("SELECT um FROM User u " +
"JOIN u.favoriteMovies um " +
"WHERE u.id = :userId AND um.id NOT IN :movieIds " + "ORDER BY RAND() LIMIT 1")
Optional<Movie> findRandomMovieByUserIdAndNotInMovieIds(@Param("userId") Long userId,
@Param("movieIds") List<Long> movieId);
Yes
Hm, I didn't know this option
Ok, how exactly can I use that?
spring.datasource.url=jdbc:h2:mem:testdb;MODE=PostgreSQL
This way?
Do you have a different hibernate diakect configured in test and production?
Yes, but I can change if it is necessary
If you are finished with your post, please close it.
If you are not, please ignore this message.
Note that you will not be able to send further messages here after this post have been closed but you will be able to create new posts.
Ok, I think it worked, let me do some more tests