im building a chat module for my site and I want to only show the users 50 last chats and when I add more than 50 delete the first chat and so on.
I made it work with the SpringScheduler. I check every 5 mins and if the database has more than 50 records I delete the all except last 50. is there a better way to do this?
EDIT
im using 10.3.16-MariaDB (SQL) and Spring boot 2.2.6.
I tried to add Triggers like this Answer but I'm getting this exception:
java.sql.SQLException: Can't update table 'chats' in stored function/trigger because it is already used by statement which invoked this stored function/trigger