Skip to content

Commit 7bb817f

Browse files
authored
Fix migration using wrong config key for database connection (#3)
## Summary - The migration stub was referencing `barstool.database_connection` but the actual config key is `barstool.connection` - Uses null coalescing to fall back to the old key for backwards compatibility with anyone who may have published the migration with the old key - Adds test coverage for the migration connection config ## Test plan - [x] New test verifies `barstool.connection` is used - [x] New test verifies fallback to `barstool.database_connection` - [x] New test verifies `barstool.connection` takes priority when both are set - [x] Full test suite passes (18 tests, 129 assertions) - [x] PHPStan passes
1 parent 15b89b9 commit 7bb817f

2 files changed

Lines changed: 19 additions & 1 deletion

File tree

database/migrations/create_barstools_table.php.stub

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ return new class extends Migration
1212
*/
1313
public function getConnection(): string|null
1414
{
15-
return config('barstool.database_connection');
15+
return config('barstool.connection') ?? config('barstool.database_connection');
1616
}
1717

1818
/**

tests/BarstoolTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,24 @@
9191
expect(Barstool::make()->getConnectionName())->toBe('sqlite');
9292
});
9393

94+
it('uses the correct config key for the migration database connection', function () {
95+
$migration = include __DIR__.'/../database/migrations/create_barstools_table.php.stub';
96+
97+
// The migration should use the 'barstool.connection' config key
98+
config()->set('barstool.connection', 'pgsql');
99+
expect($migration->getConnection())->toBe('pgsql');
100+
101+
// It should fall back to 'barstool.database_connection' for backwards compatibility
102+
config()->set('barstool.connection', null);
103+
config()->set('barstool.database_connection', 'sqlite');
104+
expect($migration->getConnection())->toBe('sqlite');
105+
106+
// 'barstool.connection' takes priority over 'barstool.database_connection'
107+
config()->set('barstool.connection', 'mysql');
108+
config()->set('barstool.database_connection', 'sqlite');
109+
expect($migration->getConnection())->toBe('mysql');
110+
});
111+
94112
it('can change the number of days to keep recordings for', function () {
95113
// Check the default value is 30
96114
expect(config('barstool.keep_for_days'))->toBe(30);

0 commit comments

Comments
 (0)