Skip to content

Commit 08be19b

Browse files
authored
Merge pull request #18 from domonik/dev
fixes db cleanup
2 parents f15401f + b6263e0 commit 08be19b

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

RNAdist/dashboard/helpers.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,12 @@ def __init__(self, config, max_cache_size:int =8):
5151
def delete_unfinished_jobs(self):
5252
with self.engine.connect() as conn:
5353
conn.execute(
54-
text("DELETE FROM jobs WHERE status != 'finished';")
54+
text("""
55+
DELETE FROM submissions
56+
WHERE hash IN (
57+
SELECT hash FROM jobs WHERE status != 'finished'
58+
);
59+
""")
5560
)
5661
conn.commit()
5762

@@ -424,7 +429,7 @@ def create_database(self, create_file_if_missing=True):
424429
header TEXT NOT NULL,
425430
UNIQUE (hash, user_id),
426431
UNIQUE (user_id, header),
427-
FOREIGN KEY (hash) REFERENCES submissions(hash)
432+
FOREIGN KEY (hash) REFERENCES submissions(hash) ON DELETE CASCADE
428433
);
429434
"""
430435

@@ -434,7 +439,7 @@ def create_database(self, create_file_if_missing=True):
434439
hash {blob_type} NOT NULL,
435440
structure {blob_type} NOT NULL,
436441
num_samples INTEGER NOT NULL,
437-
FOREIGN KEY (hash) REFERENCES submissions(hash),
442+
FOREIGN KEY (hash) REFERENCES submissions(hash) ON DELETE CASCADE,
438443
UNIQUE(hash, structure)
439444
);
440445
"""

0 commit comments

Comments
 (0)