add: 1.8.x migrations for adding error attribute.

This commit is contained in:
Darshan
2025-06-01 12:49:42 +05:30
parent 0467ebc1ff
commit 48d5ae0bca
3 changed files with 78 additions and 0 deletions
+1
View File
@@ -1286,6 +1286,7 @@ return [
]
],
],
'deployments' => [
'$collection' => ID::custom(Database::METADATA),
'$id' => ID::custom('deployments'),
+1
View File
@@ -89,6 +89,7 @@ abstract class Migration
'1.7.2' => 'V22',
'1.7.3' => 'V22',
'1.7.4' => 'V22',
'1.8.0' => 'V23',
];
/**
+76
View File
@@ -0,0 +1,76 @@
<?php
namespace Appwrite\Migration\Version;
use Appwrite\Migration\Migration;
use Exception;
use Throwable;
use Utopia\CLI\Console;
use Utopia\Database\Database;
class V23 extends Migration
{
/**
* @throws Throwable
*/
public function execute(): void
{
/**
* Disable SubQueries for Performance.
*/
foreach (['subQueryIndexes', 'subQueryPlatforms', 'subQueryDomains', 'subQueryKeys', 'subQueryDevKeys', 'subQueryWebhooks', 'subQuerySessions', 'subQueryTokens', 'subQueryMemberships', 'subQueryVariables', 'subQueryChallenges', 'subQueryProjectVariables', 'subQueryTargets', 'subQueryTopicTargets'] as $name) {
Database::addFilter(
$name,
fn () => null,
fn () => []
);
}
Console::info('Migrating collections');
$this->migrateCollections();
}
/**
* Migrate Collections.
*
* @return void
* @throws Exception|Throwable
*/
private function migrateCollections(): void
{
$this->migrateMigrationsCollections();
}
/**
* Add `error` attribute on `migrations` collection.
*/
private function migrateMigrationsCollections(): void
{
$projectInternalId = $this->project->getSequence();
if ($projectInternalId !== 'projects') {
return;
}
Console::info(" └── Migrating `migrations` collections.");
if (empty($projectInternalId)) {
throw new Exception('Project ID is null');
}
/**
* direct access.\
* same as `$this->collections['projects']['migrations']['$id']`.
*/
$migrationCollectionId = 'migrations';
try {
$attributes = ['error'];
$this->createAttributesFromCollection($this->dbForProject, $migrationCollectionId, $attributes);
} catch (\Throwable $th) {
Console::warning('Failed to create attributes "' . \implode(', ', $attributes) . "\" in collection {$migrationCollectionId}: {$th->getMessage()}");
}
$this->dbForProject->purgeCachedCollection($migrationCollectionId);
}
}