-
Notifications
You must be signed in to change notification settings - Fork 178
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[1.x] Improve migration errors to guide developers with unsupported d…
…rivers (#233) * Improve migration errors to guide developers with unsupported drivers * Fix code styling * Fix * Update PulseMigration.php --------- Co-authored-by: timacdonald <[email protected]> Co-authored-by: Taylor Otwell <[email protected]>
- Loading branch information
1 parent
0d91d94
commit 7cf1593
Showing
2 changed files
with
57 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
|
||
namespace Laravel\Pulse\Support; | ||
|
||
use Illuminate\Database\Connection; | ||
use Illuminate\Database\Migrations\Migration; | ||
use Illuminate\Support\Facades\App; | ||
use Illuminate\Support\Facades\Config; | ||
use Illuminate\Support\Facades\DB; | ||
use RuntimeException; | ||
|
||
class PulseMigration extends Migration | ||
{ | ||
/** | ||
* Get the migration connection name. | ||
*/ | ||
public function getConnection(): ?string | ||
{ | ||
return Config::get('pulse.storage.database.connection'); | ||
} | ||
|
||
/** | ||
* Determine if the migration should run. | ||
*/ | ||
protected function shouldRun(): bool | ||
{ | ||
if (in_array($this->driver(), ['mysql', 'pgsql'])) { | ||
return true; | ||
} | ||
|
||
if (! App::environment('testing')) { | ||
throw new RuntimeException("Pulse does not support the [{$this->driver()}] database driver."); | ||
} | ||
|
||
if (Config::get('pulse.enabled')) { | ||
throw new RuntimeException("Pulse does not support the [{$this->driver()}] database driver. You can disable Pulse in your testsuite by adding `<env name=\"PULSE_ENABLED\" value=\"false\"/>` to your project's `phpunit.xml` file."); | ||
} | ||
|
||
return false; | ||
} | ||
|
||
/** | ||
* Get the database connection driver. | ||
*/ | ||
protected function driver(): string | ||
{ | ||
return DB::connection($this->getConnection())->getDriverName(); | ||
} | ||
} |