This commit is contained in:
fogelito 2026-01-29 17:13:01 +02:00
parent b1ca73a041
commit e8d40a48dc
4 changed files with 29 additions and 27 deletions

1
.env
View file

@ -130,3 +130,4 @@ _APP_PROJECT_REGIONS=default
_APP_FUNCTIONS_CREATION_ABUSE_LIMIT=5000
_APP_STATS_USAGE_DUAL_WRITING_DBS=database_db_main
_APP_TRUSTED_HEADERS=x-forwarded-for
_APP_MIGRATION_ENDPOINT=http://appwrite.test/v1

4
composer.lock generated
View file

@ -9051,7 +9051,7 @@
],
"aliases": [],
"minimum-stability": "stable",
"stability-flags": {},
"stability-flags": [],
"prefer-stable": false,
"prefer-lowest": false,
"platform": {
@ -9075,5 +9075,5 @@
"platform-overrides": {
"php": "8.3"
},
"plugin-api-version": "2.9.0"
"plugin-api-version": "2.6.0"
}

View file

@ -227,6 +227,7 @@ services:
- _APP_FUNCTIONS_CREATION_ABUSE_LIMIT
- _APP_CUSTOM_DOMAIN_DENY_LIST
- _APP_TRUSTED_HEADERS
- _APP_MIGRATION_ENDPOINT
extra_hosts:
- "host.docker.internal:host-gateway"
@ -805,6 +806,7 @@ services:
- _APP_MIGRATIONS_FIREBASE_CLIENT_SECRET
- _APP_DATABASE_SHARED_TABLES
- _APP_OPTIONS_FORCE_HTTPS
- _APP_MIGRATION_ENDPOINT
appwrite-task-maintenance:
entrypoint: maintenance

View file

@ -26,7 +26,6 @@ use Utopia\Migration\Destinations\Appwrite as DestinationAppwrite;
use Utopia\Migration\Destinations\CSV as DestinationCSV;
use Utopia\Migration\Exception as MigrationException;
use Utopia\Migration\Source;
use Utopia\Migration\Sources\Appwrite;
use Utopia\Migration\Sources\Appwrite as SourceAppwrite;
use Utopia\Migration\Sources\CSV;
use Utopia\Migration\Sources\Firebase;
@ -160,19 +159,19 @@ class Migrations extends Action
/**
* @throws Exception
*/
protected function processSource(Document $migration, array $platform): Source
protected function processSource(Document $migration): Source
{
$source = $migration->getAttribute('source');
$destination = $migration->getAttribute('destination');
$resourceId = $migration->getAttribute('resourceId');
$credentials = $migration->getAttribute('credentials');
$migrationOptions = $migration->getAttribute('options');
$dataSource = Appwrite::SOURCE_API;
$dataSource = SourceAppwrite::SOURCE_API;
$database = null;
$queries = [];
if ($source === Appwrite::getName() && $destination === DestinationCSV::getName()) {
$dataSource = Appwrite::SOURCE_DATABASE;
if ($source === SourceAppwrite::getName() && $destination === DestinationCSV::getName()) {
$dataSource = SourceAppwrite::SOURCE_DATABASE;
$database = $this->dbForProject;
$queries = Query::parseQueries($migrationOptions['queries']);
}
@ -225,17 +224,15 @@ class Migrations extends Action
/**
* @throws Exception
*/
protected function processDestination(Document $migration, string $apiKey, array $platform): Destination
protected function processDestination(Document $migration, string $apiKey, string $endpoint): Destination
{
$destination = $migration->getAttribute('destination');
$options = $migration->getAttribute('options', []);
$protocol = System::getEnv('_APP_OPTIONS_FORCE_HTTPS') === 'disabled' ? 'http' : 'https';
return match ($destination) {
DestinationAppwrite::getName() => new DestinationAppwrite(
$this->project->getId(),
$protocol . '://' . $platform['apiHostname'] . '/v1',
$endpoint,
$apiKey,
$this->dbForProject,
Config::getParam('collections', [])['databases']['collections'],
@ -335,22 +332,24 @@ class Migrations extends Action
$transfer = $source = $destination = null;
try {
if (
$migration->getAttribute('source') === SourceAppwrite::getName() &&
empty($migration->getAttribute('credentials', []))
) {
$credentials = $migration->getAttribute('credentials', []);
$credentials['projectId'] = $credentials['projectId'] ?? $project->getId();
$credentials['apiKey'] = $credentials['apiKey'] ?? $tempAPIKey;
//$protocol = System::getEnv('_APP_OPTIONS_FORCE_HTTPS') === 'disabled' ? 'http' : 'https';
// $endpoint = $protocol . '://' . $platform['apiHostname'] . '/v1';
$endpoint = System::getEnv('_APP_MIGRATION_ENDPOINT');
/**
* endpoint set
*/
if (empty($credentials['endpoint'])) {
$protocol = System::getEnv('_APP_OPTIONS_FORCE_HTTPS') === 'disabled' ? 'http' : 'https';
$credentials['endpoint'] = $protocol . '://' . $platform['apiHostname'] . '/v1';
try {
if ($migration->getAttribute('source') === SourceAppwrite::getName()) {
$credentials = $migration->getAttribute('credentials', []);
if (empty($credentials)) {
$credentials['projectId'] = $project->getId();
$credentials['apiKey'] = $tempAPIKey;
$credentials['endpoint'] = $endpoint;
}
if (($credentials['endpoint'] ?? '') === 'http://localhost/v1') {
$credentials['endpoint'] = $endpoint;
}
$migration->setAttribute('credentials', $credentials);
}
@ -358,8 +357,8 @@ class Migrations extends Action
$migration->setAttribute('status', 'processing');
$this->updateMigrationDocument($migration, $project, $queueForRealtime);
$source = $this->processSource($migration, $platform);
$destination = $this->processDestination($migration, $tempAPIKey, $platform);
$source = $this->processSource($migration);
$destination = $this->processDestination($migration, $tempAPIKey, $endpoint);
$transfer = new Transfer(
$source,