July 2, 2018
Start with a super simple data model:
CREATE TABLE kv ( id BIGINT(22) NOT NULL AUTO_INCREMENT, k VARCHAR(255) NOT NULL, v LONGBLOB NOT NULL, PRIMARY KEY (`id`), UNIQUE KEY u_k (`k`) ) Engine=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin Suppose we want to audit “changes” to this data model.
Approach 1: kv_log add data model like
CREATE TABLE `kv_log` ( id BIGINT(22) NOT NULL AUTO_INCREMENT, changed_at TIMESTAMP NOT NULL, k VARCHAR(255) NOT NULL, old_v LONGBLOB NOT NULL, new_v LONGBLOB NOT NULL, ) current value query: unchanged