mirror of
https://github.com/appwrite/appwrite
synced 2026-05-21 07:58:55 +00:00
Fix domains migration
The previous approach tried to migrate the 'rules' collection, but that didn't work because the data was in the 'domains' collection. Since the 'domains' collection was removed, the migration is now done when migrating the 'projects' collection by fetching the domains and then creating the rule documents.
This commit is contained in:
parent
f10698aebe
commit
bd89fd4bf5
1 changed files with 33 additions and 24 deletions
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Reference in a new issue