scala - How to test MySQL case sensitivity using H2 -


i'm developing scala/play application uses mysql. i've run issue application breaks when deployed our integration environment because sql queries application have case wrong tables , aliases. didn't catch in development because i'm on mac mysql case insensitive default. beyond configuring local environment case sensitive well, i'd unit tests fail when queries written have case wrong. i'm testing database h2 described play documentation. set database following code schema string has creation script:

def apply[t](block: database => t):unit = {   databases.withinmemory(      urloptions = map(        "mode" -> "mysql"      ),      config = map(        "logstatements" -> false      )    ){   database =>     evolutions.withevolutions(database, simpleevolutionsreader.fordefault(       evolution(         1,         schema,         ""       )     )){       block(database)     }   } } 

intuitively config map have option "casesensitive" -> true or i've been unable find documentation options there. know if h2 has configuration option , is?

that explained both h2 docs , play docs (which quoting h2 docs):

in mysql text columns case insensitive default, while in h2 case sensitive. h2 supports case insensitive columns well. create tables case insensitive texts, append ignorecase=true database url (example: jdbc:h2:~/test;ignorecase=true).

and play docs:

text comparison in mysql case insensitive default, while in h2 case sensitive (as in other databases). h2 support case insensitive text comparison, needs set separately, using set ignorecase true. affects comparison using =, like, regexp.

so, need change urloptions consider ignorecase parameter:

def apply[t](block: database => t): unit = {   databases.withinmemory(     urloptions = map(       "mode" -> "mysql",       "ignorecase" -> "true"     ),     config = map(       "logstatements" -> false     )   ) {     database =>       evolutions.withevolutions(database, simpleevolutionsreader.fordefault(         evolution(           1,           schema,           ""         )       )) {         block(database)       }   } } 

but, advocate against using different database engine when running integration tests. try use same database used in production since give tests more confidence.


Comments