Skip to content
Open
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
2 changes: 1 addition & 1 deletion database/migrations/create_barstools_table.php.stub
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ return new class extends Migration
*/
public function getConnection(): string|null
{
return config('barstool.database_connection');
return config('barstool.connection') ?? config('barstool.database_connection');
}

/**
Expand Down
18 changes: 18 additions & 0 deletions tests/BarstoolTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,24 @@
expect(Barstool::make()->getConnectionName())->toBe('sqlite');
});

it('uses the correct config key for the migration database connection', function () {
$migration = include __DIR__.'/../database/migrations/create_barstools_table.php.stub';

// The migration should use the 'barstool.connection' config key
config()->set('barstool.connection', 'pgsql');
expect($migration->getConnection())->toBe('pgsql');

// It should fall back to 'barstool.database_connection' for backwards compatibility
config()->set('barstool.connection', null);
config()->set('barstool.database_connection', 'sqlite');
expect($migration->getConnection())->toBe('sqlite');

// 'barstool.connection' takes priority over 'barstool.database_connection'
config()->set('barstool.connection', 'mysql');
config()->set('barstool.database_connection', 'sqlite');
expect($migration->getConnection())->toBe('mysql');
});

it('can change the number of days to keep recordings for', function () {
// Check the default value is 30
expect(config('barstool.keep_for_days'))->toBe(30);
Expand Down