auditor-bundle icon indicating copy to clipboard operation
auditor-bundle copied to clipboard

audit:schema:update always produces queries even without changes

Open acrobat opened this issue 1 month ago • 1 comments

Q A
auditor-bundle version 6.2.1
PHP version 8.4.13
Database MySQL

Versions:

damienharper/auditor                          3.3.4
damienharper/auditor-bundle                   6.2.1

Summary

I did a clean setup of the bundle and initialized the audit schema to a separate database storage. When executing the audit:schema:update command, it always produces alter table statements although no changes are present. So it seems that the diff against the current schema isn't working correctly

Current behavior

audit:schema:update --dump-sql
 The following SQL statements will be executed:

     CREATE TABLE brand_audit (id INT UNSIGNED AUTO_INCREMENT NOT NULL, type VARCHAR(10) NOT NULL, object_id VARCHAR(255) NOT NULL, discriminator VARCHAR(255) DEFAULT NULL, transaction_hash VARCHAR(40) DEFAULT NULL, diffs JSON DEFAULT NULL, blame_id VARCHAR(255) DEFAULT NULL, blame_user VARCHAR(255) DEFAULT NULL, blame_user_fqdn VARCHAR(255) DEFAULT NULL, blame_user_firewall VARCHAR(100) DEFAULT NULL, ip VARCHAR(45) DEFAULT NULL, created_at DATETIME NOT NULL, INDEX type_ed4e375f24635767d50412c3733f9a3c_idx (type), INDEX object_id_ed4e375f24635767d50412c3733f9a3c_idx (object_id), INDEX discriminator_ed4e375f24635767d50412c3733f9a3c_idx (discriminator), INDEX transaction_hash_ed4e375f24635767d50412c3733f9a3c_idx (transaction_hash), INDEX blame_id_ed4e375f24635767d50412c3733f9a3c_idx (blame_id), INDEX created_at_ed4e375f24635767d50412c3733f9a3c_idx (created_at), PRIMARY KEY (id)) DEFAULT CHARACTER SET utf8mb4;

audit:schema:update --force

audit:schema:update --dump-sql
 The following SQL statements will be executed:

     ALTER TABLE brand_audit CHANGE type type VARCHAR(10) NOT NULL, CHANGE object_id object_id VARCHAR(255) NOT NULL, CHANGE discriminator discriminator VARCHAR(255) DEFAULT NULL, CHANGE transaction_hash transaction_hash VARCHAR(40) DEFAULT NULL, CHANGE blame_id blame_id VARCHAR(255) DEFAULT NULL, CHANGE blame_user blame_user VARCHAR(255) DEFAULT NULL, CHANGE blame_user_fqdn blame_user_fqdn VARCHAR(255) DEFAULT NULL, CHANGE blame_user_firewall blame_user_firewall VARCHAR(100) DEFAULT NULL, CHANGE ip ip VARCHAR(45) DEFAULT NULL;

How to reproduce

See commands above ☝️

Expected behavior

When executing the audit:schema:update command when nothing in the app is changes, no sql queries should be produced.

acrobat avatar Nov 05 '25 09:11 acrobat

It seems that this was an issue in the library and not in the bundle. I've provided a PR with a suggestion to fix this https://github.com/DamienHarper/auditor/pull/252

acrobat avatar Nov 05 '25 10:11 acrobat