New attribute + migration
This commit is contained in:
parent
ec2da723fb
commit
fe27670e1f
3 changed files with 88 additions and 0 deletions
|
@ -2627,6 +2627,17 @@ $collections = [
|
||||||
'array' => false,
|
'array' => false,
|
||||||
'filters' => [],
|
'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'),
|
'$id' => ID::custom('stderr'),
|
||||||
'type' => Database::VAR_STRING,
|
'type' => Database::VAR_STRING,
|
||||||
|
|
|
@ -48,6 +48,7 @@ abstract class Migration
|
||||||
'1.1.0' => 'V16',
|
'1.1.0' => 'V16',
|
||||||
'1.1.1' => 'V16',
|
'1.1.1' => 'V16',
|
||||||
'1.1.2' => 'V16',
|
'1.1.2' => 'V16',
|
||||||
|
'1.2.0' => 'V17',
|
||||||
];
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
76
src/Appwrite/Migration/Version/V17.php
Normal file
76
src/Appwrite/Migration/Version/V17.php
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue