Fix migrate:status when migrations table is absent#58
Conversation
There was a problem hiding this comment.
Pull request overview
This PR aims to restore bin/rxn migrate:status on fresh databases by making Migration::applied() tolerate a missing rxn_migrations table even when the Data layer surfaces the failure as a wrapped QueryException. It fits the framework’s migration tooling by keeping status inspection usable before any migration has been applied.
Changes:
- Import
QueryExceptionand widen the exception handling inMigration::applied(). - Add a private helper to recognize missing-table errors from SQLSTATE/message patterns.
- Return an empty applied-migrations list for missing-table cases while rethrowing unrelated failures.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| $message = $exception->getMessage(); | ||
| $code = (string)$exception->getCode(); | ||
|
|
||
| return strpos($code, '42S02') !== false | ||
| || strpos($message, '1146') !== false | ||
| || stripos($message, 'no such table') !== false; |
| } catch (\PDOException | QueryException $exception) { | ||
| if ($this->isMissingMigrationsTable($exception)) { | ||
| return []; | ||
| } | ||
| throw $exception; |
|
@copilot apply changes based on the comments in this thread |
…us; add MigrationAppliedTest Agent-Logs-Url: https://github.com/davidwyly/rxn/sessions/7f9ef037-8704-4f4e-af3b-03c3e40feb82 Co-authored-by: davidwyly <13552783+davidwyly@users.noreply.github.com>
Both review points are addressed in commit 822bcf3:
|
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