From 2b09d209285bd54688eb679a1a42befc13821972 Mon Sep 17 00:00:00 2001 From: Craig Potter Date: Tue, 31 Mar 2026 20:10:25 +0100 Subject: [PATCH] Fix migration using wrong config key for database connection 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. --- .../migrations/create_barstools_table.php.stub | 2 +- tests/BarstoolTest.php | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) 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);