views:

28

answers:

1

I have two types of users for my system, normal human users with a username / password, and delegation authorized accounts through OAuth (i.e. using a token identifier). The information that is stored for each is quite different, and are managed by different subsytems. They do however interact with the same tables / data within the system, so I need to maintain the audit trail regardless of whether human user, or token-based user modified the data.

My solution at the moment is to have a table called something like AuditableIdentity, and then have the two types inheriting off that table (either in the single table, or as two separate tables with 1 to 1 PK with AuditableIdentity. All operations would use the common AuditableIdentity PK for CreatedBy, ModifiedBy etc columns.

There isn't any FK constraint on the audit columns, so any text can go in there, but I want an easy way to easily determine whether it was a human or system that made the change, and joining to the one AuditableIdentity table seems like a clean way to do that?

Is there a best practice for this scenario? Is this an appropriate way of approaching the problem - or would you not bother with the common table and just rely on joins (to the two separate un-related user / token tables) later to determine which user type matches which audit records?

A: 

The solution with one parent tabel and 2 child table with the 1-1 PK-FK relation will work fine. You could add an extra field to AuditableIdentity table indicating if the row is a TokenIdentity or a NormalIdentity.

The PK of the AuditableIdentity is the key for all audit trails.

edosoft