mirror of
https://github.com/appwrite/appwrite
synced 2026-05-24 09:28:40 +00:00
Merge pull request #9856 from appwrite/fix-migration-rule-owner
fix(migration): set owner and region while migrating rules
This commit is contained in:
commit
f9a74868ff
1 changed files with 26 additions and 8 deletions
|
|
@ -12,6 +12,7 @@ use Utopia\Database\Exception\Conflict;
|
||||||
use Utopia\Database\Exception\Structure;
|
use Utopia\Database\Exception\Structure;
|
||||||
use Utopia\Database\Exception\Timeout;
|
use Utopia\Database\Exception\Timeout;
|
||||||
use Utopia\Database\Query;
|
use Utopia\Database\Query;
|
||||||
|
use Utopia\System\System;
|
||||||
|
|
||||||
class V22 extends Migration
|
class V22 extends Migration
|
||||||
{
|
{
|
||||||
|
|
@ -324,7 +325,9 @@ class V22 extends Migration
|
||||||
4. Fill "trigger" with "manual"
|
4. Fill "trigger" with "manual"
|
||||||
5. Fill "deploymentResourceType". If "resourceType" is "function", set "deploymentResourceType" to "function"
|
5. Fill "deploymentResourceType". If "resourceType" is "function", set "deploymentResourceType" to "function"
|
||||||
6. Fill "search" with "{$id} {domain}"
|
6. Fill "search" with "{$id} {domain}"
|
||||||
7. Fill "deploymentId" and "deploymentInternalId". If "deploymentResourceType" is "function", get project DB, and find function with ID "resourceId". Then fill rule's "deploymentId" with function's "deployment", and "deploymentId" as backup
|
7. Set "region" to project region
|
||||||
|
8. Fill "owner" with "Appwrite" if "domain" ends with "functions" or "sites"
|
||||||
|
9. Fill "deploymentId" and "deploymentInternalId". If "deploymentResourceType" is "function", get project DB, and find function with ID "resourceId". Then fill rule's "deploymentId" with function's "deployment", and "deploymentId" as backup
|
||||||
*/
|
*/
|
||||||
|
|
||||||
$deploymentResourceType = null;
|
$deploymentResourceType = null;
|
||||||
|
|
@ -346,14 +349,29 @@ class V22 extends Migration
|
||||||
->setAttribute('deploymentResourceType', $document->getAttribute('deploymentResourceType', $deploymentResourceType))
|
->setAttribute('deploymentResourceType', $document->getAttribute('deploymentResourceType', $deploymentResourceType))
|
||||||
->setAttribute('search', \implode(' ', [$document->getId(), $document->getAttribute('domain', '')]));
|
->setAttribute('search', \implode(' ', [$document->getId(), $document->getAttribute('domain', '')]));
|
||||||
|
|
||||||
|
$project = $this->dbForProject->getDocument('projects', $document->getAttribute('projectId'));
|
||||||
|
|
||||||
|
if ($project->isEmpty()) {
|
||||||
|
Console::warning("Project \"{$document->getAttribute('projectId')}\" not found for rule \"{$document->getId()}\"");
|
||||||
|
$document->setAttribute('region', System::getEnv('_APP_DEFAULT_REGION'));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
$document->setAttribute('region', $project->getAttribute('region', System::getEnv('_APP_DEFAULT_REGION')));
|
||||||
|
|
||||||
|
$domain = $document->getAttribute('domain', '');
|
||||||
|
$functionsDomain = System::getEnv('_APP_DOMAIN_FUNCTIONS', '');
|
||||||
|
$sitesDomain = System::getEnv('_APP_DOMAIN_SITES', '');
|
||||||
|
$owner = $document->getAttribute('owner', '');
|
||||||
|
if (
|
||||||
|
empty($owner) &&
|
||||||
|
(!empty($functionsDomain) && \str_ends_with($domain, $functionsDomain)) ||
|
||||||
|
(!empty($sitesDomain) && \str_ends_with($domain, $sitesDomain))
|
||||||
|
) {
|
||||||
|
$document->setAttribute('owner', 'Appwrite');
|
||||||
|
}
|
||||||
|
|
||||||
if ($deploymentResourceType === 'function') {
|
if ($deploymentResourceType === 'function') {
|
||||||
$project = $this->dbForProject->getDocument('projects', $document->getAttribute('projectId'));
|
|
||||||
|
|
||||||
if ($project->isEmpty()) {
|
|
||||||
Console::warning("Project \"{$document->getAttribute('projectId')}\" not found for rule \"{$document->getId()}\"");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
$dbForOwnerProject = ($this->getProjectDB)($project);
|
$dbForOwnerProject = ($this->getProjectDB)($project);
|
||||||
$function = $dbForOwnerProject->getDocument('functions', $resourceId);
|
$function = $dbForOwnerProject->getDocument('functions', $resourceId);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue