From 20f83572448187f806095ee0a8cc5b30bff72a93 Mon Sep 17 00:00:00 2001 From: terminaldweller Date: Sat, 15 Jun 2024 09:43:57 -0400 Subject: added watchlists --- scripts/entry_limit_trigger.pgsql | 19 ------------------- scripts/entry_limit_trigger.sql | 27 +++++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 19 deletions(-) delete mode 100644 scripts/entry_limit_trigger.pgsql create mode 100644 scripts/entry_limit_trigger.sql (limited to 'scripts') diff --git a/scripts/entry_limit_trigger.pgsql b/scripts/entry_limit_trigger.pgsql deleted file mode 100644 index d7d99c2..0000000 --- a/scripts/entry_limit_trigger.pgsql +++ /dev/null @@ -1,19 +0,0 @@ -CREATE OR REPLACE FUNCTION milla.janitor () - RETURNS TRIGGER - AS $$ -BEGIN - UPDATE - posts - SET - updated_at = now() - WHERE - id = NEW.id; - RETURN new; -END; -$$ -LANGUAGE plpgsql; - -CREATE TRIGGER janitor_trigger - AFTER INSERT ON milla.tables - EXECUTE PROCEDURE milla.janitor (); - diff --git a/scripts/entry_limit_trigger.sql b/scripts/entry_limit_trigger.sql new file mode 100644 index 0000000..a3d4887 --- /dev/null +++ b/scripts/entry_limit_trigger.sql @@ -0,0 +1,27 @@ +create function remove_old_entries() + returns trigger + as $$ +begin + if( + select + COUNT(*) + from + table_name) > 10000 then + delete from table_name + where id in( + select + id + from + table_name + order by + id asc + limit 1000); + end if; + return null; +end; +$$ +language plpgsql; + +create trigger remove_old_entries_trigger + after insert on table_name for each row + execute procedure remove_old_entries(); -- cgit v1.2.3