Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add db-audit file as publish file. #62

Merged
merged 1 commit into from
Jul 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 11 additions & 14 deletions config/db-auditor.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
<?php
// config for Vcian/LaravelDbAuditor
use Vcian\LaravelDBAuditor\Constants\Constant;

return [
'db_name' => database_name(),
/*
|
|--------------------------------------------------------------------------
| Skip tables
|--------------------------------------------------------------------------
|
| Specify the tables that you want to skip auditing
|
|
*/

'skip_tables' => [ // Add table name that you want to skip
'cache',
'sqlite_sequence',
Expand All @@ -15,17 +24,5 @@
'jobs',
'queue_job',
'queue_failed_jobs',
],
'mysql_commands' => [
Constant::STANDARD_COMMAND,
Constant::CONSTRAINT_COMMAND,
Constant::SUMMARY_COMMAND,
Constant::TRACK_COMMAND,
],
'sqlite_commands' => [
Constant::STANDARD_COMMAND,
Constant::CONSTRAINT_COMMAND,
Constant::SUMMARY_COMMAND,
Constant::TRACK_COMMAND,
]
];
7 changes: 4 additions & 3 deletions src/Commands/DBAuditCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Vcian\LaravelDBAuditor\Commands;

use Illuminate\Console\Command;
use League\Flysystem\Config;
use Vcian\LaravelDBAuditor\Constants\Constant;

use function Laravel\Prompts\select;
Expand All @@ -28,9 +29,9 @@ class DBAuditCommand extends Command
*/
public function handle(): void
{
$commands = match (connection_driver()) {
Constant::SQLITE_DB => config('db-auditor.sqlite_commands'),
Constant::MYSQL_DB => config('db-auditor.mysql_commands'),
$commands = match (connection_driver()) {
Constant::SQLITE_DB => config('audit.sqlite_commands'),
Constant::MYSQL_DB => config('audit.mysql_commands'),
};

$commandSelect = select(
Expand Down
30 changes: 30 additions & 0 deletions src/Config/audit.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php
// config for Vcian/LaravelDbAuditor
use Vcian\LaravelDBAuditor\Constants\Constant;

return [
'skip_tables' => [ // Add table name that you want to skip
'cache',
'sqlite_sequence',
'migrations',
'migrations_history',
'sessions',
'password_resets',
'failed_jobs',
'jobs',
'queue_job',
'queue_failed_jobs',
],
'mysql_commands' => [
Constant::STANDARD_COMMAND,
Constant::CONSTRAINT_COMMAND,
Constant::SUMMARY_COMMAND,
Constant::TRACK_COMMAND,
],
'sqlite_commands' => [
Constant::STANDARD_COMMAND,
Constant::CONSTRAINT_COMMAND,
Constant::SUMMARY_COMMAND,
Constant::TRACK_COMMAND,
]
];
44 changes: 39 additions & 5 deletions src/Providers/DBAuditorServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,28 +19,62 @@ class DBAuditorServiceProvider extends ServiceProvider
*/
public function register(): void
{
$this->commands($this->commands);

$this->registerConfig();
}

/**
* Bootstrap services.
*/
public function boot(): void
{
$this->publishes([
__DIR__ . '/../resource/images' => public_path('auditor/icon'),
], 'public');
if ($this->app->runningInConsole()) {
$this->registerCommands();
$this->publishConfigs();
}

$this->loadViewsFrom(__DIR__ . '/../views', 'DBAuditor');
$this->loadRoutesFrom(__DIR__ . '/../../routes/web.php');
$this->loadRoutesFrom(__DIR__ . '/../../routes/api.php');
$this->loadHelpers();
$this->loadTranslationsFrom(__DIR__ . '/../Lang/', 'Lang');

}

/**
* Register config
* @return void
*/
protected function registerConfig(): void
{
$this->mergeConfigFrom(__DIR__ . '/../../config/db-auditor.php', 'db-auditor');
$this->mergeConfigFrom(__DIR__ . '/../Config/audit.php', 'audit');
}

/**
* Publish configs
* @return void
*/
protected function publishConfigs(): void
{
$this->publishes([
__DIR__ . '/../resource/images' => public_path('auditor/icon'),
], 'public');

$this->publishes([
__DIR__ . '/../../config/db-auditor.php' => config_path('db-auditor.php'),
], 'config');
}

/**
* Register commands
* @return void
*/
public function registerCommands(): void
{
$this->commands($this->commands);
}
/**
* Load helpers
* @return void
*/
protected function loadHelpers(): void
Expand Down
1 change: 0 additions & 1 deletion src/views/sqlite/standard.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
@foreach ($tableStatus as $table)
<div class="flex space-x-1">
<span>{{ $table['name'] }}</span>
<i class="text-blue">({{ $table['size'] }} MB)</i>
<span class="flex-1 content-repeat-[.] text-gray"></span>
@if ($table['status'])
@php $success++; @endphp
Expand Down