Skip to content
Closed
Changes from all commits
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 69 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 +85 to +87

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Detect wrapped SQLSTATE 42S02 in missing-table check

isMissingMigrationsTable() only looks for 42S02 in $exception->getCode(), but Query::prepare() wraps PDO errors into QueryException with code 500 and puts the SQLSTATE into the message ("PDO Exception (code 42S02)"). In environments where the missing-table failure is raised at prepare time and the message does not include 1146/no such table, this branch returns false and migrate:status still crashes instead of returning an empty applied list.

Useful? React with 👍 / 👎.

Comment on lines +82 to +87
}

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