[Fix] Prevent backups:run crash for backups whose server was deleted#1207
[Fix] Prevent backups:run crash for backups whose server was deleted#1207erhanurgun wants to merge 5 commits into
Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughBackup file deletion now handles missing servers by removing orphaned records without dispatching jobs. The scheduled backup command filters out backups without associated servers. Tests cover both behaviours. ChangesBackup orphan cleanup
Estimated code review effort: 2 (Simple) | ~10 minutes Suggested reviewers: 🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 6dd0eadadc
ℹ️ 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".
|
Heads up: I noticed #1198 already adds the |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@tests/Unit/Commands/RunBackupCommandTest.php`:
- Around line 129-138: Update the assertDatabaseHas call in the orphaned-backup
test to include server_id => 999999 alongside the backup ID, ensuring the
persisted fixture is verified as orphaned while preserving the existing
assertions.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro Plus
Run ID: 9784c4a1-8610-45db-8146-c997c7723fe0
📒 Files selected for processing (1)
tests/Unit/Commands/RunBackupCommandTest.php
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@tests/Unit/Commands/RunBackupCommandTest.php`:
- Around line 132-138: Update the assertDatabaseHas call in the backup orphan
test to include server_id set to 999999 alongside the backup ID, confirming the
fixture persisted the missing server reference while preserving the existing
no-dispatch assertion.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro Plus
Run ID: 9784c4a1-8610-45db-8146-c997c7723fe0
📒 Files selected for processing (1)
tests/Unit/Commands/RunBackupCommandTest.php
|
Hi @erhanurgun - I just merged the approved PR #1198 - and these changes complement it well, this has introduced a conflict on one of the tests. |
Resolve BackupTest.php conflict as union: keep orphan-path tests alongside vitodeploy#1198's global-backup tests; both import blocks merged.
|
Thanks @RichardAnderson - glad it fits. I've merged #1198 in and resolved the |
…trengthen orphan assertion
Closes #1206
When a server that has backups is deleted, its
Backuprows are left with a danglingserver_id(there's no FK on the column). The scheduledbackups:runthen reads$backup->server->project_idon a null server and crashes on every run.This makes the runner and the backup-file cleanup resilient to those already-orphaned rows:
RunBackupCommand: skip backups whose server is gone (whereHas('server')) and eager-loadserver(also fixes a pre-existing N+1).ManageBackupFile::delete(): null-safe when the server is missing — it logs and drops the local record instead of dispatching an SSH job, and skips the socket broadcast. (Server loaded viaServer::find()so PHPStan doesn't treat the non-nullable relation as never-null.)Also removed the unused
ManageBackupFile::download()method (dead since the Inertia migration in #593 — its only caller was the old Filament widget, which wasn't re-wired), per review.Note: cascading a server's backups on delete is now handled by #1198, so this PR doesn't touch that — it only covers rows already orphaned on existing installs, which #1198's cascade doesn't reach.
Tests (SSH::fake + RefreshDatabase):
RunBackupCommandTest::test_does_not_run_backups_whose_server_is_missingBackupTest::test_delete_orphaned_backup_file_hard_deletes_without_dispatching_jobNo migration.
Summary by CodeRabbit
backups:runcommand does not start backups for missing servers.