Subject: | why is *_audit_log id col an auto-inc ? |
In DBIx::Class::Schema::Journal::DB in journal_update_or_create_log_entry we use update_or_create but pass in a
value for "id". This is contrary to the DBIx::Class documentation which says this should not be done for auto
incrementing PK type columns.
I actually think the mistake here is not that we pass a value for "id" but that "id" is configured as an auto-inc col
in the table. What the value of this column contains is in fact the "id" of the row which has been created/deleted.
For example given table username and username_audit_log, the "id" col of username_audit_log is a copy of the
"id" of username.
So should we remove the auto inc on the *_audit_log id? We should not set a FK constraint because the original
row is potentially being deleted. Actually the FK could be "id" col of *_audit_history but there might be a race
condition there, I'm not sure.
Anyway, I thought I'd log this to see if anyone else is working on this code and whether they might have an
opinion. I know that there aren't too many eyes on the Journal code normally :-}
I also think we might do with better checking in journal_update_or_create_log_entry just in case the condition
arises where a delete is logged without a corresponding previous create - this would fail because of the not null
constraint on create_id.
--
regards,
oliver.