From 4c4eb209b44d12170470bcc3098cbcf151f1bc38 Mon Sep 17 00:00:00 2001 From: RTUnreal Date: Wed, 22 May 2024 09:27:30 +0200 Subject: [PATCH] db: add database cleanup --- service/docker-compose.yml | 1 + service/init.sql | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/service/docker-compose.yml b/service/docker-compose.yml index e3b1418..3e41896 100644 --- a/service/docker-compose.yml +++ b/service/docker-compose.yml @@ -22,6 +22,7 @@ services: db: image: mariadb:latest + command: --event-scheduler=ON volumes: - ./init.sql:/docker-entrypoint-initdb.d/init.sql - ./data/:/var/lib/mysql:Z diff --git a/service/init.sql b/service/init.sql index 5341c11..ee5257b 100644 --- a/service/init.sql +++ b/service/init.sql @@ -17,6 +17,7 @@ CREATE TABLE user( created DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ); GRANT UPDATE(plan) on user TO "web"; +CREATE EVENT cleanup_user ON SCHEDULE EVERY 5 SECOND DO DELETE FROM user WHERE TIMESTAMPDIFF(SECOND, created, CURRENT_TIME) > 600; use premium_forum; CREATE TABLE post( @@ -25,4 +26,4 @@ CREATE TABLE post( created DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ); CREATE INDEX post_thread_IDX ON post(thread); - +CREATE EVENT cleanup_post ON SCHEDULE EVERY 5 SECOND DO DELETE FROM post WHERE TIMESTAMPDIFF(SECOND, created, CURRENT_TIME) > 600;