I would like to automate the process of partitioning a Zabbix 3.4 Database using PostgreSQL's Native Range Partitioning.

Would it be wiser to write a SQL function to perform the following below or to use a shell/python script?

* Make sure at least one partition is created ahead of what's needed.
* Delete any partition older than *x* weeks/months; for `history` 7 days and for `trends` 1 year