Skip to content

fix: deployment export and import bugs#153

Open
premtsd-code wants to merge 4 commits intomainfrom
fix-export-inactive-deployments
Open

fix: deployment export and import bugs#153
premtsd-code wants to merge 4 commits intomainfrom
fix-export-inactive-deployments

Conversation

@premtsd-code
Copy link
Contributor

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

Summary

  • Respect the include inactive deployments option for both functions and sites — always export active deployment, optionally export all
  • Convert activate param to string 'true'/'false' for multipart form-data requests
  • Skip child resource import (deployments, env vars, site deployments, site vars) when parent resource failed to import

Test plan

  • Migrate a project with functions, sites, deployments, and env vars to a fresh destination — all should succeed
  • Re-migrate the same project to the same destination — parent resources (function, site) should fail with 409, and child resources (deployment, env var, site deployment, site var) should fail with "Parent {type} failed to import"
  • Verify deployment activation state is preserved correctly after migration
  • Verify large deployments (chunked upload) work correctly with the range clamping fix

Summary by CodeRabbit

  • Bug Fixes
    • Added runtime checks to ensure parent resources (functions/sites) are valid before migrating dependent items, preventing incomplete imports and clearer error feedback.
    • Improved migration payloads and export logic: activation flags are transmitted consistently, parent resource IDs are resolved uniformly, and deployment export behavior is streamlined for more reliable migration results.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 2, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 589dd29 and 928e7c8.

📒 Files selected for processing (2)
  • src/Migration/Destinations/Appwrite.php
  • src/Migration/Sources/Appwrite.php
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/Migration/Sources/Appwrite.php

Walkthrough

Adds parent-resource status checks in the Appwrite migration destination: before importing env vars, deployments, site env vars, and site deployments the code validates parent function/site status and throws exceptions when parent status is STATUS_ERROR. Normalizes boolean activate flags to string values ('true'/'false') in deployment-related API payloads and consistently uses resolved parent IDs for payload construction. In the Appwrite migration source, replaces repetitive in_array checks with a computed $exportOnlyActive flag and passes it to exportDeployments and exportSiteDeployments to control which deployments are exported.

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 66.67% 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 title 'fix: deployment export and import bugs' clearly and concisely describes the main changes across both source and destination files, which involve fixing deployment export logic and adding import validation for parent-child resources.

✏️ 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 fix-export-inactive-deployments

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.

Use the resources array to determine whether to export only the active
deployment or all deployments. When deployment/site-deployment resource
type is included, export all deployments instead of only the active one.
PHP booleans become '1'/'' in multipart/form-data but the API expects
'true'/'false' strings. The non-chunked function deployment path was
already correct; this fixes the chunked function deployment and both
site deployment paths.
…stination

When a function or site already exists in the destination, the API
returns 409 and the parent resource is marked as error. Previously,
deployments for that parent would still be imported, creating
duplicates. Now importDeployment and importSiteDeployment check the
parent status and throw an error if it failed.
@premtsd-code premtsd-code force-pushed the fix-export-inactive-deployments branch from 589dd29 to 928e7c8 Compare March 2, 2026 09:57
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: 1

🤖 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/Sources/Appwrite.php`:
- Around line 1521-1522: $exportOnlyActive is being set when
Resource::TYPE_DEPLOYMENT is not requested but currently code falls back to
paginated listing and exports all deployments for resources (functions/sites)
that lack an active deployment; change the callers and exportDeployments logic
so that when $exportOnlyActive is true you only export deployments explicitly
referenced by an active deployment ID and never fall back to the full paginated
export: detect resources (functions/sites) with no activeDeploymentId and skip
exporting their deployments (do not call the paginated listing), and ensure the
same change is applied to the second occurrence around the lines mentioned (the
other $exportOnlyActive usage).

ℹ️ Review info

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 037bf4b and 589dd29.

📒 Files selected for processing (2)
  • src/Migration/Destinations/Appwrite.php
  • src/Migration/Sources/Appwrite.php

Comment on lines +1521 to +1522
$exportOnlyActive = !\in_array(Resource::TYPE_DEPLOYMENT, $resources);
$this->exportDeployments($batchSize, $exportOnlyActive);
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 | 🟠 Major

$exportOnlyActive mode can still export all deployments when no active deployment exists.

When Line 1521 / Line 1551 set active-only mode, functions/sites without an active deployment ID currently fall through to paginated listing and export all deployments. That breaks the include-inactive contract for this edge case.

🔧 Proposed fix
--- a/src/Migration/Sources/Appwrite.php
+++ b/src/Migration/Sources/Appwrite.php
@@
-            if ($exportOnlyActive && $func->getActiveDeployment()) {
-                $deployment = $this->functions->getDeployment($func->getId(), $func->getActiveDeployment());
+            if ($exportOnlyActive) {
+                $activeDeploymentId = $func->getActiveDeployment();
+                if (empty($activeDeploymentId)) {
+                    continue; // active-only mode: nothing to export for this function
+                }
+
+                $deployment = $this->functions->getDeployment($func->getId(), $activeDeploymentId);
@@
                 continue;
             }
@@
-            if ($exportOnlyActive && $site->getActiveDeployment()) {
-                $deployment = $this->sites->getDeployment($site->getId(), $site->getActiveDeployment());
+            if ($exportOnlyActive) {
+                $activeDeploymentId = $site->getActiveDeployment();
+                if (empty($activeDeploymentId)) {
+                    continue; // active-only mode: nothing to export for this site
+                }
+
+                $deployment = $this->sites->getDeployment($site->getId(), $activeDeploymentId);
@@
                 continue;
             }

Also applies to: 1551-1552

🤖 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 1521 - 1522,
$exportOnlyActive is being set when Resource::TYPE_DEPLOYMENT is not requested
but currently code falls back to paginated listing and exports all deployments
for resources (functions/sites) that lack an active deployment; change the
callers and exportDeployments logic so that when $exportOnlyActive is true you
only export deployments explicitly referenced by an active deployment ID and
never fall back to the full paginated export: detect resources (functions/sites)
with no activeDeploymentId and skip exporting their deployments (do not call the
paginated listing), and ensure the same change is applied to the second
occurrence around the lines mentioned (the other $exportOnlyActive usage).

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