diff --git a/database/migrations/create_barstools_table.php.stub b/database/migrations/create_barstools_table.php.stub index 2d30c4d..e417a2b 100644 --- a/database/migrations/create_barstools_table.php.stub +++ b/database/migrations/create_barstools_table.php.stub @@ -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'); } /** diff --git a/tests/BarstoolTest.php b/tests/BarstoolTest.php index c4f8a65..ca1c6ee 100644 --- a/tests/BarstoolTest.php +++ b/tests/BarstoolTest.php @@ -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);