sqlite-jdbc
sqlite-jdbc copied to clipboard
Allow running init SQL script for in-memory databases
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'
POC: https://github.com/xerial/sqlite-jdbc/pull/345
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...
FYI, we're using Flyway to init our DBs and it works with the in-memory instance.
I am using Flyway too, works like a charm on in-memory database.
Is this still necessary in 2022 ?