auditor
auditor copied to clipboard
Use the doctrine schema comparator to correctly determine the table diff
The default charset and collation are not present in the options array of the new columns and by just removing and re-adding the columns this change in the diff is lost thus generating equal alter table queries.
I've switched to the doctrine schema comparator to check for actual differences between the two table. This way it doesn't generate any sql the table stays the same.
Before change:
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;
After change:
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
[OK] Nothing to update.
Fixes https://github.com/DamienHarper/auditor-bundle/issues/553 Possibly fixes #241 also (to be tested as I don't use postgres in my project)