Fix migrate:status when migrations table is absent#57
Conversation
|
duplicate of #58 |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: bb3cf2e3eb
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| return strpos($code, '42S02') !== false | ||
| || strpos($message, '1146') !== false | ||
| || stripos($message, 'no such table') !== false; |
There was a problem hiding this comment.
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 👍 / 👎.
There was a problem hiding this comment.
Pull request overview
Fixes migrate:status behavior on fresh schemas by making Migration::applied() treat a missing rxn_migrations table as “no applied migrations”, even when the DB layer throws a wrapped QueryException.
Changes:
- Catch
QueryExceptionas well as\PDOExceptioninMigration::applied(). - Add
isMissingMigrationsTable()helper to detect missing-table errors and return an empty applied list.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| 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; |
| $message = $exception->getMessage(); | ||
| $code = (string)$exception->getCode(); | ||
|
|
||
| return strpos($code, '42S02') !== false | ||
| || strpos($message, '1146') !== false | ||
| || stripos($message, 'no such table') !== false; |
Motivation
migrate:statusnow constructsMigrationwithensureTable=false, so therxn_migrationstable may not exist on fresh schemas and must be handled gracefully.Querylayer wraps PDO errors inQueryException, soMigration::applied()catching only\PDOExceptioncould miss the real exception and crash instead of returning an empty applied list.Description
QueryExceptioninsrc/Rxn/Framework/Data/Migration.phpand extend the catch inapplied()to\PDOException | QueryExceptionso both error types are handled.isMissingMigrationsTable()that detects missing-table conditions by checking the SQLSTATE42S02, MySQL driver message text1146, or SQLite-styleno such tablein the exceptionmessageorcode.Testing
php -l src/Rxn/Framework/Data/Migration.php, which succeeded (no syntax errors).Codex Task