mirror of
https://github.com/appwrite/appwrite
synced 2026-05-23 00:49:02 +00:00
Merge pull request #11207 from appwrite/migration-endpoint
This commit is contained in:
commit
dfdbcf015c
2 changed files with 57 additions and 55 deletions
52
composer.lock
generated
52
composer.lock
generated
|
|
@ -283,16 +283,16 @@
|
|||
},
|
||||
{
|
||||
"name": "brick/math",
|
||||
"version": "0.14.1",
|
||||
"version": "0.14.3",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/brick/math.git",
|
||||
"reference": "f05858549e5f9d7bb45875a75583240a38a281d0"
|
||||
"reference": "6af96b11de3f7d99730c118c200418c48274edb4"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/brick/math/zipball/f05858549e5f9d7bb45875a75583240a38a281d0",
|
||||
"reference": "f05858549e5f9d7bb45875a75583240a38a281d0",
|
||||
"url": "https://api.github.com/repos/brick/math/zipball/6af96b11de3f7d99730c118c200418c48274edb4",
|
||||
"reference": "6af96b11de3f7d99730c118c200418c48274edb4",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
|
|
@ -331,7 +331,7 @@
|
|||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/brick/math/issues",
|
||||
"source": "https://github.com/brick/math/tree/0.14.1"
|
||||
"source": "https://github.com/brick/math/tree/0.14.3"
|
||||
},
|
||||
"funding": [
|
||||
{
|
||||
|
|
@ -339,7 +339,7 @@
|
|||
"type": "github"
|
||||
}
|
||||
],
|
||||
"time": "2025-11-24T14:40:29+00:00"
|
||||
"time": "2026-02-01T15:18:05+00:00"
|
||||
},
|
||||
{
|
||||
"name": "chillerlan/php-qrcode",
|
||||
|
|
@ -756,16 +756,16 @@
|
|||
},
|
||||
{
|
||||
"name": "google/protobuf",
|
||||
"version": "v4.33.4",
|
||||
"version": "v4.33.5",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/protocolbuffers/protobuf-php.git",
|
||||
"reference": "22d28025cda0d223a2e48c2e16c5284ecc9f5402"
|
||||
"reference": "ebe8010a61b2ae0cff0d246fe1c4d44e9f7dfa6d"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/protocolbuffers/protobuf-php/zipball/22d28025cda0d223a2e48c2e16c5284ecc9f5402",
|
||||
"reference": "22d28025cda0d223a2e48c2e16c5284ecc9f5402",
|
||||
"url": "https://api.github.com/repos/protocolbuffers/protobuf-php/zipball/ebe8010a61b2ae0cff0d246fe1c4d44e9f7dfa6d",
|
||||
"reference": "ebe8010a61b2ae0cff0d246fe1c4d44e9f7dfa6d",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
|
|
@ -794,9 +794,9 @@
|
|||
"proto"
|
||||
],
|
||||
"support": {
|
||||
"source": "https://github.com/protocolbuffers/protobuf-php/tree/v4.33.4"
|
||||
"source": "https://github.com/protocolbuffers/protobuf-php/tree/v4.33.5"
|
||||
},
|
||||
"time": "2026-01-12T17:58:43+00:00"
|
||||
"time": "2026-01-29T20:49:00+00:00"
|
||||
},
|
||||
{
|
||||
"name": "halaxa/json-machine",
|
||||
|
|
@ -3615,16 +3615,16 @@
|
|||
},
|
||||
{
|
||||
"name": "utopia-php/audit",
|
||||
"version": "2.1.0",
|
||||
"version": "2.1.1",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/utopia-php/audit.git",
|
||||
"reference": "8e0540aa939968418ee3ad2b2c305992a771e142"
|
||||
"reference": "00b1d5c0fe7f912315598ee83278fe74d234b196"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/utopia-php/audit/zipball/8e0540aa939968418ee3ad2b2c305992a771e142",
|
||||
"reference": "8e0540aa939968418ee3ad2b2c305992a771e142",
|
||||
"url": "https://api.github.com/repos/utopia-php/audit/zipball/00b1d5c0fe7f912315598ee83278fe74d234b196",
|
||||
"reference": "00b1d5c0fe7f912315598ee83278fe74d234b196",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
|
|
@ -3658,9 +3658,9 @@
|
|||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/utopia-php/audit/issues",
|
||||
"source": "https://github.com/utopia-php/audit/tree/2.1.0"
|
||||
"source": "https://github.com/utopia-php/audit/tree/2.1.1"
|
||||
},
|
||||
"time": "2026-01-22T12:40:48+00:00"
|
||||
"time": "2026-02-01T08:12:53+00:00"
|
||||
},
|
||||
{
|
||||
"name": "utopia-php/auth",
|
||||
|
|
@ -3961,16 +3961,16 @@
|
|||
},
|
||||
{
|
||||
"name": "utopia-php/database",
|
||||
"version": "4.6.1",
|
||||
"version": "4.6.4",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/utopia-php/database.git",
|
||||
"reference": "8795a7f5bf8828955299ae44e5946f93a2b1bde5"
|
||||
"reference": "4dfffd4d528f89b3b3fc09180d4c965ef9bdae30"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/utopia-php/database/zipball/8795a7f5bf8828955299ae44e5946f93a2b1bde5",
|
||||
"reference": "8795a7f5bf8828955299ae44e5946f93a2b1bde5",
|
||||
"url": "https://api.github.com/repos/utopia-php/database/zipball/4dfffd4d528f89b3b3fc09180d4c965ef9bdae30",
|
||||
"reference": "4dfffd4d528f89b3b3fc09180d4c965ef9bdae30",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
|
|
@ -4013,9 +4013,9 @@
|
|||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/utopia-php/database/issues",
|
||||
"source": "https://github.com/utopia-php/database/tree/4.6.1"
|
||||
"source": "https://github.com/utopia-php/database/tree/4.6.4"
|
||||
},
|
||||
"time": "2026-01-21T09:37:22+00:00"
|
||||
"time": "2026-01-30T08:19:14+00:00"
|
||||
},
|
||||
{
|
||||
"name": "utopia-php/detector",
|
||||
|
|
@ -9052,7 +9052,7 @@
|
|||
],
|
||||
"aliases": [],
|
||||
"minimum-stability": "stable",
|
||||
"stability-flags": {},
|
||||
"stability-flags": [],
|
||||
"prefer-stable": false,
|
||||
"prefer-lowest": false,
|
||||
"platform": {
|
||||
|
|
@ -9076,5 +9076,5 @@
|
|||
"platform-overrides": {
|
||||
"php": "8.3"
|
||||
},
|
||||
"plugin-api-version": "2.9.0"
|
||||
"plugin-api-version": "2.6.0"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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,18 +224,17 @@ class Migrations extends Action
|
|||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
protected function processDestination(Document $migration, string $apiKey, array $platform): Destination
|
||||
protected function processDestination(Document $migration): Destination
|
||||
{
|
||||
$destination = $migration->getAttribute('destination');
|
||||
$options = $migration->getAttribute('options', []);
|
||||
|
||||
$protocol = System::getEnv('_APP_OPTIONS_FORCE_HTTPS') === 'disabled' ? 'http' : 'https';
|
||||
$credentials = $migration->getAttribute('credentials');
|
||||
|
||||
return match ($destination) {
|
||||
DestinationAppwrite::getName() => new DestinationAppwrite(
|
||||
$this->project->getId(),
|
||||
$protocol . '://' . $platform['apiHostname'] . '/v1',
|
||||
$apiKey,
|
||||
$credentials['destinationEndpoint'],
|
||||
$credentials['destinationApiKey'],
|
||||
$this->dbForProject,
|
||||
Config::getParam('collections', [])['databases']['collections'],
|
||||
),
|
||||
|
|
@ -335,31 +333,35 @@ class Migrations extends Action
|
|||
|
||||
$transfer = $source = $destination = null;
|
||||
|
||||
$protocol = System::getEnv('_APP_OPTIONS_FORCE_HTTPS') === 'disabled' ? 'http' : 'https';
|
||||
$endpoint = $protocol . '://' . $platform['apiHostname'] . '/v1';
|
||||
|
||||
try {
|
||||
if (
|
||||
$migration->getAttribute('source') === SourceAppwrite::getName() &&
|
||||
empty($migration->getAttribute('credentials', []))
|
||||
) {
|
||||
$credentials = $migration->getAttribute('credentials', []);
|
||||
$credentials = $migration->getAttribute('credentials', []);
|
||||
|
||||
if ($migration->getAttribute('source') === SourceAppwrite::getName()) {
|
||||
$credentials['projectId'] = $credentials['projectId'] ?? $project->getId();
|
||||
$credentials['apiKey'] = $credentials['apiKey'] ?? $tempAPIKey;
|
||||
|
||||
/**
|
||||
* endpoint set
|
||||
*/
|
||||
if (empty($credentials['endpoint'])) {
|
||||
$protocol = System::getEnv('_APP_OPTIONS_FORCE_HTTPS') === 'disabled' ? 'http' : 'https';
|
||||
$credentials['endpoint'] = $protocol . '://' . $platform['apiHostname'] . '/v1';
|
||||
}
|
||||
$migration->setAttribute('credentials', $credentials);
|
||||
$credentials['endpoint'] = $credentials['endpoint'] ?? $endpoint;
|
||||
}
|
||||
|
||||
if ($migration->getAttribute('destination') === DestinationAppwrite::getName()) {
|
||||
$credentials['destinationApiKey'] = $tempAPIKey;
|
||||
$credentials['destinationEndpoint'] = $endpoint;
|
||||
}
|
||||
|
||||
if (($credentials['endpoint'] ?? '') === 'http://localhost/v1') {
|
||||
$credentials['endpoint'] = $endpoint;
|
||||
}
|
||||
|
||||
$migration->setAttribute('credentials', $credentials);
|
||||
|
||||
$migration->setAttribute('stage', 'processing');
|
||||
$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);
|
||||
|
||||
$transfer = new Transfer(
|
||||
$source,
|
||||
|
|
@ -479,6 +481,7 @@ class Migrations extends Action
|
|||
array $platform,
|
||||
Authorization $authorization,
|
||||
): void {
|
||||
$credentials = $migration->getAttribute('credentials', []);
|
||||
$options = $migration->getAttribute('options', []);
|
||||
$bucketId = 'default'; // Always use platform default bucket
|
||||
$filename = $options['filename'] ?? 'export_' . \time();
|
||||
|
|
@ -574,9 +577,8 @@ class Migrations extends Action
|
|||
]);
|
||||
|
||||
// Generate download URL with JWT
|
||||
$endpoint = System::getEnv('_APP_DOMAIN', '');
|
||||
$protocol = System::getEnv('_APP_OPTIONS_FORCE_HTTPS', 'disabled') === 'enabled' ? 'https' : 'http';
|
||||
$downloadUrl = "{$protocol}://{$endpoint}/v1/storage/buckets/{$bucketId}/files/{$fileId}/push?project={$project->getId()}&jwt={$jwt}";
|
||||
|
||||
$downloadUrl = "{$credentials['endpoint']}/storage/buckets/{$bucketId}/files/{$fileId}/push?project={$project->getId()}&jwt={$jwt}";
|
||||
$options['downloadUrl'] = $downloadUrl;
|
||||
$migration->setAttribute('options', $options);
|
||||
$this->updateMigrationDocument($migration, $project, $queueForRealtime);
|
||||
|
|
|
|||
Loading…
Reference in a new issue