Best implementation for fully auditable data model?

前端 未结 6 2078
情深已故
情深已故 2021-02-06 14:36

My requirement is for a data model where a full audit trail is retained for changes to every attribute of every object. Object definitions are also fluid: new attributes can ap

6条回答
  •  南笙
    南笙 (楼主)
    2021-02-06 15:10

    Create a table that holds the names of the tables you want to audit (ex: AuditTable); minimum columns should be: TableName (varchar), RandomValue (float). Add a trigger on the AuditTable that will fire whenever a the RandomValue changes - this trigger's job will be to drop dynamically re-create the audit trigger for each table listed (TableName) in the AuditTable. The audit trigger (for each table) should insert into an AuditRecord table, which captures: the table name, primary key ID, action type (INSERT/UPDATE/DELETE), original field values and updated field values. If table structure changes, a simple update of the RandomValue in AuditTable will cause the triggers to re-generate. You will need to write the code that auto-generates the trigger for a given table; it is recommended that only 1 primary integer key is used on each table that is audited.

提交回复
热议问题