aboutsummaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
authorterminaldweller <devi@terminaldweller.com>2024-06-15 13:43:57 +0000
committerterminaldweller <devi@terminaldweller.com>2024-06-15 13:43:57 +0000
commit20f83572448187f806095ee0a8cc5b30bff72a93 (patch)
tree4c36696a6629b8dc6615fc6e98a67872923ce86d /scripts
parentadded a shell.nix for pgformatter, and a wip trigger for db size maintenance (diff)
downloadmilla-20f83572448187f806095ee0a8cc5b30bff72a93.tar.gz
milla-20f83572448187f806095ee0a8cc5b30bff72a93.zip
added watchlists
Diffstat (limited to 'scripts')
-rw-r--r--scripts/entry_limit_trigger.pgsql19
-rw-r--r--scripts/entry_limit_trigger.sql27
2 files changed, 27 insertions, 19 deletions
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();