1
0
Fork 0
mirror of synced 2024-07-02 13:10:38 +12:00

New attribute + migration

This commit is contained in:
Matej Bačo 2022-12-12 13:39:43 +01:00
parent ec2da723fb
commit fe27670e1f
3 changed files with 88 additions and 0 deletions

View file

@ -2627,6 +2627,17 @@ $collections = [
'array' => false,
'filters' => [],
],
[
'$id' => ID::custom('outputSize'),
'type' => Database::VAR_INTEGER,
'format' => '',
'size' => 0,
'signed' => true,
'required' => false,
'default' => null,
'array' => false,
'filters' => [],
],
[
'$id' => ID::custom('stderr'),
'type' => Database::VAR_STRING,

View file

@ -48,6 +48,7 @@ abstract class Migration
'1.1.0' => 'V16',
'1.1.1' => 'V16',
'1.1.2' => 'V16',
'1.2.0' => 'V17',
];
/**

View file

@ -0,0 +1,76 @@
<?php
namespace Appwrite\Migration\Version;
use Appwrite\Migration\Migration;
use Utopia\CLI\Console;
use Utopia\Database\Database;
use Utopia\Database\Document;
class V17 extends Migration
{
public function execute(): void
{
/**
* Disable SubQueries for Performance.
*/
foreach (['subQueryIndexes', 'subQueryPlatforms', 'subQueryDomains', 'subQueryKeys', 'subQueryWebhooks', 'subQuerySessions', 'subQueryTokens', 'subQueryMemberships', 'subqueryVariables'] as $name) {
Database::addFilter(
$name,
fn () => null,
fn () => []
);
}
Console::log('Migrating Project: ' . $this->project->getAttribute('name') . ' (' . $this->project->getId() . ')');
Console::info('Migrating Collections');
$this->migrateCollections();
// Console::info('Migrating Documents');
// $this->forEachDocument([$this, 'fixDocument']);
}
/**
* Migrate all Collections.
*
* @return void
*/
protected function migrateCollections(): void
{
foreach ($this->collections as $collection) {
$id = $collection['$id'];
Console::log("Migrating Collection \"{$id}\"");
$this->projectDB->setNamespace("_{$this->project->getInternalId()}");
switch ($id) {
case 'builds':
try {
/**
* Create 'region' attribute
*/
$this->createAttributeFromCollection($this->projectDB, $id, 'outputSize');
} catch (\Throwable $th) {
Console::warning("'region' from {$id}: {$th->getMessage()}");
}
default:
break;
}
usleep(50000);
}
}
/**
* Fix run on each document
*
* @param \Utopia\Database\Document $document
* @return \Utopia\Database\Document
*/
protected function fixDocument(Document $document)
{
return $document;
}
}