Skip to content

Commit

Permalink
Add support for multiple schemas
Browse files Browse the repository at this point in the history
  • Loading branch information
edineivaldameri committed Nov 4, 2024
1 parent 29c8bda commit f031e3b
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,12 @@ With this, a file called audit.php will be available in the settings directory,

If you want to temporarily disable audits, just insert in your .env: `AUDIT_ENABLED=false`.

## Ignoring tables
### Ignoring tables
When installing and publishing the configuration file, you can insert tables that you want to ignore when performing the audit, just insert their names in the `skip` property.

### Multiple schemas
You can configure multiple database schemas by adding each of them to the `schemas` property in the settings.

But remember you can only ignore these tables before running the `php artisan audit:install` command.

## Uninstall
Expand Down
3 changes: 3 additions & 0 deletions config/audit.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,7 @@
'migrations',
'public.migrations',
],
'schemas' => [
'public',
],
];
7 changes: 6 additions & 1 deletion src/Concerns/AuditTrigger.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,12 @@ private function getSkippedTables(): array
*/
private function getAuditedTables(): array
{
$tables = DB::select('SELECT table_schema, table_name FROM information_schema.tables WHERE table_type = \'BASE TABLE\' AND table_schema IN (\'cadastro\', \'modules\', \'pmieducar\', \'portal\', \'public\', \'relatorio\');');

$schemas = implode(', ', array_map(function ($schema) {
return "'{$schema}'";
}, config('audit.schemas', ['public'])));

$tables = DB::select('SELECT table_schema, table_name FROM information_schema.tables WHERE table_type = \'BASE TABLE\' AND table_schema IN (' . $schemas . ');');

$return = [];
foreach ($tables as $table) {
Expand Down

0 comments on commit f031e3b

Please sign in to comment.