summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorTor Andersson <tor@ccxvii.net>2024-07-02 20:53:49 +0200
committerTor Andersson <tor@ccxvii.net>2024-07-23 13:47:44 +0200
commitdda6b1d635023d43f6e8ea63936824f4b2ef17ef (patch)
tree84905bbb452be824397a78124e4587d8e368d03b /tools
parentf93ebad5249418fc19d8cda818805bb0f5ede727 (diff)
downloadserver-dda6b1d635023d43f6e8ea63936824f4b2ef17ef.tar.gz
Fix purge script.
Diffstat (limited to 'tools')
-rw-r--r--tools/archive.sql2
-rw-r--r--tools/purge.sql14
2 files changed, 10 insertions, 6 deletions
diff --git a/tools/archive.sql b/tools/archive.sql
index 149d161..e8b5458 100644
--- a/tools/archive.sql
+++ b/tools/archive.sql
@@ -1,5 +1,7 @@
-- Make a copy of finished games in a separate archive database.
+pragma busy_timeout=10000;
+
attach database 'db' as live;
attach database 'archive.db' as archive;
diff --git a/tools/purge.sql b/tools/purge.sql
index e48e305..3e0c898 100644
--- a/tools/purge.sql
+++ b/tools/purge.sql
@@ -1,13 +1,15 @@
-- Prune game snapshot and game state data to save database space.
+attach database 'db' as live;
+
create temporary view prune_snap_list as
select
distinct game_id
from
- game_snap
+ live.game_snap
where
game_id in (
- select game_id from games
+ select game_id from live.games
where status=2 and date(mtime) < date('now', '-7 days')
)
;
@@ -16,10 +18,10 @@ create temporary view prune_all_list as
select
distinct game_id
from
- games
+ live.games
where
game_id in (
- select game_id from games
+ select game_id from live.games
where status=2 and date(mtime) < date('now', '-28 days')
)
;
@@ -27,9 +29,9 @@ create temporary view prune_all_list as
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);
+delete from live.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);
+update live.games set status = 3 where game_id in (select game_id from prune_all_list);
commit;