Skip to content

Audit RPC

The audit log records changes made to organizations, units, memberships, roles, and invitations. Entries are written automatically by database triggers — no application code needs to call an audit-write function.


Returns recent audit log entries for an organization, ordered by most recent first.

Signature

public.get_audit_log(
p_org_id UUID,
p_limit INT
)
RETURNS TABLE (
id UUID,
actor_id UUID,
target_table TEXT,
target_id UUID,
action TEXT,
summary TEXT,
metadata JSONB,
created_at TIMESTAMPTZ
)

Parameters

ParameterDescription
p_org_idThe organization to fetch audit entries for
p_limitMaximum number of entries to return

Return columns

ColumnDescription
idUnique audit entry ID
actor_idUUID of the user who performed the action
target_tableThe database table that was affected (e.g. 'core.organizations', 'core.memberships')
target_idUUID of the specific record that was affected
actionThe type of change: 'INSERT', 'UPDATE', or 'DELETE'
summaryHuman-readable description of what changed
metadataJSONB field with additional context (e.g. old/new values, role names)
created_atTimestamp when the audit entry was written

Usage

// Fetch the last 50 audit entries
const { data, error } = await supabase.rpc('get_audit_log', {
p_org_id: 'org-uuid',
p_limit: 50
});
for (const entry of data) {
console.log(`${entry.created_at}${entry.actor_id}: ${entry.summary}`);
}

Audit entries are written automatically by database triggers when changes occur to:

  • Organizations — create, update, delete, metadata updates
  • Units — create, update, delete
  • Memberships — org and unit member add/remove/role-change
  • Roles — role assignments and changes
  • Invitations — create, accept, cancel

Application code does not write to the audit log directly.