From c4c09f0a9d451ddbe55410d5a8fe62b1f779486e Mon Sep 17 00:00:00 2001 From: "D. Berge" Date: Mon, 31 Aug 2020 13:09:57 +0200 Subject: [PATCH] Delete online data before importing sequence. The deferred import routing will delete any online data for any raw sequences that it imports. --- bin/datastore.py | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/bin/datastore.py b/bin/datastore.py index 7bbe0da..4ed78c9 100644 --- a/bin/datastore.py +++ b/bin/datastore.py @@ -137,7 +137,7 @@ class Datastore: else: cur = cursor - qry = "SELECT * FROM files;" + qry = "SELECT * FROM files WHERE hash NOT LIKE '*%';" cur.execute(qry) res = cur.fetchall() @@ -235,6 +235,18 @@ class Datastore: hash = self.add_file(filepath, cursor) incr = records[0]["point_number"] <= records[-1]["point_number"] + # Start by deleting any online data we may have for this sequence + # FIXME Factor this out into its own function + qry = """ + DELETE + FROM raw_lines rl + USING raw_lines_files rlf + WHERE + rl.sequence = rlf.sequence + AND rlf.hash = '*online*' + AND rl.sequence = %s; + """ + qry = """ INSERT INTO raw_lines (sequence, line, remarks, ntbp, incr) VALUES (%s, %s, '', %s, %s) @@ -341,6 +353,20 @@ class Datastore: hash = self.add_file(filepath, cursor) incr = p111.point_number(records[0]) <= p111.point_number(records[-1]) + # Start by deleting any online data we may have for this sequence + # FIXME Factor this out into its own function + qry = """ + DELETE + FROM raw_lines rl + USING raw_lines_files rlf + WHERE + rl.sequence = rlf.sequence + AND rlf.hash = '*online*' + AND rl.sequence = %s; + """ + + cursor.execute(qry, (fileinfo["sequence"],)) + qry = """ INSERT INTO raw_lines (sequence, line, remarks, ntbp, incr) VALUES (%s, %s, '', %s, %s)