Database - Postgres
So I am very new to Ruby on rails and a Jr. developer so not very much aware of this task.
I have a PLSQL query which checks if there is a child whose age is more than 5 from the current date. so this is connected to. another table people. You can read the query, (name of the original tables have been changed, people and children are demo based)
I want to run a cron job once per day which checks this.
I have gone through many questions, but I am not able to understand, that how and where should I write my PLSQL query and how to use it in my cron job using whenever gem.
select ch.person_id as child_id ,
(abs(current_date::date -
to_char(to_timestamp(ppl.date_of_birth),'YYYY-MM-DD')::timestamp::date) / 365) as current_age
from children as ch inner join people as ppl
on ch.person_id = ppl.id
where
((abs(current_date -
to_char(to_timestamp(ppl.date_of_birth),'YYYY-MM-DD')::timestamp::date)) / 365 >= 5) limit 500;
I want to run this query every single day once as a cron job.
So how do I do this using whenever gem? Where and how do I write this query in my project? How do I connect this query to my cron job?
I am stuck in this for days, thanks in advance.