Index: db.scm ================================================================== --- db.scm +++ db.scm @@ -1724,32 +1724,34 @@ ;; a. If have tests that are not deleted, set state='unknown' ;; b. .... ;; (define (db:clean-up dbdat) ;; (debug:print 0 *default-log-port* "WARNING: db clean up not fully ported to v1.60, cleanup action will be on megatest.db") - (let* ((db (db:dbdat-get-db dbdat)) + (let* ((keep-record-age ( - (current-seconds) (common:hms-string->seconds (or (configf:lookup *configdat* "setup" "delete-record-age") "30d")))) + (db (db:dbdat-get-db dbdat)) (count-stmt (sqlite3:prepare db "SELECT (SELECT count(id) FROM tests)+(SELECT count(id) FROM runs);")) (statements (map (lambda (stmt) (sqlite3:prepare db stmt)) (list ;; delete all tests that belong to runs that are 'deleted' - "DELETE FROM tests WHERE run_id in (SELECT id FROM runs WHERE state='deleted');" + (conc "DELETE FROM tests WHERE run_id in (SELECT id FROM runs WHERE state='deleted') and last_update < " keep-record-age ";") ;; delete all tests that are 'DELETED' - "DELETE FROM tests WHERE state='DELETED';" + (conc "DELETE FROM tests WHERE state='DELETED' and last_update < " keep-record-age " ;") ;; delete all tests that have no run - "DELETE FROM tests WHERE run_id NOT IN (SELECT DISTINCT id FROM runs);" + (conc "DELETE FROM tests WHERE run_id NOT IN (SELECT DISTINCT id FROM runs) and last_update < " keep-record-age "; ") ;; delete all runs that are state='deleted' - "DELETE FROM runs WHERE state='deleted';" + (conc "DELETE FROM runs WHERE state='deleted' and last_update < " keep-record-age ";") ;; delete empty runs - "DELETE FROM runs WHERE id NOT IN (SELECT DISTINCT r.id FROM runs AS r INNER JOIN tests AS t ON t.run_id=r.id);" + (conc "DELETE FROM runs WHERE id NOT IN (SELECT DISTINCT r.id FROM runs AS r INNER JOIN tests AS t ON t.run_id=r.id) and last_update < " keep-record-age ";") ;; remove orphaned test_rundat entries - "DELETE FROM test_rundat where test_id NOT IN (SELECT id FROM tests);" + (conc "DELETE FROM test_rundat where test_id NOT IN (SELECT id FROM tests) ;") ;; - "DELETE FROM test_steps WHERE test_id NOT IN (SELECT id FROM tests);" + (conc "DELETE FROM test_steps WHERE test_id NOT IN (SELECT id FROM tests) and last_update < " keep-record-age " ;") )))) ;; (db:delay-if-busy dbdat) + ;(debug:print-info 0 *default-log-port* statements) (sqlite3:with-transaction db (lambda () (sqlite3:for-each-row (lambda (tot) (debug:print-info 0 *default-log-port* "Records count before clean: " tot))