Who made a given change
martinov opened this issue · 2 comments
Feature request
Is your feature request related to a problem? Please describe.
A common requirement (at least on projects I'm working on) is to keep record of which user did a particular change. So we need to store the user id (auth.uid()
in supabase terms) somewhere in the audit.record_version
so that we know who's responsible for every single change.
Describe the solution you'd like
The simplest solution would be to add, let's say changed_by
column to the audit.record_version
table and modify audit.insert_update_delete_trigger()
to insert auth.uid()
into that column. Done, that'll do the job for us, but maybe I'm missing something and there might be cases where this won't work or is unnecessary?
Another option would be to add a third jsonb column to the audit.record_version
with metadata about the change. Then audit.enable_tracking()
might be extended to expect an optional second parameter, instructing the trigger what data the extension user wants to store in the metadata column for each change, and current user uid would be one of the options. But that's probably an overkill?
Describe alternatives you've considered
I can't think of an alternative way to keep the information on who made a change without modifying or forking the extension.
Additional context
I'll be glad to make a PR if the above makes sense and other people also find this feature useful.
We have this block in the extension setup
supa_audit/supa_audit--0.2.3.sql
Line 60 in c628d88
that detects if its in a supabase projects by looking for auth.uid()
and auth.role()
and adds columns in the audit table for each value if found.
I think that should handle what you're looking for
Heres the test case output as a more complete example for what that looks like in practice
Yep, this definitely satisfies my use case, sorry for the noise created by this issue!
I've only looked at the code from the article, should have browsed the repo more thoroughly.