DBAL
Store the entries in a SQL table through a Doctrine DBAL connection.
Overview
| Package | Reads | Purge | Setup |
|---|---|---|---|
doctrine/dbal, doctrine/doctrine-bundle | Yes | Yes | Yes |
The commands, the EasyAdmin viewer and ReaderInterface can read this output. audit-log:purge and audit-log:setup work with it. See Outputs.
Enable the output
symfonycorp_audit_log:
outputs:
dbal:
connection: ~ # null = the default connection
table_name: audit_logconnection: the name of the DBAL connection. Default:null, the default connection.table_name: the table of the entries. Default:audit_log.auto_setup: create the table on the first write. Default:false. See Create the table.
Database account
Give the dbal output its own connection, with an account that can only insert and select rows. Then the application cannot change or delete an entry. Run audit-log:setup and audit-log:purge with an account that can also create tables and delete rows, for example with another database URL in their environment.
Create the table
The output does not create its table by default. Without it, a write can fail, and the bundle only logs the failure.
With Doctrine migrations, the output adds its table to the Doctrine schema of its connection. Generate a migration:
$ bin/console doctrine:migrations:diffOtherwise, run the setup command when you deploy. It does not change a table that exists. It fails with a non-zero exit code on an error:
$ bin/console audit-log:setup --output=dbalUse either Doctrine migrations or audit-log:setup, not both. The table has indexes on (occurred_at), (source, occurred_at) and (action, occurred_at).
In development and in tests, you can let the output create its table on the first write. Do not use it in production:
symfonycorp_audit_log:
outputs:
dbal:
auto_setup: trueIndexed context - the table has one column for each key of indexed_context. When you change this list, generate a Doctrine migration before you deploy. Without the new columns, the writes fail. See Filter by context.