diff --git a/README.md b/README.md index 9fc81ec..258c7d1 100644 --- a/README.md +++ b/README.md @@ -86,7 +86,7 @@ For this reason, we've developed the notion of custom resolvers. They must be im These custom resolvers don't run as items are entered, due to the load increase. This should arguably be queued, but easier on implementations for a command (cron) system. Use the Laravel Scheduler to execute our command. ```php -$schedule->command('logger:audit-resolver') +Schedule::command('logger:audit-resolver') ->hourly() ->withoutOverlapping(); ``` diff --git a/composer.json b/composer.json index aaa2eb4..79d9428 100644 --- a/composer.json +++ b/composer.json @@ -23,6 +23,11 @@ "illuminate/support": "^11.0", "illuminate/translation": "^11.0" }, + "require-dev": { + "orchestra/testbench": "^9.5", + "phpunit/phpunit": "^11.2", + "squizlabs/php_codesniffer": "^3.10" + }, "autoload": { "psr-4": { "Sourcetoad\\Logger\\": "src" @@ -42,9 +47,5 @@ "Logger": "Sourcetoad\\Logger\\LoggerFacade" } } - }, - "require-dev": { - "squizlabs/php_codesniffer": "^3.10", - "phpunit/phpunit": "^11.2" } } diff --git a/database/migrations/2019_03_35_000001_create_logger_tables.php b/database/migrations/2019_03_35_000001_create_logger_tables.php index 4cd586b..6fa1c35 100644 --- a/database/migrations/2019_03_35_000001_create_logger_tables.php +++ b/database/migrations/2019_03_35_000001_create_logger_tables.php @@ -58,7 +58,13 @@ public function up(): void ->onDelete('RESTRICT'); }); - DB::statement('ALTER TABLE `audit_activities` ADD `ip_address` VARBINARY(16) AFTER `type`'); + if (DB::getDriverName() === 'pgsql') { + // PostgreSQL-specific SQL + DB::statement('ALTER TABLE audit_activities ADD ip_address INET'); + } else { + // MySQL-specific SQL + DB::statement('ALTER TABLE `audit_activities` ADD `ip_address` VARBINARY(16) AFTER `type`'); + } Schema::create('audit_models', function (Blueprint $table) { $table->bigIncrements('id'); diff --git a/src/Models/AuditActivity.php b/src/Models/AuditActivity.php index da484b0..2960090 100644 --- a/src/Models/AuditActivity.php +++ b/src/Models/AuditActivity.php @@ -8,6 +8,7 @@ use Exception; use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\Relations\MorphTo; +use Illuminate\Support\Facades\DB; use Sourcetoad\Logger\Enums\ActivityType; use Sourcetoad\Logger\Enums\HttpVerb; use Sourcetoad\Logger\Logger; @@ -57,11 +58,19 @@ class AuditActivity extends BaseModel protected function setIpAddressAttribute(?string $value): void { - $this->attributes['ip_address'] = inet_pton((string)$value); + if (DB::getDriverName() === 'pgsql') { + $this->attributes['ip_address'] = $value; + } else { + $this->attributes['ip_address'] = inet_pton((string)$value); + } } protected function getIpAddressAttribute($value): string { + if (DB::getDriverName() === 'pgsql') { + return strtoupper($value); + } + return strtoupper(inet_ntop($value)); } diff --git a/tests/TestCase.php b/tests/TestCase.php index 9538975..6039c07 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -5,8 +5,9 @@ use Sourcetoad\Logger\LoggerFacade; use Sourcetoad\Logger\LoggerServiceProvider; +use Orchestra\Testbench\TestCase as TestBenchTestCase; -class TestCase extends \PHPUnit\Framework\TestCase +class TestCase extends TestBenchTestCase { protected function getPackageProviders($app): array {