Skip to content

Add project variable migration support#184

Merged
abnegate merged 5 commits into
mainfrom
add-project-variable-migration
May 28, 2026
Merged

Add project variable migration support#184
abnegate merged 5 commits into
mainfrom
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.)

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented May 14, 2026

Greptile Summary

This PR introduces project-variable as a migratable resource type, enabling project-level environment variables to be exported from an Appwrite source and written directly to the destination project's variables collection.

  • A new ProjectVariable resource class is added under Resources/Settings/, and TYPE_PROJECT_VARIABLE is wired into Transfer::GROUP_SETTINGS_RESOURCES, ALL_PUBLIC_RESOURCES, and the extractServices match expression.
  • Sources/Appwrite.php gains exportGroupSettings/exportProjectVariables (pagination mirrors exportApiKeys), and Destinations/Appwrite.php gains createProjectVariable with a pre-flight duplicate check plus DuplicateException guard.
  • All non-Appwrite sources (CSV, Firebase, JSON, NHost, MockSource) implement the new abstract exportGroupSettings stub, and Source.php maps the group in its export dispatch.

Confidence Score: 5/5

Safe to merge; bulk migration works correctly end-to-end.

The implementation faithfully follows the established patterns for api-key and platform migration. The one observation — TYPE_PROJECT_VARIABLE missing from ROOT_RESOURCES — makes the per-variable rootResourceId filter unreachable but does not affect normal bulk migration.

src/Migration/Transfer.php has the ROOT_RESOURCES gap worth a follow-up if single-variable export by ID is desired.

Important Files Changed

Filename Overview
src/Migration/Resources/Settings/ProjectVariable.php New resource class for project-scoped variables; mirrors pattern of other resource types, correct group/name wiring.
src/Migration/Sources/Appwrite.php Adds exportGroupSettings and exportProjectVariables; rootResourceId filter branch is unreachable because TYPE_PROJECT_VARIABLE is absent from ROOT_RESOURCES.
src/Migration/Destinations/Appwrite.php Adds importSettingsResource and createProjectVariable; duplicate-check and DuplicateException handling look correct; follows same pattern as createApiKey/createPlatform.
src/Migration/Transfer.php Adds GROUP_SETTINGS constant, GROUP_SETTINGS_RESOURCES, and the missing extractServices match arm; all wiring appears complete.
src/Migration/Resource.php Adds TYPE_PROJECT_VARIABLE constant with correct kebab-case value; added to ALL_PUBLIC_RESOURCES.
src/Migration/Source.php Adds abstract exportGroupSettings, getSettingsBatchSize helper, and GROUP_SETTINGS mapping; consistent with other group additions.
tests/Migration/Unit/Adapters/MockSource.php Adds exportGroupSettings stub to MockSource; follows same pattern as other group stubs.

Reviews (6): Last reviewed commit: "Merge branch 'main' into add-project-var..." | Re-trigger Greptile

Comment thread src/Migration/Destinations/Appwrite.php Outdated
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)

Introduces Transfer::GROUP_SETTINGS for project-level configuration
resources that aren't external integrations. Project variables are
the first inhabitant; webhooks will follow in a stacked PR.

- New abstract Source::exportGroupSettings() with no-op stubs in
  CSV/JSON/Firebase/NHost sources.
- Appwrite source: project variables exported via Project SDK
  listVariables() with cursor pagination.
- Appwrite destination: createProjectVariable writes directly to
  dbForProject 'variables' collection, mirroring upstream Project
  Variables Create payload (resourceType 'project', empty resource id).
@premtsd-code premtsd-code force-pushed the add-project-variable-migration branch from c040472 to 3376bed Compare May 14, 2026 19:00
- MockSource now stubs exportGroupSettings so the class is concrete
  (clears PHPUnit fatal + PHPStan level-3 error).
- Pint ordered_imports auto-fix on Sources/Appwrite.php and
  Destinations/Appwrite.php.
The GROUP_SETTINGS const was added in this branch (with project-variable
under it) but the extractServices() match was never updated. Any caller
passing Transfer::GROUP_SETTINGS hits the 'No service group found'
default branch even though GROUP_SETTINGS_RESOURCES is populated.
Base automatically changed from add-api-key-migration to main May 28, 2026 06:23
@abnegate abnegate merged commit 0d10f71 into main May 28, 2026
4 checks passed
@abnegate abnegate deleted the add-project-variable-migration branch May 28, 2026 06:28
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