sqlite-jdbc icon indicating copy to clipboard operation
sqlite-jdbc copied to clipboard

Allow running init SQL script for in-memory databases

Open isen-ng opened this issue 7 years ago • 4 comments

Often, in-memory databases are used for unit testing, and therefore the database needs to already have a certain schema.

You can argue that I can run the SQL script to create the schema after loading the datasource and before running the tests. This case would require the code to know what kind of DataSource it is, and run the appropriate SQL schema creation scripts (i test my code against a few database types, H2, MySql and SQLite).

I would like a way to allow the JDBC connection string to also specify a resource sql to load, so that all the changes needed to run the test against a different database type is limited to the configuration.

An example will be H2's JDBC string:

jdbc:h2:mem:FooDB;MODE=MYSQL;IGNORECASE=TRUE;INIT=RUNSCRIPT FROM 'classpath:h2-database-schema-create.sql'

isen-ng avatar Jun 01 '18 05:06 isen-ng

POC: https://github.com/xerial/sqlite-jdbc/pull/345

isen-ng avatar Jun 01 '18 07:06 isen-ng

This sure would be nice to have! Sadly looks like it's been sitting idle for 3 years 😢 I would definitely use this functionality in the Quill library unit tests. Pretty sure many others would too...

deusaquilus avatar Mar 12 '21 03:03 deusaquilus

FYI, we're using Flyway to init our DBs and it works with the in-memory instance.

guizmaii avatar Oct 08 '21 03:10 guizmaii

I am using Flyway too, works like a charm on in-memory database.

Is this still necessary in 2022 ?

gotson avatar Jul 28 '22 10:07 gotson