Skip to content

Add project variable migration support#184

Open
premtsd-code wants to merge 1 commit into
add-api-key-migrationfrom
add-project-variable-migration
Open

Add project variable migration support#184
premtsd-code wants to merge 1 commit into
add-api-key-migrationfrom
add-project-variable-migration

Conversation

@premtsd-code
Copy link
Copy Markdown
Contributor

Summary

Stacks on #183. Adds project-variable as a migrable resource using the Appwrite SDK's Project::listVariables() (source) and a direct dbForProject->createDocument('variables', ...) (destination) that mirrors upstream Project::Variables::Create exactly.

Notes

  • Resource::TYPE_PROJECT_VARIABLE = 'project-variable' (kebab) — placed in GROUP_INTEGRATIONS_RESOURCES alongside platform/api-key for minimum changes to other Source/Destination implementations.
  • Destination writes resourceType: 'project' (singular, as upstream does for project-scope) with empty resourceInternalId/resourceId and a synthesized search field.
  • Secret variables: the SDK strips value on read for secret variables, so secrets will arrive with empty values. Operator re-enters them on the destination side. (Same caveat as API key secrets.)

Source: Appwrite SDK Project::listVariables() with cursor pagination,
counting via reportIntegrations.

Destination: dbForProject->createDocument('variables', ...) matching
the upstream Project::Variables::Create payload exactly — resourceType
'project' (singular), resourceInternalId/resourceId empty, plus the
search index field.
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented May 14, 2026

Greptile Summary

This PR adds project-variable as a migratable resource, stacking on the API-key migration work in #183. It closely follows the existing Platform and ApiKey patterns throughout the source, destination, and resource layers.

  • New ProjectVariable resource class with fromArray/jsonSerialize and accessors for key, value, and secret; the source reads from project->listVariables() using the same cursor-based pagination loop as exportApiKeys.
  • Destination writes to dbForProject (variables collection) with resourceType = 'project' and empty resourceInternalId/resourceId, mirroring the upstream Project::Variables::Create schema; duplicate detection queries by resourceType + key.
  • TYPE_PROJECT_VARIABLE constant and group membership are correctly registered in Resource.php, Transfer.php, and both the source/destination supportedResources lists.

Confidence Score: 4/5

Safe to merge; the only open question is whether a platform project-cache purge is needed after writing to dbForProject.

The implementation faithfully mirrors the ApiKey/Platform patterns. The one thing that stands out is that createApiKey and createPlatform both call dbForPlatform->purgeCachedDocument('projects', ...) after writing, but createProjectVariable does not. If the platform project cache includes any variable-related metadata this omission could leave stale data, but it may also be intentional since variables live in dbForProject rather than dbForPlatform. The rest of the code — pagination, duplicate detection, resource registration — is consistent and correct.

src/Migration/Destinations/Appwrite.php — the createProjectVariable method is the only spot worth a second look (the cache purge question).

Important Files Changed

Filename Overview
src/Migration/Destinations/Appwrite.php Adds createProjectVariable writing to dbForProject; correctly checks for duplicates and handles DuplicateException, but omits the purgeCachedDocument call present in both createApiKey and createPlatform.
src/Migration/Sources/Appwrite.php Adds exportProjectVariables that uses cursor-based pagination, closely mirroring the existing exportApiKeys implementation.
src/Migration/Resources/Integrations/ProjectVariable.php New resource class mirroring the ApiKey pattern; clean with fromArray, jsonSerialize, and accessors for key, value, and secret fields.
src/Migration/Resource.php Adds TYPE_PROJECT_VARIABLE = 'project-variable' constant and includes it in the all-types list; straightforward and consistent.
src/Migration/Transfer.php Adds TYPE_PROJECT_VARIABLE to GROUP_INTEGRATIONS_RESOURCES alongside platform and api-key; minimal and correct.

Reviews (1): Last reviewed commit: "Add project variable migration support" | Re-trigger Greptile

Comment on lines +3217 to 3225
} catch (DuplicateException) {
$resource->setStatus(Resource::STATUS_SKIPPED, 'Project variable already exists');
return false;
}

return true;
}

private function validateFieldsForIndexes(Index $resource, UtopiaDocument $table, array &$lengths)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 Both createPlatform and createApiKey call $this->dbForPlatform->purgeCachedDocument('projects', $this->project) after writing their documents. createProjectVariable omits this. If the platform's projects document caches any project-level metadata (variable counts, etc.), created variables won't be reflected until the cache naturally expires. Worth verifying against the upstream Project::Variables::Create implementation to confirm whether the purge is needed here too.

Suggested change
} catch (DuplicateException) {
$resource->setStatus(Resource::STATUS_SKIPPED, 'Project variable already exists');
return false;
}
return true;
}
private function validateFieldsForIndexes(Index $resource, UtopiaDocument $table, array &$lengths)
} catch (DuplicateException) {
$resource->setStatus(Resource::STATUS_SKIPPED, 'Project variable already exists');
return false;
}
$this->dbForPlatform->purgeCachedDocument('projects', $this->project);
return true;
}
private function validateFieldsForIndexes(Index $resource, UtopiaDocument $table, array &$lengths)

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