From bb3cf2e3eb0ce435447d3a147fe8349a25a5bb16 Mon Sep 17 00:00:00 2001 From: David Wyly Date: Sun, 3 May 2026 13:37:00 -0600 Subject: [PATCH] Handle missing migrations table in migrate:status --- src/Rxn/Framework/Data/Migration.php | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) 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 */