Change Management

Database schemas change over time. Auditing has tools to keep your changes in-line with both databases.

Adding a new field or audited entity

Your first step is to make the change to the entity and consequently the column for the new field. These instructions do not describe change management on your target database as that is outside the scope of auditing.

Update the audit database with the new field

Run the orm schema tool:

php public/index.php orm:schema-tool:update --object-manager=doctrine.entitymanager.orm_default

This command requires a –force or –dump-sql parameter too. This part of the process is no different than managing your target database with the schema tool.

Update the audit database fixtures

After running the schema tool and changing the database you must re-run the fixtures for the audit database. These fixtures are smart and will not produce duplicate data:

php public/index.php data-fixture:import zf-doctrine-audit

Update the target database triggers

The triggers generated by zf-doctrine-audit drop any existing triggers. This allows us to re-run the trigger tool to generate updated sql. The next step is to run the generated triggers on your target database. This is not done directly on the database through code but instead the trigger code is output by the tool. We will be piping this directly to the target database:

php public/index.php audit:trigger-tool:create

Then pipe this output to the target database such as:

php public/index.php audit:trigger-tool:create | mysql -u user -p123 -h mysql target_database

Your audit database is now up to date with your target database.

Removing a field from an entity

zf-doctrine-audit does not try to archive data for fields which have been removed from the target database. If you want to preserve data for a field or entity which you are removing from the target database you must dump that data and preserve it yourself.

After you have saved the old audit data you may follow the same steps above for Adding a new field or audited entity.