-
Notifications
You must be signed in to change notification settings - Fork 184
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #83 from parallax/feature/missing-column
Suggest running migrations when a column is missing
- Loading branch information
Showing
4 changed files
with
46 additions
and
2 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,35 @@ | ||
<?php | ||
|
||
namespace Facade\Ignition\SolutionProviders; | ||
|
||
use Throwable; | ||
use Illuminate\Database\QueryException; | ||
use Facade\Ignition\Solutions\RunMigrationsSolution; | ||
use Facade\IgnitionContracts\HasSolutionsForThrowable; | ||
|
||
class MissingColumnSolutionProvider implements HasSolutionsForThrowable | ||
{ | ||
/** | ||
* See https://dev.mysql.com/doc/refman/8.0/en/server-error-reference.html#error_er_bad_field_error. | ||
*/ | ||
const MYSQL_BAD_FIELD_CODE = '42S22'; | ||
|
||
public function canSolve(Throwable $throwable): bool | ||
{ | ||
if (! $throwable instanceof QueryException) { | ||
return false; | ||
} | ||
|
||
return $this->isBadTableErrorCode($throwable->getCode()); | ||
} | ||
|
||
protected function isBadTableErrorCode($code): bool | ||
{ | ||
return $code === static::MYSQL_BAD_FIELD_CODE; | ||
} | ||
|
||
public function getSolutions(Throwable $throwable): array | ||
{ | ||
return [new RunMigrationsSolution('A column was not found')]; | ||
} | ||
} |
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