diff --git a/pepdbagent/modules/project.py b/pepdbagent/modules/project.py index d56bb12..b3e89ec 100644 --- a/pepdbagent/modules/project.py +++ b/pepdbagent/modules/project.py @@ -1351,3 +1351,19 @@ def restore( tag=tag, user=user or namespace, ) + + def clean_history(self, days: int = 90) -> None: + """ + Delete all history data that is older then 3 month, or specific number of days + + :param days: number of days to keep history data + :return: None + """ + + with Session(self._sa_engine) as session: + session.execute( + delete(HistoryProjects).where( + HistoryProjects.update_time < (datetime.datetime.now() - datetime.timedelta(days=days)) + ) + ) + session.commit()