Skip to content

Commit

Permalink
🔧 Add deletion of indexd gfs on delete study resource
Browse files Browse the repository at this point in the history
  • Loading branch information
znatty22 committed May 21, 2018
1 parent 712c0f3 commit b77cc5c
Showing 1 changed file with 21 additions and 8 deletions.
29 changes: 21 additions & 8 deletions dataservice/api/study/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,23 +133,36 @@ def delete(self, kf_id):
if st is None:
abort(404, 'could not find {} `{}`'.format('study', kf_id))

db.session.delete(st)
# -- Delete genomic_files from indexd --
from dataservice.api.participant.models import Participant
from dataservice.api.biospecimen.models import Biospecimen
from dataservice.api.genomic_file.models import GenomicFile
from dataservice.api.common.model import delete_indexd
# GenomicFiles for this study
gfs = (GenomicFile.query.join(GenomicFile.biospecimen)
.join(Biospecimen.participant)
.filter(Participant.study_id == kf_id)).all()
# Delete from indexd
[delete_indexd(None, None, gf) for gf in gfs]

# Delete study - will execute db cascade delete
Study.query.filter_by(kf_id=kf_id).delete()
db.session.commit()

# Delete orphans
# -- Delete orphans ---
# Families
from dataservice.api.family.models import Family
q = (db.session.query(Family)
.filter(~Family.participants.any()))
q.delete(synchronize_session=False)
(db.session.query(Family)
.filter(~Family.participants.any())).delete(
synchronize_session=False)

# Sequencing experiments
from dataservice.api.sequencing_experiment.models import (
SequencingExperiment
)
q = (db.session.query(SequencingExperiment)
.filter(~SequencingExperiment.genomic_files.any()))
q.delete(synchronize_session=False)
(db.session.query(SequencingExperiment)
.filter(~SequencingExperiment.genomic_files.any())).delete(
synchronize_session=False)

db.session.commit()

Expand Down

0 comments on commit b77cc5c

Please sign in to comment.