Update postgres field on date

Hi,

what would be the best way to update database field on a specific date? For an example, a project has a db fields status, start_date and end_date. When project is created, status is set to “active”, start_date is created and end_date is set to 30 days later. Now, how to update status to “inactive” on end_date automatically after 30 days? Should I create a cron job, it won’t do it at exact time but it will be close at least, or is there a better way?

Hi, if you can still remodel that table, consider using only start and end columns. Then create a view with status column derived from both dates.

You could always use Oban?

1 Like

Hi, if you can still remodel that table, consider using only start and end columns. Then create a view with status column derived from both dates.

This would be the easiest way but some business logic depends on that field so it’s not really a viable solution in this situation, but thanks anyway.

You could always use Oban?

I wasn’t aware of Oban before, this could solve the problem I have here and a couple of others too. Thanks for pointing me to it.

2 Likes