Skip to content

Commit

Permalink
Improved Default Database Connection Check
Browse files Browse the repository at this point in the history
  • Loading branch information
eusonlito committed Feb 2, 2024
1 parent 1abe194 commit ee37fee
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
3 changes: 2 additions & 1 deletion database/migrations/create_health_tables.php.stub
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use Spatie\Health\Models\HealthCheckResultHistoryItem;
use Spatie\Health\ResultStores\EloquentHealthResultStore;

return new class extends Migration
{
public function up()
{
$connection = config('health.result_stores.'.EloquentHealthResultStore::class.'.connection');
$connection = (new HealthCheckResultHistoryItem())->getConnectionName();
$tableName = EloquentHealthResultStore::getHistoryItemInstance()->getTable();

Schema::connection($connection)->create($tableName, function (Blueprint $table) {
Expand Down
3 changes: 2 additions & 1 deletion src/Models/HealthCheckResultHistoryItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ class HealthCheckResultHistoryItem extends Model

public function getConnectionName(): string
{
return config('health.result_stores.'.EloquentHealthResultStore::class.'.connection');
return config('health.result_stores.'.EloquentHealthResultStore::class.'.connection')
?: config('database.default');
}

public function prunable(): Builder
Expand Down

0 comments on commit ee37fee

Please sign in to comment.