Trigger delete for old instances? #174
|
Is it possible to define a trigger which removes model instances after X days of last update? |
Answered by
wesleykendall
Sep 8, 2024
Replies: 1 comment
|
Short answer is no - triggers are driven by events on the table, so this problem doesn't map very well. You could make a statement-level trigger on your table for any event, cleaning up old rows. This would impact performance whenever there is clean-up to do. Your data would remain uncleaned until there were events on the table. I would recommend a task scheduler here. If you want to keep all of this in Postgres and not something like Celery, you could consider the pgcron extension, which is supported by AWS and many other DB hosts |
0 replies
Answer selected by
wesleykendall
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Short answer is no - triggers are driven by events on the table, so this problem doesn't map very well.
You could make a statement-level trigger on your table for any event, cleaning up old rows. This would impact performance whenever there is clean-up to do. Your data would remain uncleaned until there were events on the table.
I would recommend a task scheduler here. If you want to keep all of this in Postgres and not something like Celery, you could consider the pgcron extension, which is supported by AWS and many other DB hosts