Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/Migration/Destinations/Appwrite.php
Original file line number Diff line number Diff line change
Expand Up @@ -2473,8 +2473,8 @@ functionId: $resource->getId(),
entrypoint: $resource->getEntrypoint(),
commands: $resource->getCommands(),
scopes: $resource->getScopes(),
buildSpecification: $resource->getSpecification() ?: null,
runtimeSpecification: $resource->getSpecification() ?: null,
buildSpecification: $resource->getBuildSpecification() ?: null,
runtimeSpecification: $resource->getRuntimeSpecification() ?: null,
);
break;
case Resource::TYPE_ENVIRONMENT_VARIABLE:
Expand Down Expand Up @@ -2662,8 +2662,8 @@ public function importSiteResource(Resource $resource): Resource
outputDirectory: $resource->getOutputDirectory(),
adapter: $adapter,
fallbackFile: $resource->getFallbackFile(),
buildSpecification: $resource->getSpecification() ?: null,
runtimeSpecification: $resource->getSpecification() ?: null,
buildSpecification: $resource->getBuildSpecification() ?: null,
runtimeSpecification: $resource->getRuntimeSpecification() ?: null,
);
break;
case Resource::TYPE_SITE_VARIABLE:
Expand Down
19 changes: 17 additions & 2 deletions src/Migration/Resources/Functions/Func.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class Func extends Resource
* @param bool $logging
* @param array<string> $scopes
* @param string $specification
* @param string $buildSpecification
*/
public function __construct(
string $id,
Expand All @@ -37,7 +38,8 @@ public function __construct(
private readonly string $commands = '',
private readonly bool $logging = true,
private readonly array $scopes = [],
private readonly string $specification = ''
private readonly string $specification = '',
private readonly string $buildSpecification = ''
) {
$this->id = $id;
}
Expand All @@ -62,7 +64,8 @@ public static function fromArray(array $array): self
$array['commands'] ?? '',
$array['logging'] ?? true,
$array['scopes'] ?? [],
$array['specification'] ?? ''
$array['runtimeSpecification'] ?? $array['specification'] ?? '',
$array['buildSpecification'] ?? $array['specification'] ?? ''
);
}

Expand All @@ -86,6 +89,8 @@ public function jsonSerialize(): array
'logging' => $this->logging,
'scopes' => $this->scopes,
'specification' => $this->specification,
'runtimeSpecification' => $this->specification,
'buildSpecification' => $this->buildSpecification,
];
}

Expand Down Expand Up @@ -172,4 +177,14 @@ public function getSpecification(): string
{
return $this->specification;
}

public function getRuntimeSpecification(): string
{
return $this->specification;
}

public function getBuildSpecification(): string
{
return $this->buildSpecification ?: $this->specification;
}
}
21 changes: 18 additions & 3 deletions src/Migration/Resources/Sites/Site.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class Site extends Resource
* @param string $fallbackFile
* @param string $specification
* @param string $activeDeployment
* @param string $buildSpecification
*/
public function __construct(
string $id,
Expand All @@ -37,7 +38,8 @@ public function __construct(
private readonly string $adapter = 'static',
private readonly string $fallbackFile = '',
private readonly string $specification = '',
private readonly string $activeDeployment = ''
private readonly string $activeDeployment = '',
private readonly string $buildSpecification = ''
) {
$this->id = $id;
}
Expand All @@ -61,8 +63,9 @@ public static function fromArray(array $array): self
$array['outputDirectory'] ?? '',
$array['adapter'] ?? 'static',
$array['fallbackFile'] ?? '',
$array['specification'] ?? '',
$array['activeDeployment'] ?? ''
$array['runtimeSpecification'] ?? $array['specification'] ?? '',
$array['activeDeployment'] ?? '',
$array['buildSpecification'] ?? $array['specification'] ?? ''
);
}

Expand All @@ -85,7 +88,9 @@ public function jsonSerialize(): array
'adapter' => $this->adapter,
'fallbackFile' => $this->fallbackFile,
'specification' => $this->specification,
'runtimeSpecification' => $this->specification,
'activeDeployment' => $this->activeDeployment,
'buildSpecification' => $this->buildSpecification,
];
}

Expand Down Expand Up @@ -159,6 +164,16 @@ public function getSpecification(): string
return $this->specification;
}

public function getRuntimeSpecification(): string
{
return $this->specification;
}

public function getBuildSpecification(): string
{
return $this->buildSpecification ?: $this->specification;
}

public function getActiveDeployment(): string
{
return $this->activeDeployment;
Expand Down
8 changes: 5 additions & 3 deletions src/Migration/Sources/Appwrite.php
Original file line number Diff line number Diff line change
Expand Up @@ -2149,7 +2149,8 @@ private function exportFunctions(int $batchSize): void
$function->commands ?? '',
$function->logging ?? true,
$function->scopes ?? [],
$function->runtimeSpecification ?: $function->buildSpecification ?: '',
$function->runtimeSpecification ?: '',
$function->buildSpecification ?: '',
);
$functions[] = $convertedFunc;

Expand Down Expand Up @@ -2732,8 +2733,9 @@ private function exportSites(int $batchSize): void
$site->outputDirectory ?? '',
$site->adapter ?? 'static',
$site->fallbackFile ?? '',
$site->runtimeSpecification ?: $site->buildSpecification ?: '',
$site->deploymentId ?? ''
$site->runtimeSpecification ?: '',
$site->deploymentId ?? '',
$site->buildSpecification ?: ''
);
$sites[] = $convertedSite;
$convertedResources[] = $convertedSite;
Expand Down
56 changes: 56 additions & 0 deletions tests/Migration/Unit/Resources/SpecificationTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php

namespace Utopia\Tests\Unit\Resources;

use PHPUnit\Framework\TestCase;
use Utopia\Migration\Resources\Functions\Func;
use Utopia\Migration\Resources\Sites\Site;

class SpecificationTest extends TestCase
{
public function testFunctionPreservesBuildAndRuntimeSpecifications(): void
{
$function = Func::fromArray([
'id' => 'function',
'name' => 'Function',
'runtime' => 'php-8.4',
'runtimeSpecification' => 's-1vcpu-512mb',
'buildSpecification' => 's-2vcpu-2gb',
]);

$this->assertSame('s-1vcpu-512mb', $function->getRuntimeSpecification());
$this->assertSame('s-2vcpu-2gb', $function->getBuildSpecification());
$this->assertSame('s-1vcpu-512mb', $function->jsonSerialize()['runtimeSpecification']);
$this->assertSame('s-2vcpu-2gb', $function->jsonSerialize()['buildSpecification']);
}

public function testSitePreservesBuildAndRuntimeSpecifications(): void
{
$site = Site::fromArray([
'id' => 'site',
'name' => 'Site',
'framework' => 'other',
'buildRuntime' => 'node-22',
'runtimeSpecification' => 's-1vcpu-512mb',
'buildSpecification' => 's-2vcpu-2gb',
]);

$this->assertSame('s-1vcpu-512mb', $site->getRuntimeSpecification());
$this->assertSame('s-2vcpu-2gb', $site->getBuildSpecification());
$this->assertSame('s-1vcpu-512mb', $site->jsonSerialize()['runtimeSpecification']);
$this->assertSame('s-2vcpu-2gb', $site->jsonSerialize()['buildSpecification']);
}

public function testLegacySpecificationIsUsedForBuildAndRuntime(): void
{
$function = Func::fromArray([
'id' => 'function',
'name' => 'Function',
'runtime' => 'php-8.4',
'specification' => 's-1vcpu-512mb',
]);

$this->assertSame('s-1vcpu-512mb', $function->getRuntimeSpecification());
$this->assertSame('s-1vcpu-512mb', $function->getBuildSpecification());
}
}
Loading