Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions src/Rxn/Framework/Data/Migration.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Rxn\Framework\Data;

use Rxn\Framework\Error\DatabaseException;
use Rxn\Framework\Error\QueryException;

/**
* Minimal, file-based schema migration runner.
Expand Down Expand Up @@ -67,15 +68,25 @@ public function applied(): array
{
try {
$rows = $this->database->fetchAll("SELECT filename FROM `" . self::TABLE . "` ORDER BY filename ASC");
} catch (\PDOException $exception) {
if ((int)$exception->getCode() === 1146) {
} catch (\PDOException | QueryException $exception) {
if ($this->isMissingMigrationsTable($exception)) {
return [];
}
throw $exception;
Comment on lines +71 to 75
}
return array_column($rows ?: [], 'filename');
}

private function isMissingMigrationsTable(\Throwable $exception): bool
{
$message = $exception->getMessage();
$code = (string)$exception->getCode();

return strpos($code, '42S02') !== false
|| strpos($message, '1146') !== false
|| stripos($message, 'no such table') !== false;
Comment on lines +91 to +97
}

/**
* @return string[] filenames discovered on disk, sorted lexicographically
*/
Expand Down
Loading