From 591b91194a1346a3f1cbcb8b6fb6e674091242be Mon Sep 17 00:00:00 2001 From: Nicolas Mowen Date: Mon, 6 Nov 2023 06:43:26 -0700 Subject: [PATCH] Cleanup existing timeline entries (#8495) * Cleanup existing timeline entries for beta users * Formatting --- frigate/app.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/frigate/app.py b/frigate/app.py index c5357e400..1535eeaf6 100644 --- a/frigate/app.py +++ b/frigate/app.py @@ -279,6 +279,17 @@ class FrigateApp: except PermissionError: logger.error("Unable to write to /config to save DB state") + def cleanup_timeline_db(db: SqliteExtDatabase) -> None: + db.execute_sql( + "DELETE FROM timeline WHERE source_id NOT IN (SELECT id FROM event);" + ) + + try: + with open(f"{CONFIG_DIR}/.timeline", "w") as f: + f.write(str(datetime.datetime.now().timestamp())) + except PermissionError: + logger.error("Unable to write to /config to save DB state") + # Migrate DB location old_db_path = DEFAULT_DB_PATH if not os.path.isfile(self.config.database.path) and os.path.isfile( @@ -294,6 +305,11 @@ class FrigateApp: router = Router(migrate_db) router.run() + # this is a temporary check to clean up user DB from beta + # will be removed before final release + if not os.path.exists(f"{CONFIG_DIR}/.timeline"): + cleanup_timeline_db(migrate_db) + # check if vacuum needs to be run if os.path.exists(f"{CONFIG_DIR}/.vacuum"): with open(f"{CONFIG_DIR}/.vacuum") as f: