From 9904eba5514543d91acd7e755a9aad168c1143e6 Mon Sep 17 00:00:00 2001 From: Hampus Carlsson Date: Mon, 22 Apr 2024 19:09:29 +0200 Subject: [PATCH] Fixes SQL error in GetClipsQualifyingForRemoval This commit: 16c0961738664f8fc5dbef203d6651258d2c173e did some cleanup of the GetClipsQualifyingForRemoval and removed a small hack used to get the main select with the n.. Causing the unit tests to fail. Adds back the AS statement the correct way, utilizing the built in features of gorm. --- internal/datastore/interfaces.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/datastore/interfaces.go b/internal/datastore/interfaces.go index fc8744cf..371b091d 100644 --- a/internal/datastore/interfaces.go +++ b/internal/datastore/interfaces.go @@ -214,7 +214,7 @@ func (ds *DataStore) GetClipsQualifyingForRemoval(minHours int, minClips int) ([ } // Main query to find clips qualifying for removal based on retention policy - err := ds.DB.Model(&Note{}). + err := ds.DB.Table("(?) AS n", ds.DB.Model(&Note{})). Select("n.ID, n.scientific_name, n.clip_name, sub.num_recordings"). Joins("INNER JOIN (?) AS sub ON n.ID = sub.ID", subquery). Where("strftime('%s', 'now') - strftime('%s', begin_time) > ?", minHours*3600). // Convert hours to seconds for comparison