You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When migrating databases from Appwrite Cloud to a self-hosted Appwrite instance, the migration worker crashes with a PHP warning: Warning: Undefined array key "database" in .../Migration/Sources/Appwrite.php on line 868
Root Cause
In exportDatabases(), the code builds a database object using the raw API response from Appwrite Cloud:
Newer versions of the Appwrite Cloud API do not return the internal database key in the database listing response. This causes a fatal PHP warning that halts the migration.
Fix
Updated the logic to use null instead of an empty string '' for the database field when it's missing from the source. This is crucial because:
An empty string '' causes Appwrite 1.9.0 to attempt parsing an invalid DSN (e.g., mysql://), leading to HTTP 500 errors.
Using null allows Appwrite's internal getAttribute() logic to correctly trigger the default fallback to the internal connection pool (e.g., database_db_main).
'database' => $database['database'] ?? null,
Testing
Tested successfully by performing a full Cloud to self-hosted migration:
1 database migrated
15 tables migrated
141 columns migrated
11,791 rows migrated
Adds a ?? null null-coalescing fallback for the database key in exportDatabases(), preventing a PHP warning when the Appwrite Cloud API omits that field. The chosen null fallback is consistent with Database::fromArray()'s own default for this field, addressing the prior review concern. Note: the PR description mentions ?? '' as the fix, but the actual committed code correctly uses ?? null.
Confidence Score: 5/5
Safe to merge — minimal, targeted fix with correct semantics.
The change is a single-line null-coalescing guard with the correct null default (consistent with how Database::fromArray() handles the same field). No P0/P1 issues remain.
No files require special attention.
Important Files Changed
Filename
Overview
src/Migration/Sources/Appwrite.php
Single-line null-coalescing fix for missing 'database' key in API response; uses null fallback consistent with Database::fromArray() defaults.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
When migrating databases from Appwrite Cloud to a self-hosted Appwrite instance, the migration worker crashes with a PHP warning:
Warning: Undefined array key "database" in .../Migration/Sources/Appwrite.php on line 868Root Cause
In
exportDatabases(), the code builds a database object using the raw API response from Appwrite Cloud:Newer versions of the Appwrite Cloud API do not return the internal
databasekey in the database listing response. This causes a fatal PHP warning that halts the migration.Fix
Updated the logic to use
nullinstead of an empty string''for thedatabasefield when it's missing from the source. This is crucial because:''causes Appwrite 1.9.0 to attempt parsing an invalid DSN (e.g.,mysql://), leading to HTTP 500 errors.nullallows Appwrite's internalgetAttribute()logic to correctly trigger the default fallback to the internal connection pool (e.g.,database_db_main).Testing
Tested successfully by performing a full Cloud to self-hosted migration:
1 database migrated
15 tables migrated
141 columns migrated
11,791 rows migrated