0

I have a PlayFramework application (Scala/2.8.1) which uses PostgreSQL in production. I'm trying to create tests for it using H2. The issue is that some of my evolutions use SQL statements that H2 does not recognize. Specifically, H2 chokes on this:

CREATE UNIQUE INDEX lowercase_user_names ON users (lower(username));

Is there a way I can make H2 ignore this statement, or not execute it while in Test?

Michael Bar-Sinai
  • 2,729
  • 20
  • 27
  • No, you can't make H2 ignore it. As to not execute it in test just don't run the code that executes it? – Oleg Apr 11 '20 at 11:58
  • Can't just "not run" it, since this SQL code is executed automatically by an evolution mechanism when the database is initialized. – Michael Bar-Sinai Apr 11 '20 at 19:03
  • Then just do what reasonable people do, use the same database for production and testing. – Oleg Apr 11 '20 at 20:40
  • C'mon, if I was a reasonable person, would I be a programmer? Also - that's what I'm doing now. But I wanted my tests to be memory-only, without requiring external infrastructure. Hence the H2 motivation. – Michael Bar-Sinai Apr 12 '20 at 06:21
  • Okay, fair enough. Then your options are to only use basic SQL which will work on both databases or create your own version of H2 (actually shouldn't be that hard if all you need is to ignore functional index creation). You can also see the following answer which sums it up why it's generally speaking a bad idea https://stackoverflow.com/a/24230907/1398418 – Oleg Apr 12 '20 at 20:53

0 Answers0