How to update the updated_at field automatically
Hey! I'm working with supabase database and I need to create new table with update_at field and that field will be updated automatically on new change. I wondering if there is a better way to enable it rather than that I'll implement complete trigger snippet for that.
I'll probably need it for multiple migrations.
I found that postgresSQL have this
modadatetime extension but I'm ensure if it should work out of the box with the latest postgres.
https://www.postgresql.org/docs/current/contrib-spi.html#CONTRIB-SPI-MODDATETIMEPostgreSQL Documentation
F.41. spi — Server Programming Interface features/examples
F.41. spi — Server Programming Interface features/examples # F.41.1. refint — Functions for Implementing Referential Integrity F.41.2. autoinc — Functions for …
5 Replies
A trigger is the normal way.
Moddatetime is a trigger being added.
I see that the extension is available in supabase cloud but not enabled
should this new migration work?
You can just enable in the dashboard...
I'd have to go read the extension info again, I used it a couple of years ago. BUT I would typically plan to have a created_at and and ID column I don't want the user to change or other such columns so usually just role the updated_at into the same trigger for everything.
You can just enable in the dashboard...It's nice that the whole infra can be declared from the migratinos Like creating a buckets, enabling extensions
If you are using migrations that is certainly the way to go to allow moving to other instances easier.