summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTor Andersson <tor@ccxvii.net>2024-03-24 16:17:58 +0100
committerTor Andersson <tor@ccxvii.net>2024-03-24 16:18:17 +0100
commit6d56af566dc688e3f2af800dbd17950b06297fe7 (patch)
tree72b12634383b6061d877a48afe73e7a73058a799
parente194f43c75b14c5307c030c01ea77af789d4afc7 (diff)
downloadserver-6d56af566dc688e3f2af800dbd17950b06297fe7.tar.gz
Add script to purge game snapshots and archive old games.
-rw-r--r--tools/purge.sql35
1 files changed, 35 insertions, 0 deletions
diff --git a/tools/purge.sql b/tools/purge.sql
new file mode 100644
index 0000000..e48e305
--- /dev/null
+++ b/tools/purge.sql
@@ -0,0 +1,35 @@
+-- Prune game snapshot and game state data to save database space.
+
+create temporary view prune_snap_list as
+ select
+ distinct game_id
+ from
+ game_snap
+ where
+ game_id in (
+ select game_id from games
+ where status=2 and date(mtime) < date('now', '-7 days')
+ )
+ ;
+
+create temporary view prune_all_list as
+ select
+ distinct game_id
+ from
+ games
+ where
+ game_id in (
+ select game_id from games
+ where status=2 and date(mtime) < date('now', '-28 days')
+ )
+ ;
+
+begin;
+
+select 'PURGE SNAPS FROM ' || count(1) from prune_snap_list;
+delete from game_snap where game_id in (select game_id from prune_snap_list);
+
+select 'PURGE ALL FROM ' || count(1) from prune_all_list;
+update games set status = 3 where game_id in (select game_id from prune_all_list);
+
+commit;