diff --git a/db/db.go b/db/db.go index d350229..722f090 100644 --- a/db/db.go +++ b/db/db.go @@ -28,7 +28,7 @@ func ClearUp(db *DbContainer, ii *inverted_index_2.InvertedIndex) error { // read ids as strings (helper) strIds := func(sql string) (ids []string, uintIds []uint32, err error) { - r, err := db.Query("SELECT id FROM files") + r, err := db.Query(sql) if err != nil { return } @@ -63,7 +63,7 @@ func ClearUp(db *DbContainer, ii *inverted_index_2.InvertedIndex) error { if len(danglingSegmentIds) > 0 { segmentIdsString := strings.Join(danglingSegmentIds, ",") - _, err = db.Exec(fmt.Sprintf("DELETE FROM file_segments_messages WHERE segmentId NOT IN (%s)", segmentIdsString)) + _, err = db.Exec(fmt.Sprintf("DELETE FROM file_segments_messages WHERE segmentId IN (%s)", segmentIdsString)) if err != nil { return err } diff --git a/db/db_test.go b/db/db_test.go index ef93fc1..aacde67 100644 --- a/db/db_test.go +++ b/db/db_test.go @@ -34,6 +34,8 @@ func TestClearUp(t *testing.T) { _, err = _db.Exec(`DELETE FROM files WHERE id=1`) require.NoError(t, err) + test_util.DumpTable(_db.DB, "files", 2) + test_util.DumpTable(_db.DB, "file_segments", 6) require.NoError(t, db.ClearUp(_db, ii)) // Assert files