mirror of
https://github.com/appwrite/appwrite
synced 2026-05-23 08:58:35 +00:00
Merge pull request #10976 from appwrite/platforms-in-migrations
This commit is contained in:
commit
8d94b6585e
3 changed files with 47 additions and 25 deletions
|
|
@ -69,10 +69,11 @@ App::post('/v1/migrations/appwrite')
|
|||
->inject('response')
|
||||
->inject('dbForProject')
|
||||
->inject('project')
|
||||
->inject('platform')
|
||||
->inject('user')
|
||||
->inject('queueForEvents')
|
||||
->inject('queueForMigrations')
|
||||
->action(function (array $resources, string $endpoint, string $projectId, string $apiKey, Response $response, Database $dbForProject, Document $project, Document $user, Event $queueForEvents, Migration $queueForMigrations) {
|
||||
->action(function (array $resources, string $endpoint, string $projectId, string $apiKey, Response $response, Database $dbForProject, Document $project, array $platform, Document $user, Event $queueForEvents, Migration $queueForMigrations) {
|
||||
$migration = $dbForProject->createDocument('migrations', new Document([
|
||||
'$id' => ID::unique(),
|
||||
'status' => 'pending',
|
||||
|
|
@ -96,6 +97,7 @@ App::post('/v1/migrations/appwrite')
|
|||
$queueForMigrations
|
||||
->setMigration($migration)
|
||||
->setProject($project)
|
||||
->setPlatform($platform)
|
||||
->setUser($user)
|
||||
->trigger();
|
||||
|
||||
|
|
@ -128,10 +130,11 @@ App::post('/v1/migrations/firebase')
|
|||
->inject('response')
|
||||
->inject('dbForProject')
|
||||
->inject('project')
|
||||
->inject('platform')
|
||||
->inject('user')
|
||||
->inject('queueForEvents')
|
||||
->inject('queueForMigrations')
|
||||
->action(function (array $resources, string $serviceAccount, Response $response, Database $dbForProject, Document $project, Document $user, Event $queueForEvents, Migration $queueForMigrations) {
|
||||
->action(function (array $resources, string $serviceAccount, Response $response, Database $dbForProject, Document $project, array $platform, Document $user, Event $queueForEvents, Migration $queueForMigrations) {
|
||||
$serviceAccountData = json_decode($serviceAccount, true);
|
||||
|
||||
if (empty($serviceAccountData)) {
|
||||
|
|
@ -163,6 +166,7 @@ App::post('/v1/migrations/firebase')
|
|||
$queueForMigrations
|
||||
->setMigration($migration)
|
||||
->setProject($project)
|
||||
->setPlatform($platform)
|
||||
->setUser($user)
|
||||
->trigger();
|
||||
|
||||
|
|
@ -200,10 +204,11 @@ App::post('/v1/migrations/supabase')
|
|||
->inject('response')
|
||||
->inject('dbForProject')
|
||||
->inject('project')
|
||||
->inject('platform')
|
||||
->inject('user')
|
||||
->inject('queueForEvents')
|
||||
->inject('queueForMigrations')
|
||||
->action(function (array $resources, string $endpoint, string $apiKey, string $databaseHost, string $username, string $password, int $port, Response $response, Database $dbForProject, Document $project, Document $user, Event $queueForEvents, Migration $queueForMigrations) {
|
||||
->action(function (array $resources, string $endpoint, string $apiKey, string $databaseHost, string $username, string $password, int $port, Response $response, Database $dbForProject, Document $project, array $platform, Document $user, Event $queueForEvents, Migration $queueForMigrations) {
|
||||
$migration = $dbForProject->createDocument('migrations', new Document([
|
||||
'$id' => ID::unique(),
|
||||
'status' => 'pending',
|
||||
|
|
@ -230,6 +235,7 @@ App::post('/v1/migrations/supabase')
|
|||
$queueForMigrations
|
||||
->setMigration($migration)
|
||||
->setProject($project)
|
||||
->setPlatform($platform)
|
||||
->setUser($user)
|
||||
->trigger();
|
||||
|
||||
|
|
@ -268,10 +274,11 @@ App::post('/v1/migrations/nhost')
|
|||
->inject('response')
|
||||
->inject('dbForProject')
|
||||
->inject('project')
|
||||
->inject('platform')
|
||||
->inject('user')
|
||||
->inject('queueForEvents')
|
||||
->inject('queueForMigrations')
|
||||
->action(function (array $resources, string $subdomain, string $region, string $adminSecret, string $database, string $username, string $password, int $port, Response $response, Database $dbForProject, Document $project, Document $user, Event $queueForEvents, Migration $queueForMigrations) {
|
||||
->action(function (array $resources, string $subdomain, string $region, string $adminSecret, string $database, string $username, string $password, int $port, Response $response, Database $dbForProject, Document $project, array $platform, Document $user, Event $queueForEvents, Migration $queueForMigrations) {
|
||||
$migration = $dbForProject->createDocument('migrations', new Document([
|
||||
'$id' => ID::unique(),
|
||||
'status' => 'pending',
|
||||
|
|
@ -299,6 +306,7 @@ App::post('/v1/migrations/nhost')
|
|||
$queueForMigrations
|
||||
->setMigration($migration)
|
||||
->setProject($project)
|
||||
->setPlatform($platform)
|
||||
->setUser($user)
|
||||
->trigger();
|
||||
|
||||
|
|
@ -335,6 +343,7 @@ App::post('/v1/migrations/csv/imports')
|
|||
->inject('dbForProject')
|
||||
->inject('dbForPlatform')
|
||||
->inject('project')
|
||||
->inject('platform')
|
||||
->inject('deviceForFiles')
|
||||
->inject('deviceForMigrations')
|
||||
->inject('queueForEvents')
|
||||
|
|
@ -348,6 +357,7 @@ App::post('/v1/migrations/csv/imports')
|
|||
Database $dbForProject,
|
||||
Database $dbForPlatform,
|
||||
Document $project,
|
||||
array $platform,
|
||||
Device $deviceForFiles,
|
||||
Device $deviceForMigrations,
|
||||
Event $queueForEvents,
|
||||
|
|
@ -441,6 +451,7 @@ App::post('/v1/migrations/csv/imports')
|
|||
$queueForMigrations
|
||||
->setMigration($migration)
|
||||
->setProject($project)
|
||||
->setProject($project)
|
||||
->trigger();
|
||||
|
||||
$response
|
||||
|
|
@ -481,6 +492,7 @@ App::post('/v1/migrations/csv/exports')
|
|||
->inject('dbForProject')
|
||||
->inject('dbForPlatform')
|
||||
->inject('project')
|
||||
->inject('platform')
|
||||
->inject('queueForEvents')
|
||||
->inject('queueForMigrations')
|
||||
->action(function (
|
||||
|
|
@ -498,6 +510,7 @@ App::post('/v1/migrations/csv/exports')
|
|||
Database $dbForProject,
|
||||
Database $dbForPlatform,
|
||||
Document $project,
|
||||
array $platform,
|
||||
Event $queueForEvents,
|
||||
Migration $queueForMigrations
|
||||
) {
|
||||
|
|
@ -571,6 +584,7 @@ App::post('/v1/migrations/csv/exports')
|
|||
$queueForMigrations
|
||||
->setMigration($migration)
|
||||
->setProject($project)
|
||||
->setPlatform($platform)
|
||||
->trigger();
|
||||
|
||||
$response
|
||||
|
|
@ -903,9 +917,10 @@ App::patch('/v1/migrations/:migrationId')
|
|||
->inject('response')
|
||||
->inject('dbForProject')
|
||||
->inject('project')
|
||||
->inject('platform')
|
||||
->inject('user')
|
||||
->inject('queueForMigrations')
|
||||
->action(function (string $migrationId, Response $response, Database $dbForProject, Document $project, Document $user, Migration $queueForMigrations) {
|
||||
->action(function (string $migrationId, Response $response, Database $dbForProject, Document $project, array $platform, Document $user, Migration $queueForMigrations) {
|
||||
$migration = $dbForProject->getDocument('migrations', $migrationId);
|
||||
|
||||
if ($migration->isEmpty()) {
|
||||
|
|
@ -924,6 +939,7 @@ App::patch('/v1/migrations/:migrationId')
|
|||
$queueForMigrations
|
||||
->setMigration($migration)
|
||||
->setProject($project)
|
||||
->setPlatform($platform)
|
||||
->setUser($user)
|
||||
->trigger();
|
||||
|
||||
|
|
|
|||
|
|
@ -129,8 +129,7 @@ class Builds extends Action
|
|||
$resource = new Document($payload['resource'] ?? []);
|
||||
$deployment = new Document($payload['deployment'] ?? []);
|
||||
$template = new Document($payload['template'] ?? []);
|
||||
$platform = $payload['platform'] ?? [];
|
||||
|
||||
$platform = $payload['platform'] ?? Config::getParam('platform', []);
|
||||
|
||||
$log->addTag('projectId', $project->getId());
|
||||
$log->addTag('type', $type);
|
||||
|
|
|
|||
|
|
@ -119,12 +119,14 @@ class Migrations extends Action
|
|||
$this->project = $project;
|
||||
$this->logError = $logError;
|
||||
|
||||
$platform = $payload['platform'] ?? Config::getParam('platform', []);
|
||||
|
||||
if (!empty($events)) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
$this->processMigration($migration, $queueForRealtime, $queueForMails);
|
||||
$this->processMigration($migration, $queueForRealtime, $queueForMails, $platform);
|
||||
} finally {
|
||||
$this->dbForProject = null;
|
||||
$this->dbForPlatform = null;
|
||||
|
|
@ -142,7 +144,7 @@ class Migrations extends Action
|
|||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
protected function processSource(Document $migration): Source
|
||||
protected function processSource(Document $migration, array $platform): Source
|
||||
{
|
||||
$source = $migration->getAttribute('source');
|
||||
$destination = $migration->getAttribute('destination');
|
||||
|
|
@ -154,7 +156,6 @@ class Migrations extends Action
|
|||
$queries = [];
|
||||
|
||||
if (($credentials['endpoint'] ?? null) === 'http://localhost/v1') {
|
||||
$platform = Config::getParam('platform', []);
|
||||
$protocol = System::getEnv('_APP_OPTIONS_FORCE_HTTPS') === 'disabled' ? 'http' : 'https';
|
||||
$credentials['endpoint'] = $protocol . '://' . $platform['apiHostname'] . '/v1';
|
||||
}
|
||||
|
|
@ -212,13 +213,12 @@ class Migrations extends Action
|
|||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
protected function processDestination(Document $migration, string $apiKey): Destination
|
||||
protected function processDestination(Document $migration, string $apiKey, array $platform): Destination
|
||||
{
|
||||
$destination = $migration->getAttribute('destination');
|
||||
$options = $migration->getAttribute('options', []);
|
||||
|
||||
$protocol = System::getEnv('_APP_OPTIONS_FORCE_HTTPS') === 'disabled' ? 'http' : 'https';
|
||||
$platform = Config::getParam('platform', []);
|
||||
|
||||
return match ($destination) {
|
||||
DestinationAppwrite::getName() => new DestinationAppwrite(
|
||||
|
|
@ -314,6 +314,7 @@ class Migrations extends Action
|
|||
Document $migration,
|
||||
Realtime $queueForRealtime,
|
||||
Mail $queueForMails,
|
||||
array $platform,
|
||||
): void {
|
||||
$project = $this->dbForPlatform->getDocument('projects', $this->project->getId());
|
||||
$tempAPIKey = $this->generateAPIKey($project);
|
||||
|
|
@ -330,7 +331,6 @@ class Migrations extends Action
|
|||
$credentials['apiKey'] = $credentials['apiKey'] ?? $tempAPIKey;
|
||||
|
||||
if (empty($credentials['endpoint'])) {
|
||||
$platform = Config::getParam('platform', []);
|
||||
$protocol = System::getEnv('_APP_OPTIONS_FORCE_HTTPS') === 'disabled' ? 'http' : 'https';
|
||||
$credentials['endpoint'] = $protocol . '://' . $platform['apiHostname'] . '/v1';
|
||||
}
|
||||
|
|
@ -341,8 +341,8 @@ class Migrations extends Action
|
|||
$migration->setAttribute('status', 'processing');
|
||||
$this->updateMigrationDocument($migration, $project, $queueForRealtime);
|
||||
|
||||
$source = $this->processSource($migration);
|
||||
$destination = $this->processDestination($migration, $tempAPIKey);
|
||||
$source = $this->processSource($migration, $platform);
|
||||
$destination = $this->processDestination($migration, $tempAPIKey, $platform);
|
||||
|
||||
$transfer = new Transfer(
|
||||
$source,
|
||||
|
|
@ -436,7 +436,7 @@ class Migrations extends Action
|
|||
$source?->success();
|
||||
|
||||
if ($migration->getAttribute('destination') === DestinationCSV::getName()) {
|
||||
$this->handleCSVExportComplete($project, $migration, $queueForMails, $queueForRealtime);
|
||||
$this->handleCSVExportComplete($project, $migration, $queueForMails, $queueForRealtime, $platform);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -463,6 +463,7 @@ class Migrations extends Action
|
|||
Document $migration,
|
||||
Mail $queueForMails,
|
||||
Realtime $queueForRealtime,
|
||||
array $platform,
|
||||
): void {
|
||||
$options = $migration->getAttribute('options', []);
|
||||
$bucketId = 'default'; // Always use platform default bucket
|
||||
|
|
@ -512,6 +513,7 @@ class Migrations extends Action
|
|||
user: $user,
|
||||
options: $options,
|
||||
queueForMails: $queueForMails,
|
||||
platform: $platform,
|
||||
sizeMB: $sizeMB
|
||||
);
|
||||
|
||||
|
|
@ -571,6 +573,7 @@ class Migrations extends Action
|
|||
user: $user,
|
||||
options: $options,
|
||||
queueForMails: $queueForMails,
|
||||
platform: $platform,
|
||||
downloadUrl: $downloadUrl
|
||||
);
|
||||
}
|
||||
|
|
@ -583,6 +586,7 @@ class Migrations extends Action
|
|||
* @param Document $user The user who triggered the operation
|
||||
* @param array $options Migration options
|
||||
* @param Mail $queueForMails
|
||||
* @param array $platform
|
||||
* @param string $downloadUrl Download URL for successful exports
|
||||
* @param float $sizeMB File size in MB for failed exports
|
||||
* @return void
|
||||
|
|
@ -594,15 +598,16 @@ class Migrations extends Action
|
|||
Document $user,
|
||||
array $options,
|
||||
Mail $queueForMails,
|
||||
array $platform,
|
||||
string $downloadUrl = '',
|
||||
float $sizeMB = 0.0
|
||||
float $sizeMB = 0.0,
|
||||
): void {
|
||||
if (!($options['notify'] ?? false)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($user->isEmpty()) {
|
||||
Console::warning("User not found for CSV export notification: {$user->getInternalId()}");
|
||||
Console::warning("User not found for CSV export notification: {$user->getSequence()}");
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -649,13 +654,14 @@ class Migrations extends Action
|
|||
|
||||
$emailVariables = [
|
||||
'direction' => $locale->getText('settings.direction'),
|
||||
'logoUrl' => $this->plan['logoUrl'] ?? APP_EMAIL_LOGO_URL,
|
||||
'accentColor' => $this->plan['accentColor'] ?? APP_EMAIL_ACCENT_COLOR,
|
||||
'twitterUrl' => $this->plan['twitterUrl'] ?? APP_SOCIAL_TWITTER,
|
||||
'discordUrl' => $this->plan['discordUrl'] ?? APP_SOCIAL_DISCORD,
|
||||
'githubUrl' => $this->plan['githubUrl'] ?? APP_SOCIAL_GITHUB_APPWRITE,
|
||||
'termsUrl' => $this->plan['termsUrl'] ?? APP_EMAIL_TERMS_URL,
|
||||
'privacyUrl' => $this->plan['privacyUrl'] ?? APP_EMAIL_PRIVACY_URL,
|
||||
'logoUrl' => $platform['logoUrl'],
|
||||
'accentColor' => $platform['accentColor'],
|
||||
'twitter' => $platform['twitterUrl'],
|
||||
'discord' => $platform['discordUrl'],
|
||||
'github' => $platform['githubUrl'],
|
||||
'terms' => $platform['termsUrl'],
|
||||
'privacy' => $platform['privacyUrl'],
|
||||
'platform' => $platform['platformName'],
|
||||
];
|
||||
|
||||
$queueForMails
|
||||
|
|
@ -666,6 +672,7 @@ class Migrations extends Action
|
|||
->setVariables($emailVariables)
|
||||
->setName($user->getAttribute('name', $user->getAttribute('email')))
|
||||
->setRecipient($user->getAttribute('email'))
|
||||
->setSenderName($platform['emailSenderName'])
|
||||
->trigger();
|
||||
|
||||
Console::info("CSV export {$emailType} notification email sent to " . $user->getAttribute('email'));
|
||||
|
|
|
|||
Loading…
Reference in a new issue