Unverified Commit 9b2783fa authored by averyv's avatar averyv
Browse files

pihole-ftl: Fix log deleter service creating an empty database

If it runs before the main service itself, the sqlite command may create an
empty database, causing the main service to not run the initial database setup.
parent 54b5d8a3
Loading
Loading
Loading
Loading
+6 −1
Original line number Diff line number Diff line
@@ -415,11 +415,16 @@ in
        script =
          let
            days = toString cfg.queryLogDeleter.age;
            database = "${cfg.stateDirectory}/pihole-FTL.db";
            database = cfg.settings.files.database;
          in
          ''
            set -euo pipefail

            # Avoid creating an empty database file if it doesn't yet exist
            if [ ! -f "${database}" ]; then
              exit 0;
            fi

            echo "Deleting query logs older than ${days} days"
            ${getExe cfg.package} sqlite3 "${database}" "DELETE FROM query_storage WHERE timestamp <= CAST(strftime('%s', date('now', '-${days} day')) AS INT); select changes() from query_storage limit 1"
          '';