Skip to content

fix: deployment export and import bugs#153

Merged
abnegate merged 7 commits intomainfrom
fix-export-inactive-deployments
Mar 4, 2026
Merged

fix: deployment export and import bugs#153
abnegate merged 7 commits intomainfrom
fix-export-inactive-deployments

Conversation

@premtsd-code
Copy link
Contributor

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

Summary

  • Export only the active deployment by default; export all deployments when the inactive deployments resource type is included
  • Skip functions/sites with no active deployment entirely in active-only mode instead of falling back to full paginated export
  • Convert activate param to string 'true'/'false' for multipart form-data (PHP booleans serialize as 1/"", not true/false)
  • Skip child resource import (deployments, site deployments, site variables) when parent resource failed to import

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 2, 2026

Note

Reviews paused

It 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 reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

Walkthrough

Adds parent-resource status validation in the Appwrite migration destination: before importing a Function or Site deployment the code checks the resolved parent Function/Site status and, if not STATUS_SUCCESS, sets the child deployment to STATUS_SKIPPED with a message and returns early; otherwise it uses the resolved parent ID. Normalizes activate values in function and site deployment payloads to the strings 'true'/'false'. Adjusts control flow to set STATUS_SUCCESS and return immediately in certain small-paths. In the Appwrite migration source, replaces repeated in_array checks with a computed $exportOnlyActive flag passed to exportDeployments/exportSiteDeployments.

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
Title check ✅ Passed The title 'fix: deployment export and import bugs' directly addresses the core changes in the PR, which involve fixing bugs in both the export and import logic for deployments across functions and sites.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ 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

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/Destinations/Appwrite.php`:
- Around line 1476-1484: The current checks only skip child deployment imports
when the parent function status equals Resource::STATUS_ERROR, which misses
other non-success states (e.g., STATUS_SKIPPED); update the guard(s) to skip
whenever the parent status is not Resource::STATUS_SUCCESS. Specifically, change
the condition that reads $function = $deployment->getFunction(); if
($function->getStatus() === Resource::STATUS_ERROR) ... to check if
($function->getStatus() !== Resource::STATUS_SUCCESS) and call
$deployment->setStatus(Resource::STATUS_SKIPPED, ...) accordingly; apply the
same change to the other occurrence around the block referenced (the check at
the 1691–1695 area) so any non-success parent prevents child import.

ℹ️ Review info

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 928e7c8 and 541efc8.

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

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.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/Migration/Destinations/Appwrite.php (1)

1452-1459: ⚠️ Potential issue | 🟠 Major

Add parent-status guards for function/site variable imports too.

Deployments now correctly skip when parent import failed, but function/site variables still import unconditionally. On re-migrate (parent 409), this can still write child vars instead of returning the expected parent-failure skip.

💡 Proposed fix
 case Resource::TYPE_ENVIRONMENT_VARIABLE:
     /** `@var` EnvVar $resource */
+    $function = $resource->getFunc();
+    if ($function->getStatus() !== Resource::STATUS_SUCCESS) {
+        $resource->setStatus(Resource::STATUS_SKIPPED, 'Parent function "' . $function->getId() . '" failed to import');
+        return $resource;
+    }
     $this->functions->createVariable(
-        $resource->getFunc()->getId(),
+        $function->getId(),
         $resource->getKey(),
         $resource->getValue()
     );
     break;
 case Resource::TYPE_SITE_VARIABLE:
     /** `@var` SiteEnvVar $resource */
+    $site = $resource->getSite();
+    if ($site->getStatus() !== Resource::STATUS_SUCCESS) {
+        $resource->setStatus(Resource::STATUS_SKIPPED, 'Parent site "' . $site->getId() . '" failed to import');
+        return $resource;
+    }
     $this->sites->createVariable(
-        $resource->getSite()->getId(),
+        $site->getId(),
         $resource->getKey(),
         $resource->getValue()
     );
     break;

Also applies to: 1663-1669

🤖 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 1452 - 1459, The EnvVar
creation block (case Resource::TYPE_ENVIRONMENT_VARIABLE) currently calls
$this->functions->createVariable unconditionally; change it to first check the
parent import result/status and only call $this->functions->createVariable when
the parent import succeeded (i.e. not failed/skipped/returned 409); if the
parent failed or was skipped, skip creating the variable and mark the child as
skipped. Apply the same guard to the analogous site-variable creation block (the
one around lines handling site variables) so both function and site variables
respect parent-status before calling createVariable.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In `@src/Migration/Destinations/Appwrite.php`:
- Around line 1452-1459: The EnvVar creation block (case
Resource::TYPE_ENVIRONMENT_VARIABLE) currently calls
$this->functions->createVariable unconditionally; change it to first check the
parent import result/status and only call $this->functions->createVariable when
the parent import succeeded (i.e. not failed/skipped/returned 409); if the
parent failed or was skipped, skip creating the variable and mark the child as
skipped. Apply the same guard to the analogous site-variable creation block (the
one around lines handling site variables) so both function and site variables
respect parent-status before calling createVariable.

ℹ️ Review info

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 541efc8 and f27276b.

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

When exportOnlyActive is true, functions/sites without an active
deployment ID should be skipped entirely rather than falling back
to the full paginated listing.
@abnegate abnegate merged commit c2d0169 into main Mar 4, 2026
4 checks passed
@abnegate abnegate deleted the fix-export-inactive-deployments branch March 4, 2026 07:08
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.

2 participants