Skip to content

Add backup policy migration support#163

Open
premtsd-code wants to merge 3 commits intomainfrom
backup-migration-multitype
Open

Add backup policy migration support#163
premtsd-code wants to merge 3 commits intomainfrom
backup-migration-multitype

Conversation

@premtsd-code
Copy link
Contributor

@premtsd-code premtsd-code commented Mar 12, 2026

Summary

  • Add backup-policy resource type and backups group to the migration framework
  • Add Policy resource class with properties: id, name, services, retention, schedule, enabled, resourceId, resourceType
  • Add no-op stubs in CE source/destination (backup policies are Cloud-only)
  • Add exportGroupBackups abstract method to Source with implementations in all source classes

Test plan

  • Unit tests for Policy resource serialization
  • E2E test: migrate backup policies between Cloud projects
  • Verify no-op behavior on CE (self-hosted)
  • Verify other migration sources (Firebase, NHost, CSV, JSON) don't break

Summary by CodeRabbit

  • New Features
    • Added backup policy support to the migration system.
    • Backup policies are now a recognized transferable resource type.
    • Sources can export backups and destinations can import backup policies during migrations.
  • Tests
    • Migration tests updated to include backup policy export paths.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 12, 2026

Walkthrough

Adds backup policy support across the migration system. Introduces Resource::TYPE_BACKUP_POLICY and a new Backups Policy resource class modeling backup policies. Adds Transfer backup group constants and integrates backups into resource extraction and public lists. Extends Source with getBackupsBatchSize and an abstract exportGroupBackups; concrete sources (Appwrite, CSV, Firebase, JSON, NHost, MockSource) add exportGroupBackups handlers (Appwrite imports via importBackupResource which marks resources skipped). Source reporting and supported-resources lists updated to include backups.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 57.14% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title 'Add backup policy migration support' directly and clearly summarizes the main change: introducing backup policy migration functionality to the framework.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch backup-migration-multitype
📝 Coding Plan
  • Generate coding plan for human review comments

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (1)
src/Migration/Sources/Appwrite.php (1)

1426-1437: Consider surfacing the Cloud-only no-op when backups are requested.

exportGroupBackups() currently does a silent no-op. If backups are explicitly requested on CE, a non-fatal warning/log would improve operator feedback during migration runs.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/Migration/Sources/Appwrite.php` around lines 1426 - 1437,
exportGroupBackups currently silently no-ops; change it to emit a non-fatal
warning when invoked so operators know backups are Cloud-only (reference: method
exportGroupBackups). Use the class logger (e.g. $this->logger or the existing
logging facility in this class) to log a clear warning indicating backups are
Cloud-only and will not be exported for CE, include any relevant group
identifier/parameters if available. Also augment reportBackups (reference:
reportBackups and Resource::TYPE_BACKUP_POLICY) to log a brief informational
message when backup policies are requested and you populate the report with
zero, so the migration report plus logs both surface that backups are
unsupported on CE.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/Migration/Destinations/Appwrite.php`:
- Around line 1490-1495: The importBackupResource(Resource $resource): Resource
method currently sets Resource::STATUS_SUCCESS without performing any import;
change it to mark the resource as skipped or warning (e.g.,
Resource::STATUS_SKIPPED or Resource::STATUS_WARNING) and attach a clear message
like "Import not implemented" (or similar), and avoid returning success until
real import logic is implemented; update the method in the Appwrite migration
class (importBackupResource) to set the non-success status and message and
optionally log the skipped action so reports/do-not-report logic won't treat it
as migrated.

In `@src/Migration/Resources/Backups/Policy.php`:
- Around line 37-48: The fromArray() factory (Policy::fromArray) currently
assumes $array['id'] exists; add explicit validation for the required id: check
isset($array['id']) and that it's the expected type/format (e.g., non-empty
string or integer) and throw a clear InvalidArgumentException (or similar) if
missing/invalid so callers get a descriptive validation error instead of a PHP
notice; then pass the validated/casted id into new self(...) as before.

---

Nitpick comments:
In `@src/Migration/Sources/Appwrite.php`:
- Around line 1426-1437: exportGroupBackups currently silently no-ops; change it
to emit a non-fatal warning when invoked so operators know backups are
Cloud-only (reference: method exportGroupBackups). Use the class logger (e.g.
$this->logger or the existing logging facility in this class) to log a clear
warning indicating backups are Cloud-only and will not be exported for CE,
include any relevant group identifier/parameters if available. Also augment
reportBackups (reference: reportBackups and Resource::TYPE_BACKUP_POLICY) to log
a brief informational message when backup policies are requested and you
populate the report with zero, so the migration report plus logs both surface
that backups are unsupported on CE.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: c038b0e9-982e-4e7e-a15b-4ab24f9c9d3f

📥 Commits

Reviewing files that changed from the base of the PR and between 95dcbb9 and d3084fb.

📒 Files selected for processing (10)
  • src/Migration/Destinations/Appwrite.php
  • src/Migration/Resource.php
  • src/Migration/Resources/Backups/Policy.php
  • src/Migration/Source.php
  • src/Migration/Sources/Appwrite.php
  • src/Migration/Sources/CSV.php
  • src/Migration/Sources/Firebase.php
  • src/Migration/Sources/JSON.php
  • src/Migration/Sources/NHost.php
  • src/Migration/Transfer.php

Comment on lines +37 to +48
public static function fromArray(array $array): self
{
return new self(
$array['id'],
$array['name'] ?? '',
$array['services'] ?? [],
$array['retention'] ?? 0,
$array['schedule'] ?? '',
$array['enabled'] ?? true,
$array['resourceId'] ?? '',
$array['resourceType'] ?? '',
);
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Harden fromArray() for missing/invalid required id.

Line 40 assumes id exists and is valid. Malformed payloads will trigger a low-level notice instead of a clear validation error.

💡 Proposed fix
 public static function fromArray(array $array): self
 {
+    if (!isset($array['id']) || !\is_string($array['id']) || $array['id'] === '') {
+        throw new \InvalidArgumentException('Backup policy "id" is required.');
+    }
+
     return new self(
         $array['id'],
         $array['name'] ?? '',
         $array['services'] ?? [],
         $array['retention'] ?? 0,
         $array['schedule'] ?? '',
         $array['enabled'] ?? true,
         $array['resourceId'] ?? '',
         $array['resourceType'] ?? '',
     );
 }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/Migration/Resources/Backups/Policy.php` around lines 37 - 48, The
fromArray() factory (Policy::fromArray) currently assumes $array['id'] exists;
add explicit validation for the required id: check isset($array['id']) and that
it's the expected type/format (e.g., non-empty string or integer) and throw a
clear InvalidArgumentException (or similar) if missing/invalid so callers get a
descriptive validation error instead of a PHP notice; then pass the
validated/casted id into new self(...) as before.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

♻️ Duplicate comments (1)
src/Migration/Destinations/Appwrite.php (1)

1490-1495: ⚠️ Potential issue | 🟡 Minor

Include a skip reason when backup import is not implemented.

Line 1492 sets STATUS_SKIPPED without context. This makes migration reports harder to interpret when backups are intentionally no-op.

Proposed fix
 public function importBackupResource(Resource $resource): Resource
 {
-    $resource->setStatus(Resource::STATUS_SKIPPED);
+    $resource->setStatus(
+        Resource::STATUS_SKIPPED,
+        'Backup policy import is not implemented for this destination'
+    );
 
     return $resource;
 }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/Migration/Destinations/Appwrite.php` around lines 1490 - 1495, In
importBackupResource (class Appwrite) you should still mark the resource skipped
but also record a human-readable skip reason; after setting
Resource::STATUS_SKIPPED call a method on the Resource to record the reason
(e.g. $resource->setSkipReason('backup import not implemented for Appwrite')) so
migration reports show context — if Resource has no setSkipReason, add the
reason to resource metadata (e.g. $resource->setMeta('skip_reason', 'backup
import not implemented for Appwrite')) and return the resource.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Duplicate comments:
In `@src/Migration/Destinations/Appwrite.php`:
- Around line 1490-1495: In importBackupResource (class Appwrite) you should
still mark the resource skipped but also record a human-readable skip reason;
after setting Resource::STATUS_SKIPPED call a method on the Resource to record
the reason (e.g. $resource->setSkipReason('backup import not implemented for
Appwrite')) so migration reports show context — if Resource has no
setSkipReason, add the reason to resource metadata (e.g.
$resource->setMeta('skip_reason', 'backup import not implemented for Appwrite'))
and return the resource.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 4aa7918e-6e48-4aa6-906c-b2e688117d89

📥 Commits

Reviewing files that changed from the base of the PR and between d3084fb and 5352a2b.

📒 Files selected for processing (2)
  • src/Migration/Destinations/Appwrite.php
  • tests/Migration/Unit/Adapters/MockSource.php

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant