ancient-vegetable-10556
11/08/2023, 9:55 PMbroad-processor-92400
11/09/2023, 3:11 AMsession
-scoped fixture that creates and deletes the database
b. doing this construction each time is slow, so we put the migrations into a PEX, hash it, and restore from a cached version $hashed_name = "CACHED:$hash"
, if we can, via:
i. to create the $random_name
database for this test run, optimistically execute CREATE DATABASE $random_name TEMPLATE $hashed_name
. If that succeeds, all done ✅ otherwise, continue...
ii. create the empty database CREATE DATABASE $random_name
iii. run the migrations in that database (now good for running tests ✅ )
iv. save the cache for next time: CREATE DATABASE $hashed_name TEMPLATE $random_name
, ignoring "already exists" errors, which might come from this happening concurrently and another process winning.
c. (NB. the cached DB is left lying around, only the $random_name
one is cleaned up)ancient-vegetable-10556
11/09/2023, 3:15 AMcurved-television-6568
11/09/2023, 3:35 PMhappy-kitchen-89482
11/09/2023, 5:43 PM