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

Merge pull request #6076 from appwrite/fix-domains-migration

Fix domains migration
This commit is contained in:
Jake Barnby 2023-08-30 17:30:12 -04:00 committed by GitHub
commit 31bff542e9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -10,6 +10,7 @@ use Utopia\Database\Database;
use Utopia\Database\DateTime;
use Utopia\Database\Document;
use Utopia\Database\Exception;
use Utopia\Database\Query;
class V19 extends Migration
{
@ -33,6 +34,11 @@ class V19 extends Migration
Console::info('Migrating Collections');
$this->migrateCollections();
if ($this->project->getId() == 'console') {
Console::info('Migrating Domains');
$this->migrateDomains();
}
Console::info('Migrating Buckets');
$this->migrateBuckets();
@ -43,6 +49,33 @@ class V19 extends Migration
$this->cleanCollections();
}
protected function migrateDomains(): void
{
foreach ($this->documentsIterator('domains') as $domain) {
$status = 'created';
if ($domain->getAttribute('verification', false)) {
$status = 'verified';
}
$ruleDocument = new Document([
'projectId' => $domain->getAttribute('projectId'),
'projectInternalId' => $domain->getAttribute('projectInternalId'),
'domain' => $domain->getAttribute('domain'),
'resourceType' => 'api',
'resourceInternalId' => '',
'resourceId' => '',
'status' => $status,
'certificateId' => $domain->getAttribute('certificateId'),
]);
try {
$this->consoleDB->createDocument('rules', $ruleDocument);
} catch (\Throwable $th) {
Console::warning("Error migrating domain {$domain->getAttribute('domain')}: {$th->getMessage()}");
}
}
}
/**
* Migrating all Bucket tables.
*
@ -611,30 +644,6 @@ class V19 extends Migration
$document->setAttribute('smtp', []);
$document->setAttribute('templates', []);
break;
case 'rules':
$status = 'created';
if ($document->getAttribute('verification', false)) {
$status = 'verified';
}
$ruleDocument = new Document([
'projectId' => $this->project->getId(),
'projectInternalId' => $this->project->getInternalId(),
'domain' => $document->getAttribute('domain'),
'resourceType' => 'api',
'resourceInternalId' => '',
'resourceId' => '',
'status' => $status,
'certificateId' => $document->getAttribute('certificateId'),
]);
try {
$this->consoleDB->createDocument('rules', $ruleDocument);
} catch (\Throwable $th) {
Console::warning("Error migrating domain {$document->getAttribute('domain')}: {$th->getMessage()}");
}
break;
default:
break;