oq-engine
oq-engine copied to clipboard
Investigate if foreign keys are off in the oqdb
When creating the db, the engine correctly sets PRAGMA foreign_keys = ON
, however it happened that deleting a job did not delete its outputs, causing an integrity error like this one:
django.db.utils.IntegrityError: The row in table 'output' with primary key '40864' has an invalid foreign key:
output.oq_job_id contains a value '99955133' that does not have a corresponding value in job.id.
Perhaps we have an old version of sqlite3 not compiled with foreign key support? To check, simply run a calculation, delete it and see if the outputs are deleted or not.
To read: https://www.sqlite.org/foreignkeys.html
On oqdb I ran a calculation from the command line, then I deleted it (still from the command line) and the queries to check orphans confirmed that outputs and log elements pointing to that job had been removed. So everything seems to be working fine when a calculation completes and then it is removed. Perhaps we need to test some corner cases.
I double checked again, running a calculation, then deleting it and checking if any orphans remained in the db, with select distinct oq_job_id from output left join job on job.id=oq_job_id where job.id is null;
and it returned none. Therefore the behavior is correct.