1
0
Fork 0
mirror of synced 2024-10-01 01:37:56 +13:00

Fix update migrations for functions and deployments

- Create additional attributes for the deployments collection.
- Set the commands attribute for the functions and deployments based on
  runtime.
This commit is contained in:
Steven Nguyen 2023-09-02 17:29:38 -07:00
parent a609759951
commit 03c2a16306
No known key found for this signature in database

View file

@ -227,7 +227,25 @@ class V19 extends Migration
$attributesToCreate = [
'resourceInternalId',
'buildInternalId',
'commands',
'type',
'installationId',
'installationInternalId',
'providerRepositoryId',
'repositoryId',
'repositoryInternalId',
'providerRepositoryName',
'providerRepositoryOwner',
'providerRepositoryUrl',
'providerCommitHash',
'providerCommitAuthorUrl',
'providerCommitAuthor',
'providerCommitMessage',
'providerCommitUrl',
'providerBranch',
'providerBranchUrl',
'providerRootDirectory',
'providerCommentId',
];
foreach ($attributesToCreate as $attribute) {
try {
@ -558,6 +576,25 @@ class V19 extends Migration
}
}
private function getFunctionCommands(Document $function): string
{
$runtime = $function->getAttribute('runtime');
$language = explode('-', $runtime)[0];
$commands = match($language) {
'dart' => 'dart pub get',
'deno' => 'deno cache ' . $function->getAttribute('entrypoint'),
'dotnet' => 'dotnet restore',
'node' => 'npm install',
'php' => 'composer install',
'python' => 'pip install -r requirements.txt',
'ruby' => 'bundle install',
'swift' => 'swift package resolve',
default => '',
};
return $commands;
}
/**
* Fix run on each document
*
@ -597,6 +634,9 @@ class V19 extends Migration
$document->setAttribute('buildInternalId', $build->getInternalId());
}
$commands = $this->getFunctionCommands($function);
$document->setAttribute('commands', $commands);
$document->setAttribute('type', 'manual');
break;
case 'executions':
@ -620,6 +660,9 @@ class V19 extends Migration
$document->setAttribute('entrypoint', $deployment->getAttribute('entrypoint'));
}
$commands = $this->getFunctionCommands($document);
$document->setAttribute('commands', $commands);
$schedule = $this->consoleDB->createDocument('schedules', new Document([
'region' => App::getEnv('_APP_REGION', 'default'), // Todo replace with projects region
'resourceType' => 'function',