Skip to content
Snippets Groups Projects
Verified Commit 51bec588 authored by Michal 'vorner' Vaner's avatar Michal 'vorner' Vaner
Browse files

Plugin history: Duplicate the last event on cleanup

That way we are sure we have the current state still in the table. Also,
when deleting several days old events, we still have recent history.
This is to prevent the last event of too long active client from
dropping out.
parent ff1a013e
Branches
No related merge requests found
......@@ -10,6 +10,10 @@ DATE=$(date -d "$CLEAN_DAYS days ago" "+'%Y-%m-%d'")
(
echo "BEGIN;"
# Duplicate the last plugin history event. This way, even if
# the client is connected for a long time, we won't lose all
# the events and we shall know what its state is now or a day ago
echo "INSERT INTO plugin_history (client, name, timestamp, version, hash, active) SELECT DISTINCT ph.client, ph.name, CURRENT_TIMESTAMP AT TIME ZONE 'UTC', ph.version, ph.hash, ph.active FROM plugin_history AS ph JOIN (SELECT client, name, MAX(timestamp) AS timestamp FROM plugin_history GROUP BY client, name) AS latest ON ph.client = latest.client AND ph.name = latest.name AND ph.timestamp = latest.timestamp;"
for TABLE in $TABLES ; do
echo "DELETE FROM $TABLE WHERE timestamp < $DATE;"
done
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment