mirror of
https://github.com/appwrite/appwrite
synced 2026-05-05 22:38:37 +00:00
Merge pull request #10407 from appwrite/dat-647
updated migration error attribute size
This commit is contained in:
commit
4130983210
2 changed files with 51 additions and 1 deletions
|
|
@ -2345,7 +2345,7 @@ return [
|
|||
'$id' => ID::custom('errors'),
|
||||
'type' => Database::VAR_STRING,
|
||||
'format' => '',
|
||||
'size' => 65535,
|
||||
'size' => 1_000_000,
|
||||
'signed' => true,
|
||||
'required' => true,
|
||||
'default' => null,
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ use Appwrite\Migration\Migration;
|
|||
use Exception;
|
||||
use Throwable;
|
||||
use Utopia\CLI\Console;
|
||||
use Utopia\Config\Config;
|
||||
use Utopia\Database\Database;
|
||||
use Utopia\Database\Document;
|
||||
use Utopia\Database\Exception\Conflict;
|
||||
|
|
@ -132,6 +133,13 @@ class V23 extends Migration
|
|||
}
|
||||
$this->dbForProject->purgeCachedCollection($id);
|
||||
break;
|
||||
case 'migrations':
|
||||
try {
|
||||
$this->updateMigrateErrorSize();
|
||||
} catch (\Throwable $th) {
|
||||
Console::warning("Failed to migration error attribute size in collection {$id}: {$th->getMessage()}");
|
||||
}
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
|
@ -201,4 +209,46 @@ class V23 extends Migration
|
|||
}
|
||||
return $document;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update migration attribute size
|
||||
* @return void
|
||||
*/
|
||||
private function updateMigrateErrorSize(): void
|
||||
{
|
||||
|
||||
if ($this->project->getId() === 'console') {
|
||||
return;
|
||||
}
|
||||
|
||||
// Read-modify-write from the live schema to avoid overwriting unrelated changes.
|
||||
$migration = $this->dbForProject->getCollection('migrations');
|
||||
$attributes = $migration->getAttribute('attributes', []);
|
||||
$attrsArray = \array_map(fn (Document $doc) => $doc->getArrayCopy(), $attributes);
|
||||
$errorsIdx = \array_search('errors', \array_column($attrsArray, '$id'));
|
||||
|
||||
if ($errorsIdx === false) {
|
||||
Console::warning("Skipping: 'errors' attribute not found in migrations collection for project {$this->project->getId()}");
|
||||
return;
|
||||
}
|
||||
|
||||
$desiredSize = 1_000_000;
|
||||
$migrationAttributes = Config::getParam('collections', [])['projects']['migrations']['attributes'] ?? [];
|
||||
$migrationIndex = \array_search('errors', \array_column($migrationAttributes, '$id'));
|
||||
|
||||
if ($migrationIndex !== false && isset($migrationAttributes[$migrationIndex]['size'])) {
|
||||
$desiredSize = (int) $migrationAttributes[$migrationIndex]['size'];
|
||||
}
|
||||
|
||||
$currentSize = (int) ($attributes[$errorsIdx]['size'] ?? 0);
|
||||
|
||||
if ($currentSize === $desiredSize) {
|
||||
Console::warning("Skipping: 'errors' attribute already of desired size {$desiredSize} in migrations collection for project {$this->project->getId()}");
|
||||
return;
|
||||
}
|
||||
$attributes[$errorsIdx]['size'] = $desiredSize;
|
||||
$migration->setAttribute('attributes', $attributes);
|
||||
$this->dbForProject->updateDocument($migration->getCollection(), $migration->getId(), $migration);
|
||||
$this->dbForProject->purgeCachedCollection('migrations');
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue