SQLite Forum

Atomically initialize database
Login
You need to test for 1 before even trying to open the file, as SQLite will create it if it doesn't exist as soon as you do anything with the file.

Assuming you don't have two versions that need different initializations, I would just do each transaction worth as a chunk, start the transaction with a BEGIN IMMEDIATE so you know that no other version can be competing with you for initializing, and test if you need to do that phase. For the 'CREATE TABLE' phase, either just use CREATE TABLE IF NOT EXISTS or check for the tables you need if that might take too long (unlikely). If you need to populate the tables with data, again BEGIN IMMEDIATE, check if the data is there, and if not insert. 

Note, setting JPURNAL_MODE to WAL doesn't really need isolation unless you are flipping modes during initialization