diff --git a/src/Rxn/Framework/Data/Migration.php b/src/Rxn/Framework/Data/Migration.php index 79c19ec..cc9ab8a 100644 --- a/src/Rxn/Framework/Data/Migration.php +++ b/src/Rxn/Framework/Data/Migration.php @@ -3,6 +3,7 @@ namespace Rxn\Framework\Data; use Rxn\Framework\Error\DatabaseException; +use Rxn\Framework\Error\QueryException; /** * Minimal, file-based schema migration runner. @@ -67,8 +68,8 @@ 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; @@ -76,6 +77,16 @@ public function applied(): array 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; + } + /** * @return string[] filenames discovered on disk, sorted lexicographically */