Merge pull request #9738 from appwrite/feat-ce-migration

1.7.x ce migration
This commit is contained in:
Jake Barnby 2025-05-17 08:18:00 +00:00 committed by GitHub
commit d3ba4dab46
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
14 changed files with 1067 additions and 539 deletions

View file

@ -1101,6 +1101,28 @@ return [
'array' => false,
'filters' => ['json', 'encrypt'],
],
[
'$id' => ID::custom('scopes'),
'type' => Database::VAR_STRING,
'format' => '',
'size' => Database::LENGTH_KEY,
'signed' => true,
'required' => false,
'default' => null,
'array' => true,
'filters' => [],
],
[
'$id' => ID::custom('expire'),
'type' => Database::VAR_DATETIME,
'format' => '',
'size' => 0,
'required' => false,
'signed' => false,
'default' => null,
'array' => false,
'filters' => ['datetime'],
],
],
'indexes' => [
[

View file

@ -225,7 +225,7 @@ return [
'$id' => ID::custom('templates'),
'type' => Database::VAR_STRING,
'format' => '',
'size' => 1000000, // TODO make sure size fits
'size' => 1_000_000, // TODO make sure size fits
'signed' => true,
'required' => false,
'default' => [],
@ -1890,5 +1890,5 @@ return [
'name' => 'vcsCommentLocks',
'attributes' => [],
'indexes' => []
]
],
];

View file

@ -3,48 +3,37 @@
namespace Appwrite\Migration;
use Exception;
use Swoole\Runtime;
use Utopia\CLI\Console;
use Utopia\Config\Config;
use Utopia\Database\Database;
use Utopia\Database\Document;
use Utopia\Database\Exception\Conflict;
use Utopia\Database\Exception\Duplicate;
use Utopia\Database\Exception\Limit;
use Utopia\Database\Exception\Structure;
use Utopia\Database\Helpers\ID;
use Utopia\Database\PDO;
use Utopia\Database\Query;
use Utopia\Database\Validator\Authorization;
use Utopia\System\System;
Runtime::enableCoroutine(SWOOLE_HOOK_ALL);
abstract class Migration
{
/**
* @var int
*/
protected int $limit = 100;
/**
* @var Document
*/
protected Document $project;
/**
* @var Database
*/
protected Database $projectDB;
protected Database $dbForProject;
protected Database $dbForPlatform;
/**
* @var Database
* @var callable(Document): Database
*/
protected Database $consoleDB;
protected mixed $getProjectDB;
/**
* @var PDO
*/
protected PDO $pdo;
/**
* @var array
* @var array<string, string>
*/
public static array $versions = [
'1.0.0-RC1' => 'V15',
@ -98,7 +87,7 @@ abstract class Migration
];
/**
* @var array
* @var array<string, array<string, mixed>>
*/
protected array $collections;
@ -109,38 +98,35 @@ abstract class Migration
$this->collections = Config::getParam('collections', []);
$projectCollections = $this->collections['projects'];
$this->collections['projects']['_metadata'] = [
'$id' => ID::custom('_metadata'),
'$collection' => Database::METADATA,
];
$this->collections['projects'] = array_merge([
'_metadata' => [
'$id' => ID::custom('_metadata'),
'$collection' => Database::METADATA
],
'audit' => [
'$id' => ID::custom('audit'),
'$collection' => Database::METADATA
],
'abuse' => [
'$id' => ID::custom('abuse'),
'$collection' => Database::METADATA
]
], $projectCollections);
$this->collections['projects']['audit'] = [
'$id' => ID::custom('audit'),
'$collection' => Database::METADATA,
];
}
/**
* Set project for migration.
*
* @param Document $project
* @param Database $projectDB
* @param Database $oldConsoleDB
*
* @param Database $dbForProject
* @param Database $dbForPlatform
* @return self
*/
public function setProject(Document $project, Database $projectDB, Database $consoleDB): self
{
public function setProject(
Document $project,
Database $dbForProject,
Database $dbForPlatform,
?callable $getProjectDB = null
): self {
$this->project = $project;
$this->projectDB = $projectDB;
$this->consoleDB = $consoleDB;
$this->dbForProject = $dbForProject;
$this->dbForPlatform = $dbForPlatform;
$this->getProjectDB = $getProjectDB;
return $this;
}
@ -149,7 +135,7 @@ abstract class Migration
* Set PDO for Migration.
*
* @param PDO $pdo
* @return \Appwrite\Migration\Migration
* @return Migration
*/
public function setPDO(PDO $pdo): self
{
@ -162,87 +148,49 @@ abstract class Migration
* Iterates through every document.
*
* @param callable $callback
* @throws Exception
*/
public function forEachDocument(callable $callback): void
{
$internalProjectId = $this->project->getInternalId();
$projectInternalId = $this->project->getInternalId();
$collections = match ($internalProjectId) {
$collections = match ($projectInternalId) {
'console' => $this->collections['console'],
default => $this->collections['projects'],
};
foreach ($collections as $collection) {
// Only migrate top-level collections
if ($collection['$collection'] !== Database::METADATA) {
continue;
}
Console::log('Migrating Collection ' . $collection['$id'] . ':');
Console::log('Migrating documents for collection "' . $collection['$id'] . '"');
foreach ($this->documentsIterator($collection['$id']) as $document) {
go(function (Document $document, callable $callback) {
if (empty($document->getId()) || empty($document->getCollection())) {
return;
}
$old = $document->getArrayCopy();
$new = call_user_func($callback, $document);
if (is_null($new) || $new->getArrayCopy() == $old) {
return;
}
try {
$this->projectDB->updateDocument($document->getCollection(), $document->getId(), $document);
} catch (\Throwable $th) {
Console::error('Failed to update document: ' . $th->getMessage());
return;
}
}, $document, $callback);
}
}
}
/**
* Provides an iterator for all documents on a collection.
*
* @param string $collectionId
* @return iterable<Document>
* @throws \Exception
*/
public function documentsIterator(string $collectionId, $queries = []): iterable
{
$sum = 0;
$nextDocument = null;
$collectionCount = $this->projectDB->count($collectionId);
$queries[] = Query::limit($this->limit);
do {
if ($nextDocument !== null) {
$cursorQueryIndex = \array_search('cursorAfter', \array_map(fn (Query $query) => $query->getMethod(), $queries));
if ($cursorQueryIndex !== false) {
$queries[$cursorQueryIndex] = Query::cursorAfter($nextDocument);
} else {
$queries[] = Query::cursorAfter($nextDocument);
$this->dbForProject->foreach($collection['$id'], function (Document $document) use ($collection, $callback) {
if (empty($document->getId()) || empty($document->getCollection())) {
return;
}
}
$documents = $this->projectDB->find($collectionId, $queries);
$count = count($documents);
$sum += $count;
$old = $document->getArrayCopy();
$new = $callback($document);
Console::log($sum . ' / ' . $collectionCount);
foreach ($documents as $document) {
yield $document;
}
if ($new === null || $new->getArrayCopy() == $old) {
return;
}
if ($count !== $this->limit) {
$nextDocument = null;
} else {
$nextDocument = end($documents);
}
} while (!is_null($nextDocument));
try {
$this->dbForProject->updateDocument(
$document->getCollection(),
$document->getId(),
$document
);
} catch (\Throwable $th) {
Console::error("Failed to update document \"{$document->getId()}\" in collection \"{$collection['$id']}\":" . $th->getMessage());
return;
}
});
}
}
/**
@ -262,55 +210,50 @@ abstract class Migration
default => 'projects',
};
if (!$this->projectDB->exists(System::getEnv('_APP_DB_SCHEMA', 'appwrite'), $name)) {
$attributes = [];
$indexes = [];
$collection = $this->collections[$collectionType][$id];
if (!$this->dbForProject->getCollection($id)->isEmpty()) {
return;
}
foreach ($collection['attributes'] as $attribute) {
$attributes[] = new Document([
'$id' => $attribute['$id'],
'type' => $attribute['type'],
'size' => $attribute['size'],
'required' => $attribute['required'],
'default' => $attribute['default'] ?? null,
'signed' => $attribute['signed'],
'array' => $attribute['array'],
'filters' => $attribute['filters'],
]);
}
$collection = $this->collections[$collectionType][$id];
foreach ($collection['indexes'] as $index) {
$indexes[] = new Document([
'$id' => $index['$id'],
'type' => $index['type'],
'attributes' => $index['attributes'],
'lengths' => $index['lengths'],
'orders' => $index['orders'],
]);
}
$attributes = [];
foreach ($collection['attributes'] as $attribute) {
$attributes[] = new Document($attribute);
}
try {
$this->projectDB->createCollection($name, $attributes, $indexes);
} catch (\Throwable $th) {
throw $th;
}
$indexes = [];
foreach ($collection['indexes'] as $index) {
$indexes[] = new Document($index);
}
try {
$this->dbForProject->createCollection($name, $attributes, $indexes);
} catch (Duplicate) {
Console::warning('Failed to create collection "' . $name . '": Collection already exists');
}
}
/**
* Creates attribute from collections.php
* Creates attributes from collections.php
*
* @param \Utopia\Database\Database $database
* @param Database $database
* @param string $collectionId
* @param string $attributeId
* @param array $attributeIds
* @param string|null $from
* @return void
* @throws \Exception
* @throws \Utopia\Database\Exception\Duplicate
* @throws \Utopia\Database\Exception\Limit
* @throws \Utopia\Database\Exception
* @throws \Utopia\Database\Exception\Authorization
* @throws Conflict
* @throws Duplicate
* @throws Limit
* @throws Structure
*/
public function createAttributeFromCollection(Database $database, string $collectionId, string $attributeId, string $from = null): void
{
public function createAttributesFromCollection(
Database $database,
string $collectionId,
array $attributeIds,
string $from = null
): void {
$from ??= $collectionId;
$collectionType = match ($this->project->getInternalId()) {
@ -324,13 +267,78 @@ abstract class Migration
$collection = $this->collections[$collectionType][$from] ?? null;
if (is_null($collection)) {
if ($collection === null) {
throw new Exception("Collection {$from} not found");
}
$attributesToCreate = [];
$attributes = $collection['attributes'];
$attributeKeys = \array_column($collection['attributes'], '$id');
foreach ($attributeIds as $attributeId) {
$attributeKey = \array_search($attributeId, $attributeKeys);
if ($attributeKey === false) {
throw new Exception("Attribute {$attributeId} not found");
}
$attribute = $attributes[$attributeKey];
$attribute['filters'] ??= [];
$attribute['default'] ??= null;
$attribute['default'] = \in_array('json', $attribute['filters'])
? \json_encode($attribute['default'])
: $attribute['default'];
$attributesToCreate[] = $attribute;
}
$database->createAttributes(
collection: $collectionId,
attributes: $attributesToCreate,
);
}
/**
* Creates attribute from collections.php
*
* @param Database $database
* @param string $collectionId
* @param string $attributeId
* @param string|null $from
* @return void
* @throws \Utopia\Database\Exception
* @throws \Utopia\Database\Exception\Authorization
* @throws Conflict
* @throws Duplicate
* @throws Limit
* @throws Structure
*/
public function createAttributeFromCollection(
Database $database,
string $collectionId,
string $attributeId,
string $from = null
): void {
$from ??= $collectionId;
$collectionType = match ($this->project->getInternalId()) {
'console' => 'console',
default => 'projects',
};
if ($from === 'files') {
$collectionType = 'buckets';
}
$collection = $this->collections[$collectionType][$from] ?? null;
if ($collection === null) {
throw new Exception("Collection {$from} not found");
}
$attributes = $collection['attributes'];
$attributeKey = array_search($attributeId, array_column($attributes, '$id'));
$attributeKey = \array_search($attributeId, \array_column($attributes, '$id'));
if ($attributeKey === false) {
throw new Exception("Attribute {$attributeId} not found");
@ -345,9 +353,9 @@ abstract class Migration
id: $attributeId,
type: $attribute['type'],
size: $attribute['size'],
required: $attribute['required'] ?? false,
default: in_array('json', $filters) ? json_encode($default) : $default,
signed: $attribute['signed'] ?? false,
required: $attribute['required'],
default: \in_array('json', $filters) ? \json_encode($default) : $default,
signed: $attribute['signed'] ?? true,
array: $attribute['array'] ?? false,
format: $attribute['format'] ?? '',
formatOptions: $attribute['formatOptions'] ?? [],
@ -358,14 +366,14 @@ abstract class Migration
/**
* Creates index from collections.php
*
* @param \Utopia\Database\Database $database
* @param Database $database
* @param string $collectionId
* @param string $indexId
* @param string|null $from
* @return void
* @throws \Exception
* @throws \Utopia\Database\Exception\Duplicate
* @throws \Utopia\Database\Exception\Limit
* @throws Duplicate
* @throws Limit
*/
public function createIndexFromCollection(Database $database, string $collectionId, string $indexId, string $from = null): void
{
@ -378,13 +386,13 @@ abstract class Migration
$collection = $this->collections[$collectionType][$from] ?? null;
if (is_null($collection)) {
if ($collection === null) {
throw new Exception("Collection {$collectionId} not found");
}
$indexes = $collection['indexes'];
$indexKey = array_search($indexId, array_column($indexes, '$id'));
$indexKey = \array_search($indexId, \array_column($indexes, '$id'));
if ($indexKey === false) {
throw new Exception("Index {$indexId} not found");
@ -409,10 +417,11 @@ abstract class Migration
* @param string $attribute
* @param string $type
* @return void
* @throws \Utopia\Database\Exception
*/
protected function changeAttributeInternalType(string $collection, string $attribute, string $type): void
{
$stmt = $this->pdo->prepare("ALTER TABLE `{$this->projectDB->getDatabase()}`.`_{$this->project->getInternalId()}_{$collection}` MODIFY `$attribute` $type;");
$stmt = $this->pdo->prepare("ALTER TABLE `{$this->dbForProject->getDatabase()}`.`_{$this->project->getInternalId()}_{$collection}` MODIFY `$attribute` $type;");
try {
$stmt->execute();

View file

@ -114,7 +114,7 @@ class V15 extends Migration
$bucket->setAttribute('compression', 'none');
}
$this->projectDB->updateDocument('buckets', $bucket->getId(), $bucket);
$this->dbForProject->updateDocument('buckets', $bucket->getId(), $bucket);
/**
* Migrating stats for every Bucket.
@ -134,13 +134,13 @@ class V15 extends Migration
table: $bucketTable,
addCreatePermission: false
);
$this->projectDB->updateDocument($bucketTable, $file->getId(), $file);
$this->dbForProject->updateDocument($bucketTable, $file->getId(), $file);
}
$this->removeWritePermissions($bucketTable);
}
try {
$this->projectDB->deleteAttribute('buckets', 'permission');
$this->dbForProject->deleteAttribute('buckets', 'permission');
} catch (\Throwable $th) {
Console::warning("'permissions' from buckets: {$th->getMessage()}");
}
@ -188,10 +188,10 @@ class V15 extends Migration
addCreatePermission: false
);
$this->projectDB->updateDocument('databases', $database->getId(), $database);
$this->dbForProject->updateDocument('databases', $database->getId(), $database);
try {
$this->createAttributeFromCollection($this->projectDB, $databaseTable, 'documentSecurity', 'collections');
$this->createAttributeFromCollection($this->dbForProject, $databaseTable, 'documentSecurity', 'collections');
} catch (\Throwable $th) {
Console::warning("'documentSecurity' from {$databaseTable}: {$th->getMessage()}");
}
@ -231,7 +231,7 @@ class V15 extends Migration
$collection->setAttribute('documentSecurity', $collection->getAttribute('permissions') === 'document');
}
$this->projectDB->updateDocument($databaseTable, $collection->getId(), $collection);
$this->dbForProject->updateDocument($databaseTable, $collection->getId(), $collection);
/**
* Migrating stats for single Collections.
@ -270,14 +270,14 @@ class V15 extends Migration
addCreatePermission: false
);
$this->projectDB->updateDocument($collectionTable, $document->getId(), $document);
$this->dbForProject->updateDocument($collectionTable, $document->getId(), $document);
}
$this->removeWritePermissions($collectionTable);
}
$this->removeWritePermissions($databaseTable);
try {
$this->projectDB->deleteAttribute("database_{$database->getInternalId()}", 'permission');
$this->dbForProject->deleteAttribute("database_{$database->getInternalId()}", 'permission');
} catch (\Throwable $th) {
Console::warning("'permission' from {$databaseTable}: {$th->getMessage()}");
}
@ -293,7 +293,7 @@ class V15 extends Migration
protected function removeWritePermissions(string $table): void
{
try {
$this->pdo->prepare("DELETE FROM `{$this->projectDB->getDatabase()}`.`_{$this->project->getInternalId()}_{$table}_perms` WHERE _type = 'write'")->execute();
$this->pdo->prepare("DELETE FROM `{$this->dbForProject->getDatabase()}`.`_{$this->project->getInternalId()}_{$table}_perms` WHERE _type = 'write'")->execute();
} catch (\Throwable $th) {
Console::warning("Remove 'write' permissions from {$table}: {$th->getMessage()}");
}
@ -309,7 +309,7 @@ class V15 extends Migration
*/
protected function getSQLColumnTypes(string $table): array
{
$query = $this->pdo->prepare("SELECT COLUMN_NAME, DATA_TYPE FROM INFORMATION_SCHEMA.COLUMNS WHERE table_name = '_{$this->project->getInternalId()}_{$table}' AND table_schema = '{$this->projectDB->getDatabase()}'");
$query = $this->pdo->prepare("SELECT COLUMN_NAME, DATA_TYPE FROM INFORMATION_SCHEMA.COLUMNS WHERE table_name = '_{$this->project->getInternalId()}_{$table}' AND table_schema = '{$this->dbForProject->getDatabase()}'");
$query->execute();
return array_reduce($query->fetchAll(), function (array $carry, array $item) {
@ -331,8 +331,8 @@ class V15 extends Migration
if ($columns[$attribute] === 'int') {
try {
$this->pdo->prepare("ALTER TABLE IF EXISTS `{$this->projectDB->getDatabase()}`.`_{$this->project->getInternalId()}_{$table}` MODIFY {$attribute} VARCHAR(64)")->execute();
$this->pdo->prepare("UPDATE `{$this->projectDB->getDatabase()}`.`_{$this->project->getInternalId()}_{$table}` SET {$attribute} = IF({$attribute} = 0, NULL, FROM_UNIXTIME({$attribute}))")->execute();
$this->pdo->prepare("ALTER TABLE IF EXISTS `{$this->dbForProject->getDatabase()}`.`_{$this->project->getInternalId()}_{$table}` MODIFY {$attribute} VARCHAR(64)")->execute();
$this->pdo->prepare("UPDATE `{$this->dbForProject->getDatabase()}`.`_{$this->project->getInternalId()}_{$table}` SET {$attribute} = IF({$attribute} = 0, NULL, FROM_UNIXTIME({$attribute}))")->execute();
$columns[$attribute] = 'varchar';
} catch (\Throwable $th) {
Console::warning($th->getMessage());
@ -341,7 +341,7 @@ class V15 extends Migration
if ($columns[$attribute] === 'varchar') {
try {
$this->pdo->prepare("ALTER TABLE IF EXISTS `{$this->projectDB->getDatabase()}`.`_{$this->project->getInternalId()}_{$table}` MODIFY {$attribute} DATETIME(3)")->execute();
$this->pdo->prepare("ALTER TABLE IF EXISTS `{$this->dbForProject->getDatabase()}`.`_{$this->project->getInternalId()}_{$table}` MODIFY {$attribute} DATETIME(3)")->execute();
} catch (\Throwable $th) {
Console::warning($th->getMessage());
}
@ -355,11 +355,11 @@ class V15 extends Migration
/**
* Add datetime filter.
*/
$this->projectDB->updateAttributeFilters($table, ID::custom($attribute), ['datetime']);
$this->dbForProject->updateAttributeFilters($table, ID::custom($attribute), ['datetime']);
/**
* Change data type to DateTime.
*/
$this->projectDB->updateAttribute(
$this->dbForProject->updateAttribute(
collection: $table,
id: $attribute,
type: Database::VAR_DATETIME,
@ -370,7 +370,7 @@ class V15 extends Migration
}
}
$this->projectDB->purgeCachedCollection($table);
$this->dbForProject->purgeCachedCollection($table);
}
/**
@ -387,7 +387,7 @@ class V15 extends Migration
if (!array_key_exists('_permissions', $columns)) {
try {
$this->pdo->prepare("ALTER TABLE IF EXISTS `{$this->projectDB->getDatabase()}`.`_{$this->project->getInternalId()}_{$table}` ADD `_permissions` MEDIUMTEXT DEFAULT NULL")->execute();
$this->pdo->prepare("ALTER TABLE IF EXISTS `{$this->dbForProject->getDatabase()}`.`_{$this->project->getInternalId()}_{$table}` ADD `_permissions` MEDIUMTEXT DEFAULT NULL")->execute();
} catch (\Throwable $th) {
Console::warning("Add '_permissions' column to '{$table}': {$th->getMessage()}");
}
@ -408,7 +408,7 @@ class V15 extends Migration
{
$table ??= $document->getCollection();
$query = $this->pdo->prepare("SELECT * FROM `{$this->projectDB->getDatabase()}`.`_{$this->project->getInternalId()}_{$table}_perms` WHERE _document = '{$document->getId()}'");
$query = $this->pdo->prepare("SELECT * FROM `{$this->dbForProject->getDatabase()}`.`_{$this->project->getInternalId()}_{$table}_perms` WHERE _document = '{$document->getId()}'");
$query->execute();
$results = $query->fetchAll();
$permissions = [];
@ -466,7 +466,7 @@ class V15 extends Migration
Console::log("Migrating Collection \"{$id}\"");
$this->projectDB->setNamespace("_{$this->project->getInternalId()}");
$this->dbForProject->setNamespace("_{$this->project->getInternalId()}");
switch ($id) {
case '_metadata':
@ -477,7 +477,7 @@ class V15 extends Migration
$this->createCollection('cache');
Console::log('Created new Collection "variables" collection');
$this->createCollection('variables');
$this->projectDB->purgeCachedCollection($id);
$this->dbForProject->purgeCachedCollection($id);
break;
case 'abuse':
@ -509,7 +509,7 @@ class V15 extends Migration
/**
* Create 'compression' attribute
*/
$this->createAttributeFromCollection($this->projectDB, $id, 'compression');
$this->createAttributeFromCollection($this->dbForProject, $id, 'compression');
} catch (\Throwable $th) {
Console::warning("'compression' from {$id}: {$th->getMessage()}");
}
@ -518,7 +518,7 @@ class V15 extends Migration
/**
* Create 'fileSecurity' attribute
*/
$this->createAttributeFromCollection($this->projectDB, $id, 'fileSecurity');
$this->createAttributeFromCollection($this->dbForProject, $id, 'fileSecurity');
} catch (\Throwable $th) {
Console::warning("'fileSecurity' from {$id}: {$th->getMessage()}");
}
@ -527,7 +527,7 @@ class V15 extends Migration
/**
* Create '_key_enabled' index
*/
$this->createIndexFromCollection($this->projectDB, $id, '_key_enabled');
$this->createIndexFromCollection($this->dbForProject, $id, '_key_enabled');
} catch (\Throwable $th) {
Console::warning("'_key_enabled' from {$id}: {$th->getMessage()}");
}
@ -536,7 +536,7 @@ class V15 extends Migration
/**
* Create '_key_name' index
*/
$this->createIndexFromCollection($this->projectDB, $id, '_key_name');
$this->createIndexFromCollection($this->dbForProject, $id, '_key_name');
} catch (\Throwable $th) {
Console::warning("'_key_name' from {$id}: {$th->getMessage()}");
}
@ -545,7 +545,7 @@ class V15 extends Migration
/**
* Create '_key_fileSecurity' index
*/
$this->createIndexFromCollection($this->projectDB, $id, '_key_fileSecurity');
$this->createIndexFromCollection($this->dbForProject, $id, '_key_fileSecurity');
} catch (\Throwable $th) {
Console::warning("'_key_fileSecurity' from {$id}: {$th->getMessage()}");
}
@ -554,7 +554,7 @@ class V15 extends Migration
/**
* Create '_key_maximumFileSize' index
*/
$this->createIndexFromCollection($this->projectDB, $id, '_key_maximumFileSize');
$this->createIndexFromCollection($this->dbForProject, $id, '_key_maximumFileSize');
} catch (\Throwable $th) {
Console::warning("'_key_maximumFileSize' from {$id}: {$th->getMessage()}");
}
@ -563,7 +563,7 @@ class V15 extends Migration
/**
* Create '_key_encryption' index
*/
$this->createIndexFromCollection($this->projectDB, $id, '_key_encryption');
$this->createIndexFromCollection($this->dbForProject, $id, '_key_encryption');
} catch (\Throwable $th) {
Console::warning("'_key_encryption' from {$id}: {$th->getMessage()}");
}
@ -572,7 +572,7 @@ class V15 extends Migration
/**
* Create '_key_antivirus' index
*/
$this->createIndexFromCollection($this->projectDB, $id, '_key_antivirus');
$this->createIndexFromCollection($this->dbForProject, $id, '_key_antivirus');
} catch (\Throwable $th) {
Console::warning("'_key_antivirus' from {$id}: {$th->getMessage()}");
}
@ -611,7 +611,7 @@ class V15 extends Migration
/**
* Create '_key_entrypoint' index
*/
$this->createIndexFromCollection($this->projectDB, $id, '_key_entrypoint');
$this->createIndexFromCollection($this->dbForProject, $id, '_key_entrypoint');
} catch (\Throwable $th) {
Console::warning("'_key_entrypoint' from {$id}: {$th->getMessage()}");
}
@ -620,7 +620,7 @@ class V15 extends Migration
/**
* Create '_key_size' index
*/
$this->createIndexFromCollection($this->projectDB, $id, '_key_size');
$this->createIndexFromCollection($this->dbForProject, $id, '_key_size');
} catch (\Throwable $th) {
Console::warning("'_key_size' from {$id}: {$th->getMessage()}");
}
@ -629,7 +629,7 @@ class V15 extends Migration
/**
* Create '_key_buildId' index
*/
$this->createIndexFromCollection($this->projectDB, $id, '_key_buildId');
$this->createIndexFromCollection($this->dbForProject, $id, '_key_buildId');
} catch (\Throwable $th) {
Console::warning("'_key_buildId' from {$id}: {$th->getMessage()}");
}
@ -638,7 +638,7 @@ class V15 extends Migration
/**
* Create '_key_activate' index
*/
$this->createIndexFromCollection($this->projectDB, $id, '_key_activate');
$this->createIndexFromCollection($this->dbForProject, $id, '_key_activate');
} catch (\Throwable $th) {
Console::warning("'_key_activate' from {$id}: {$th->getMessage()}");
}
@ -662,7 +662,7 @@ class V15 extends Migration
/**
* Create 'stdout' attribute
*/
$this->createAttributeFromCollection($this->projectDB, $id, 'stdout');
$this->createAttributeFromCollection($this->dbForProject, $id, 'stdout');
} catch (\Throwable $th) {
Console::warning("'stdout' from {$id}: {$th->getMessage()}");
}
@ -671,7 +671,7 @@ class V15 extends Migration
/**
* Rename 'time' to 'duration'
*/
$this->projectDB->renameAttribute($id, 'time', 'duration');
$this->dbForProject->renameAttribute($id, 'time', 'duration');
} catch (\Throwable $th) {
Console::warning("'duration' from {$id}: {$th->getMessage()}");
}
@ -680,7 +680,7 @@ class V15 extends Migration
/**
* Create '_key_trigger' index
*/
$this->createIndexFromCollection($this->projectDB, $id, '_key_trigger');
$this->createIndexFromCollection($this->dbForProject, $id, '_key_trigger');
} catch (\Throwable $th) {
Console::warning("'_key_trigger' from {$id}: {$th->getMessage()}");
}
@ -689,7 +689,7 @@ class V15 extends Migration
/**
* Create '_key_status' index
*/
$this->createIndexFromCollection($this->projectDB, $id, '_key_status');
$this->createIndexFromCollection($this->dbForProject, $id, '_key_status');
} catch (\Throwable $th) {
Console::warning("'_key_status' from {$id}: {$th->getMessage()}");
}
@ -698,7 +698,7 @@ class V15 extends Migration
/**
* Create '_key_statusCode' index
*/
$this->createIndexFromCollection($this->projectDB, $id, '_key_statusCode');
$this->createIndexFromCollection($this->dbForProject, $id, '_key_statusCode');
} catch (\Throwable $th) {
Console::warning("'_key_statusCode' from {$id}: {$th->getMessage()}");
}
@ -707,7 +707,7 @@ class V15 extends Migration
/**
* Create '_key_duration' index
*/
$this->createIndexFromCollection($this->projectDB, $id, '_key_duration');
$this->createIndexFromCollection($this->dbForProject, $id, '_key_duration');
} catch (\Throwable $th) {
Console::warning("'_key_duration' from {$id}: {$th->getMessage()}");
}
@ -751,16 +751,16 @@ class V15 extends Migration
'value' => (string) $value,
'search' => implode(' ', [$variableId, $key, $function->getId()])
]);
$this->projectDB->createDocument('variables', $variable);
$this->dbForProject->createDocument('variables', $variable);
}
$this->projectDB->deleteAttribute('functions', 'vars');
$this->createAttributeFromCollection($this->projectDB, 'functions', 'vars');
$this->dbForProject->deleteAttribute('functions', 'vars');
$this->createAttributeFromCollection($this->dbForProject, 'functions', 'vars');
}
try {
/**
* Create 'scheduleUpdatedAt' attribute
*/
$this->createAttributeFromCollection($this->projectDB, $id, 'scheduleUpdatedAt');
$this->createAttributeFromCollection($this->dbForProject, $id, 'scheduleUpdatedAt');
} catch (\Throwable $th) {
Console::warning("'scheduleUpdatedAt' from {$id}: {$th->getMessage()}");
}
@ -768,8 +768,8 @@ class V15 extends Migration
/**
* Create 'enabled' attribute
*/
@$this->projectDB->deleteAttribute($id, 'status');
$this->createAttributeFromCollection($this->projectDB, $id, 'enabled');
@$this->dbForProject->deleteAttribute($id, 'status');
$this->createAttributeFromCollection($this->dbForProject, $id, 'enabled');
} catch (\Throwable $th) {
Console::warning("'enabled' from {$id}: {$th->getMessage()}");
}
@ -777,7 +777,7 @@ class V15 extends Migration
/**
* Create '_key_name' index
*/
$this->createIndexFromCollection($this->projectDB, $id, '_key_name');
$this->createIndexFromCollection($this->dbForProject, $id, '_key_name');
} catch (\Throwable $th) {
Console::warning("'_key_name' from {$id}: {$th->getMessage()}");
}
@ -786,7 +786,7 @@ class V15 extends Migration
/**
* Create '_key_enabled' index
*/
$this->createIndexFromCollection($this->projectDB, $id, '_key_enabled');
$this->createIndexFromCollection($this->dbForProject, $id, '_key_enabled');
} catch (\Throwable $th) {
Console::warning("'_key_enabled' from {$id}: {$th->getMessage()}");
}
@ -795,7 +795,7 @@ class V15 extends Migration
/**
* Create '_key_runtime' index
*/
$this->createIndexFromCollection($this->projectDB, $id, '_key_runtime');
$this->createIndexFromCollection($this->dbForProject, $id, '_key_runtime');
} catch (\Throwable $th) {
Console::warning("'_key_runtime' from {$id}: {$th->getMessage()}");
}
@ -804,7 +804,7 @@ class V15 extends Migration
/**
* Create '_key_deployment' index
*/
$this->createIndexFromCollection($this->projectDB, $id, '_key_deployment');
$this->createIndexFromCollection($this->dbForProject, $id, '_key_deployment');
} catch (\Throwable $th) {
Console::warning("'_key_deployment' from {$id}: {$th->getMessage()}");
}
@ -813,7 +813,7 @@ class V15 extends Migration
/**
* Create '_key_schedule' index
*/
$this->createIndexFromCollection($this->projectDB, $id, '_key_schedule');
$this->createIndexFromCollection($this->dbForProject, $id, '_key_schedule');
} catch (\Throwable $th) {
Console::warning("'_key_schedule' from {$id}: {$th->getMessage()}");
}
@ -822,7 +822,7 @@ class V15 extends Migration
/**
* Create '_key_scheduleNext' index
*/
$this->createIndexFromCollection($this->projectDB, $id, '_key_scheduleNext');
$this->createIndexFromCollection($this->dbForProject, $id, '_key_scheduleNext');
} catch (\Throwable $th) {
Console::warning("'_key_scheduleNext' from {$id}: {$th->getMessage()}");
}
@ -831,7 +831,7 @@ class V15 extends Migration
/**
* Create '_key_schedulePrevious' index
*/
$this->createIndexFromCollection($this->projectDB, $id, '_key_schedulePrevious');
$this->createIndexFromCollection($this->dbForProject, $id, '_key_schedulePrevious');
} catch (\Throwable $th) {
Console::warning("'_key_schedulePrevious' from {$id}: {$th->getMessage()}");
}
@ -840,7 +840,7 @@ class V15 extends Migration
/**
* Create '_key_timeout' index
*/
$this->createIndexFromCollection($this->projectDB, $id, '_key_timeout');
$this->createIndexFromCollection($this->dbForProject, $id, '_key_timeout');
} catch (\Throwable $th) {
Console::warning("'_key_timeout' from {$id}: {$th->getMessage()}");
}
@ -863,7 +863,7 @@ class V15 extends Migration
/**
* Update 'expire' default value
*/
$this->projectDB->updateAttributeDefault('keys', 'expire', null);
$this->dbForProject->updateAttributeDefault('keys', 'expire', null);
} catch (\Throwable $th) {
Console::warning("'expire' from {$id}: {$th->getMessage()}");
}
@ -871,7 +871,7 @@ class V15 extends Migration
/**
* Create 'accessedAt' attribute
*/
$this->createAttributeFromCollection($this->projectDB, $id, 'accessedAt');
$this->createAttributeFromCollection($this->dbForProject, $id, 'accessedAt');
} catch (\Throwable $th) {
Console::warning("'accessedAt' from {$id}: {$th->getMessage()}");
}
@ -880,7 +880,7 @@ class V15 extends Migration
/**
* Create 'sdks' attribute
*/
$this->createAttributeFromCollection($this->projectDB, $id, 'sdks');
$this->createAttributeFromCollection($this->dbForProject, $id, 'sdks');
} catch (\Throwable $th) {
Console::warning("'sdks' from {$id}: {$th->getMessage()}");
}
@ -889,7 +889,7 @@ class V15 extends Migration
/**
* Create '_key_accessedAt' index
*/
$this->createIndexFromCollection($this->projectDB, $id, '_key_accessedAt');
$this->createIndexFromCollection($this->dbForProject, $id, '_key_accessedAt');
} catch (\Throwable $th) {
Console::warning("'_key_accessedAt' from {$id}: {$th->getMessage()}");
}
@ -907,7 +907,7 @@ class V15 extends Migration
/**
* Create '_key_userId' index
*/
$this->createIndexFromCollection($this->projectDB, $id, '_key_userId');
$this->createIndexFromCollection($this->dbForProject, $id, '_key_userId');
} catch (\Throwable $th) {
Console::warning("'_key_userId' from {$id}: {$th->getMessage()}");
}
@ -916,7 +916,7 @@ class V15 extends Migration
/**
* Create '_key_teamId' index
*/
$this->createIndexFromCollection($this->projectDB, $id, '_key_teamId');
$this->createIndexFromCollection($this->dbForProject, $id, '_key_teamId');
} catch (\Throwable $th) {
Console::warning("'_key_teamId' from {$id}: {$th->getMessage()}");
}
@ -925,7 +925,7 @@ class V15 extends Migration
/**
* Create '_key_invited' index
*/
$this->createIndexFromCollection($this->projectDB, $id, '_key_invited');
$this->createIndexFromCollection($this->dbForProject, $id, '_key_invited');
} catch (\Throwable $th) {
Console::warning("'_key_invited' from {$id}: {$th->getMessage()}");
}
@ -934,7 +934,7 @@ class V15 extends Migration
/**
* Create '_key_joined' index
*/
$this->createIndexFromCollection($this->projectDB, $id, '_key_joined');
$this->createIndexFromCollection($this->dbForProject, $id, '_key_joined');
} catch (\Throwable $th) {
Console::warning("'_key_joined' from {$id}: {$th->getMessage()}");
}
@ -943,7 +943,7 @@ class V15 extends Migration
/**
* Create '_key_confirm' index
*/
$this->createIndexFromCollection($this->projectDB, $id, '_key_confirm');
$this->createIndexFromCollection($this->dbForProject, $id, '_key_confirm');
} catch (\Throwable $th) {
Console::warning("'_key_confirm' from {$id}: {$th->getMessage()}");
}
@ -966,7 +966,7 @@ class V15 extends Migration
/**
* Create '_key_name' index
*/
$this->createIndexFromCollection($this->projectDB, $id, '_key_name');
$this->createIndexFromCollection($this->dbForProject, $id, '_key_name');
} catch (\Throwable $th) {
Console::warning("'_key_name' from {$id}: {$th->getMessage()}");
}
@ -1000,8 +1000,8 @@ class V15 extends Migration
/**
* Re-Create '_key_metric' index
*/
@$this->projectDB->deleteIndex($id, '_key_metric');
$this->createIndexFromCollection($this->projectDB, $id, '_key_period_time');
@$this->dbForProject->deleteIndex($id, '_key_metric');
$this->createIndexFromCollection($this->dbForProject, $id, '_key_period_time');
} catch (\Throwable $th) {
Console::warning("'_key_period_time' from {$id}: {$th->getMessage()}");
}
@ -1010,8 +1010,8 @@ class V15 extends Migration
/**
* Re-Create '_key_metric_period' index
*/
@$this->projectDB->deleteIndex($id, '_key_metric_period');
$this->createIndexFromCollection($this->projectDB, $id, '_key_metric_period_time');
@$this->dbForProject->deleteIndex($id, '_key_metric_period');
$this->createIndexFromCollection($this->dbForProject, $id, '_key_metric_period_time');
} catch (\Throwable $th) {
Console::warning("'_key_metric_period_time' from {$id}: {$th->getMessage()}");
}
@ -1027,7 +1027,7 @@ class V15 extends Migration
/**
* Create '_key_name' index
*/
$this->createIndexFromCollection($this->projectDB, $id, '_key_name');
$this->createIndexFromCollection($this->dbForProject, $id, '_key_name');
} catch (\Throwable $th) {
Console::warning("'_key_name' from {$id}: {$th->getMessage()}");
}
@ -1036,7 +1036,7 @@ class V15 extends Migration
/**
* Create '_key_total' index
*/
$this->createIndexFromCollection($this->projectDB, $id, '_key_total');
$this->createIndexFromCollection($this->dbForProject, $id, '_key_total');
} catch (\Throwable $th) {
Console::warning("'_key_total' from {$id}: {$th->getMessage()}");
}
@ -1062,7 +1062,7 @@ class V15 extends Migration
/**
* Create 'hash' attribute
*/
$this->createAttributeFromCollection($this->projectDB, $id, 'hash');
$this->createAttributeFromCollection($this->dbForProject, $id, 'hash');
} catch (\Throwable $th) {
Console::warning("'hash' from {$id}: {$th->getMessage()}");
}
@ -1071,7 +1071,7 @@ class V15 extends Migration
/**
* Create 'hashOptions' attribute
*/
$this->createAttributeFromCollection($this->projectDB, $id, 'hashOptions');
$this->createAttributeFromCollection($this->dbForProject, $id, 'hashOptions');
} catch (\Throwable $th) {
Console::warning("'hashOptions' from {$id}: {$th->getMessage()}");
}
@ -1124,14 +1124,14 @@ class V15 extends Migration
*/
$this->populatePermissionsAttribute($user, addCreatePermission: false);
$this->projectDB->updateDocument('users', $user->getId(), $user);
$this->dbForProject->updateDocument('users', $user->getId(), $user);
}
try {
/**
* Add datetime filter to password.
*/
$this->projectDB->updateAttributeFilters($id, 'password', ['encrypt']);
$this->dbForProject->updateAttributeFilters($id, 'password', ['encrypt']);
} catch (\Throwable $th) {
Console::warning("Add 'encrypt' filter to 'password' from {$id}: {$th->getMessage()}");
}
@ -1140,7 +1140,7 @@ class V15 extends Migration
/**
* Create '_key_name' index
*/
$this->createIndexFromCollection($this->projectDB, $id, '_key_name');
$this->createIndexFromCollection($this->dbForProject, $id, '_key_name');
} catch (\Throwable $th) {
Console::warning("'_key_name' from {$id}: {$th->getMessage()}");
}
@ -1149,7 +1149,7 @@ class V15 extends Migration
/**
* Create '_key_status' index
*/
$this->createIndexFromCollection($this->projectDB, $id, '_key_status');
$this->createIndexFromCollection($this->dbForProject, $id, '_key_status');
} catch (\Throwable $th) {
Console::warning("'_key_status' from {$id}: {$th->getMessage()}");
}
@ -1158,7 +1158,7 @@ class V15 extends Migration
/**
* Create '_key_passwordUpdate' index
*/
$this->createIndexFromCollection($this->projectDB, $id, '_key_passwordUpdate');
$this->createIndexFromCollection($this->dbForProject, $id, '_key_passwordUpdate');
} catch (\Throwable $th) {
Console::warning("'_key_passwordUpdate' from {$id}: {$th->getMessage()}");
}
@ -1167,7 +1167,7 @@ class V15 extends Migration
/**
* Create '_key_registration' index
*/
$this->createIndexFromCollection($this->projectDB, $id, '_key_registration');
$this->createIndexFromCollection($this->dbForProject, $id, '_key_registration');
} catch (\Throwable $th) {
Console::warning("'_key_registration' from {$id}: {$th->getMessage()}");
}
@ -1176,7 +1176,7 @@ class V15 extends Migration
/**
* Create '_key_emailVerification' index
*/
$this->createIndexFromCollection($this->projectDB, $id, '_key_emailVerification');
$this->createIndexFromCollection($this->dbForProject, $id, '_key_emailVerification');
} catch (\Throwable $th) {
Console::warning("'_key_emailVerification' from {$id}: {$th->getMessage()}");
}
@ -1185,7 +1185,7 @@ class V15 extends Migration
/**
* Create '_key_phoneVerification' index
*/
$this->createIndexFromCollection($this->projectDB, $id, '_key_phoneVerification');
$this->createIndexFromCollection($this->dbForProject, $id, '_key_phoneVerification');
} catch (\Throwable $th) {
Console::warning("'_key_phoneVerification' from {$id}: {$th->getMessage()}");
}
@ -1470,9 +1470,9 @@ class V15 extends Migration
$from = $this->pdo->quote($from);
$to = $this->pdo->quote($to);
$this->pdo->prepare("UPDATE `{$this->projectDB->getDatabase()}`.`_{$this->project->getInternalId()}_stats` SET metric = {$to} WHERE metric = {$from}")->execute();
$this->pdo->prepare("UPDATE `{$this->dbForProject->getDatabase()}`.`_{$this->project->getInternalId()}_stats` SET metric = {$to} WHERE metric = {$from}")->execute();
} catch (\Throwable $th) {
Console::warning("Migrating steps from {$this->projectDB->getDatabase()}`.`_{$this->project->getInternalId()}_stats:" . $th->getMessage());
Console::warning("Migrating steps from {$this->dbForProject->getDatabase()}`.`_{$this->project->getInternalId()}_stats:" . $th->getMessage());
}
}

View file

@ -45,7 +45,7 @@ class V16 extends Migration
Console::log("Migrating Collection \"{$id}\"");
$this->projectDB->setNamespace("_{$this->project->getInternalId()}");
$this->dbForProject->setNamespace("_{$this->project->getInternalId()}");
switch ($id) {
case 'sessions':
@ -53,7 +53,7 @@ class V16 extends Migration
/**
* Create 'expire' attribute
*/
$this->projectDB->deleteAttribute($id, 'expire');
$this->dbForProject->deleteAttribute($id, 'expire');
} catch (\Throwable $th) {
Console::warning("'expire' from {$id}: {$th->getMessage()}");
}
@ -65,7 +65,7 @@ class V16 extends Migration
/**
* Create 'region' attribute
*/
$this->createAttributeFromCollection($this->projectDB, $id, 'region');
$this->createAttributeFromCollection($this->dbForProject, $id, 'region');
} catch (\Throwable $th) {
Console::warning("'region' from {$id}: {$th->getMessage()}");
}
@ -74,7 +74,7 @@ class V16 extends Migration
/**
* Create '_key_team' index
*/
$this->createIndexFromCollection($this->projectDB, $id, '_key_team');
$this->createIndexFromCollection($this->dbForProject, $id, '_key_team');
} catch (\Throwable $th) {
Console::warning("'_key_team' from {$id}: {$th->getMessage()}");
}
@ -85,7 +85,7 @@ class V16 extends Migration
/**
* Create 'region' attribute
*/
$this->createAttributeFromCollection($this->projectDB, $id, 'region');
$this->createAttributeFromCollection($this->dbForProject, $id, 'region');
} catch (\Throwable $th) {
Console::warning("'region' from {$id}: {$th->getMessage()}");
}

View file

@ -47,8 +47,8 @@ class V17 extends Migration
$id = "bucket_{$bucket->getInternalId()}";
try {
$this->projectDB->updateAttribute($id, 'mimeType', Database::VAR_STRING, 255, true, false);
$this->projectDB->purgeCachedCollection($id);
$this->dbForProject->updateAttribute($id, 'mimeType', Database::VAR_STRING, 255, true, false);
$this->dbForProject->purgeCachedCollection($id);
} catch (\Throwable $th) {
Console::warning("'mimeType' from {$id}: {$th->getMessage()}");
}
@ -67,7 +67,7 @@ class V17 extends Migration
Console::log("Migrating Collection \"{$id}\"");
$this->projectDB->setNamespace("_{$this->project->getInternalId()}");
$this->dbForProject->setNamespace("_{$this->project->getInternalId()}");
switch ($id) {
case 'builds':
@ -75,8 +75,8 @@ class V17 extends Migration
/**
* Create 'size' attribute
*/
$this->createAttributeFromCollection($this->projectDB, $id, 'size');
$this->projectDB->purgeCachedCollection($id);
$this->createAttributeFromCollection($this->dbForProject, $id, 'size');
$this->dbForProject->purgeCachedCollection($id);
} catch (\Throwable $th) {
Console::warning("'size' from {$id}: {$th->getMessage()}");
}
@ -87,8 +87,8 @@ class V17 extends Migration
/**
* Update 'mimeType' attribute size (127->255)
*/
$this->projectDB->updateAttribute($id, 'mimeType', Database::VAR_STRING, 255, true, false);
$this->projectDB->purgeCachedCollection($id);
$this->dbForProject->updateAttribute($id, 'mimeType', Database::VAR_STRING, 255, true, false);
$this->dbForProject->purgeCachedCollection($id);
} catch (\Throwable $th) {
Console::warning("'mimeType' from {$id}: {$th->getMessage()}");
}
@ -97,8 +97,8 @@ class V17 extends Migration
/**
* Create 'bucketInternalId' attribute
*/
$this->createAttributeFromCollection($this->projectDB, $id, 'bucketInternalId');
$this->projectDB->purgeCachedCollection($id);
$this->createAttributeFromCollection($this->dbForProject, $id, 'bucketInternalId');
$this->dbForProject->purgeCachedCollection($id);
} catch (\Throwable $th) {
Console::warning("'deploymentInternalId' from {$id}: {$th->getMessage()}");
}
@ -109,8 +109,8 @@ class V17 extends Migration
/**
* Delete 'endTime' attribute (use startTime+duration if needed)
*/
$this->projectDB->deleteAttribute($id, 'endTime');
$this->projectDB->purgeCachedCollection($id);
$this->dbForProject->deleteAttribute($id, 'endTime');
$this->dbForProject->purgeCachedCollection($id);
} catch (\Throwable $th) {
Console::warning("'endTime' from {$id}: {$th->getMessage()}");
}
@ -119,8 +119,8 @@ class V17 extends Migration
/**
* Rename 'outputPath' to 'path'
*/
$this->projectDB->renameAttribute($id, 'outputPath', 'path');
$this->projectDB->purgeCachedCollection($id);
$this->dbForProject->renameAttribute($id, 'outputPath', 'path');
$this->dbForProject->purgeCachedCollection($id);
} catch (\Throwable $th) {
Console::warning("'path' from {$id}: {$th->getMessage()}");
}
@ -129,8 +129,8 @@ class V17 extends Migration
/**
* Create 'deploymentInternalId' attribute
*/
$this->createAttributeFromCollection($this->projectDB, $id, 'deploymentInternalId');
$this->projectDB->purgeCachedCollection($id);
$this->createAttributeFromCollection($this->dbForProject, $id, 'deploymentInternalId');
$this->dbForProject->purgeCachedCollection($id);
} catch (\Throwable $th) {
Console::warning("'deploymentInternalId' from {$id}: {$th->getMessage()}");
}
@ -141,8 +141,8 @@ class V17 extends Migration
/**
* Delete 'type' attribute
*/
$this->projectDB->deleteAttribute($id, 'type');
$this->projectDB->purgeCachedCollection($id);
$this->dbForProject->deleteAttribute($id, 'type');
$this->dbForProject->purgeCachedCollection($id);
} catch (\Throwable $th) {
Console::warning("'type' from {$id}: {$th->getMessage()}");
}
@ -153,8 +153,8 @@ class V17 extends Migration
/**
* Create 'resourceInternalId' attribute
*/
$this->createAttributeFromCollection($this->projectDB, $id, 'resourceInternalId');
$this->projectDB->purgeCachedCollection($id);
$this->createAttributeFromCollection($this->dbForProject, $id, 'resourceInternalId');
$this->dbForProject->purgeCachedCollection($id);
} catch (\Throwable $th) {
Console::warning("'resourceInternalId' from {$id}: {$th->getMessage()}");
}
@ -165,8 +165,8 @@ class V17 extends Migration
/**
* Create 'deploymentInternalId' attribute
*/
$this->createAttributeFromCollection($this->projectDB, $id, 'deploymentInternalId');
$this->projectDB->purgeCachedCollection($id);
$this->createAttributeFromCollection($this->dbForProject, $id, 'deploymentInternalId');
$this->dbForProject->purgeCachedCollection($id);
} catch (\Throwable $th) {
Console::warning("'deploymentInternalId' from {$id}: {$th->getMessage()}");
}
@ -175,8 +175,8 @@ class V17 extends Migration
/**
* Create 'scheduleInternalId' attribute
*/
$this->createAttributeFromCollection($this->projectDB, $id, 'scheduleInternalId');
$this->projectDB->purgeCachedCollection($id);
$this->createAttributeFromCollection($this->dbForProject, $id, 'scheduleInternalId');
$this->dbForProject->purgeCachedCollection($id);
} catch (\Throwable $th) {
Console::warning("'scheduleInternalId' from {$id}: {$th->getMessage()}");
}
@ -185,8 +185,8 @@ class V17 extends Migration
/**
* Delete 'scheduleUpdatedAt' attribute
*/
$this->projectDB->deleteAttribute($id, 'scheduleUpdatedAt');
$this->projectDB->purgeCachedCollection($id);
$this->dbForProject->deleteAttribute($id, 'scheduleUpdatedAt');
$this->dbForProject->purgeCachedCollection($id);
} catch (\Throwable $th) {
Console::warning("'scheduleUpdatedAt' from {$id}: {$th->getMessage()}");
}
@ -197,8 +197,8 @@ class V17 extends Migration
/**
* Create 'resourceInternalId' attribute
*/
$this->createAttributeFromCollection($this->projectDB, $id, 'resourceInternalId');
$this->projectDB->purgeCachedCollection($id);
$this->createAttributeFromCollection($this->dbForProject, $id, 'resourceInternalId');
$this->dbForProject->purgeCachedCollection($id);
} catch (\Throwable $th) {
Console::warning("'resourceInternalId' from {$id}: {$th->getMessage()}");
}
@ -207,8 +207,8 @@ class V17 extends Migration
/**
* Create 'buildInternalId' attribute
*/
$this->createAttributeFromCollection($this->projectDB, $id, 'buildInternalId');
$this->projectDB->purgeCachedCollection($id);
$this->createAttributeFromCollection($this->dbForProject, $id, 'buildInternalId');
$this->dbForProject->purgeCachedCollection($id);
} catch (\Throwable $th) {
Console::warning("'buildInternalId' from {$id}: {$th->getMessage()}");
}
@ -219,8 +219,8 @@ class V17 extends Migration
/**
* Create 'functionInternalId' attribute
*/
$this->createAttributeFromCollection($this->projectDB, $id, 'functionInternalId');
$this->projectDB->purgeCachedCollection($id);
$this->createAttributeFromCollection($this->dbForProject, $id, 'functionInternalId');
$this->dbForProject->purgeCachedCollection($id);
} catch (\Throwable $th) {
Console::warning("'functionInternalId' from {$id}: {$th->getMessage()}");
}
@ -229,8 +229,8 @@ class V17 extends Migration
/**
* Create 'deploymentInternalId' attribute
*/
$this->createAttributeFromCollection($this->projectDB, $id, 'deploymentInternalId');
$this->projectDB->purgeCachedCollection($id);
$this->createAttributeFromCollection($this->dbForProject, $id, 'deploymentInternalId');
$this->dbForProject->purgeCachedCollection($id);
} catch (\Throwable $th) {
Console::warning("'deploymentInternalId' from {$id}: {$th->getMessage()}");
}

View file

@ -26,7 +26,7 @@ class V18 extends Migration
}
Console::log('Migrating Project: ' . $this->project->getAttribute('name') . ' (' . $this->project->getId() . ')');
$this->projectDB->setNamespace("_{$this->project->getInternalId()}");
$this->dbForProject->setNamespace("_{$this->project->getInternalId()}");
$this->addDocumentSecurityToProject();
Console::info('Migrating Databases');
@ -66,7 +66,7 @@ class V18 extends Migration
$documentSecurity = $collection->getAttribute('documentSecurity', false);
$permissions = $collection->getPermissions();
$this->projectDB->updateCollection($collectionTable, $permissions, $documentSecurity);
$this->dbForProject->updateCollection($collectionTable, $permissions, $documentSecurity);
} catch (\Throwable $th) {
Console::warning($th->getMessage());
}
@ -94,7 +94,7 @@ class V18 extends Migration
}
try {
$this->projectDB->updateCollection($id, [Permission::create(Role::any())], true);
$this->dbForProject->updateCollection($id, [Permission::create(Role::any())], true);
} catch (\Throwable $th) {
Console::warning($th->getMessage());
}
@ -105,8 +105,8 @@ class V18 extends Migration
/**
* Create 'passwordHistory' attribute
*/
$this->createAttributeFromCollection($this->projectDB, $id, 'passwordHistory');
$this->projectDB->purgeCachedCollection($id);
$this->createAttributeFromCollection($this->dbForProject, $id, 'passwordHistory');
$this->dbForProject->purgeCachedCollection($id);
} catch (\Throwable $th) {
Console::warning("'passwordHistory' from {$id}: {$th->getMessage()}");
}
@ -116,8 +116,8 @@ class V18 extends Migration
/**
* Create 'prefs' attribute
*/
$this->createAttributeFromCollection($this->projectDB, $id, 'prefs');
$this->projectDB->purgeCachedCollection($id);
$this->createAttributeFromCollection($this->dbForProject, $id, 'prefs');
$this->dbForProject->purgeCachedCollection($id);
} catch (\Throwable $th) {
Console::warning("'prefs' from {$id}: {$th->getMessage()}");
}
@ -127,8 +127,8 @@ class V18 extends Migration
/**
* Create 'options' attribute
*/
$this->createAttributeFromCollection($this->projectDB, $id, 'options');
$this->projectDB->purgeCachedCollection($id);
$this->createAttributeFromCollection($this->dbForProject, $id, 'options');
$this->dbForProject->purgeCachedCollection($id);
} catch (\Throwable $th) {
Console::warning("'options' from {$id}: {$th->getMessage()}");
}
@ -138,7 +138,7 @@ class V18 extends Migration
/**
* Delete 'userInternalId' attribute
*/
$this->projectDB->deleteAttribute($id, 'userInternalId');
$this->dbForProject->deleteAttribute($id, 'userInternalId');
} catch (\Throwable $th) {
Console::warning("'userInternalId' from {$id}: {$th->getMessage()}");
}
@ -200,7 +200,7 @@ class V18 extends Migration
$internalBucketId = "bucket_{$this->project->getInternalId()}";
$permissions = $document->getPermissions();
$fileSecurity = $document->getAttribute('fileSecurity', false);
$this->projectDB->updateCollection($internalBucketId, $permissions, $fileSecurity);
$this->dbForProject->updateCollection($internalBucketId, $permissions, $fileSecurity);
} catch (\Throwable $th) {
Console::warning($th->getMessage());
}
@ -214,8 +214,8 @@ class V18 extends Migration
$data = $document->getAttribute('data', []);
$mode = $data['mode'] ?? 'default';
$user = match ($mode) {
'admin' => $this->consoleDB->getDocument('users', $userId),
default => $this->projectDB->getDocument('users', $userId),
'admin' => $this->dbForPlatform->getDocument('users', $userId),
default => $this->dbForProject->getDocument('users', $userId),
};
if ($user->isEmpty()) {
@ -244,7 +244,7 @@ class V18 extends Migration
/**
* Create 'documentSecurity' column
*/
$this->pdo->prepare("ALTER TABLE `{$this->projectDB->getDatabase()}`.`_{$this->project->getInternalId()}__metadata` ADD COLUMN IF NOT EXISTS documentSecurity TINYINT(1);")->execute();
$this->pdo->prepare("ALTER TABLE `{$this->dbForProject->getDatabase()}`.`_{$this->project->getInternalId()}__metadata` ADD COLUMN IF NOT EXISTS documentSecurity TINYINT(1);")->execute();
} catch (\Throwable $th) {
Console::warning($th->getMessage());
}
@ -253,7 +253,7 @@ class V18 extends Migration
/**
* Set 'documentSecurity' column to 1 if NULL
*/
$this->pdo->prepare("UPDATE `{$this->projectDB->getDatabase()}`.`_{$this->project->getInternalId()}__metadata` SET documentSecurity = 1 WHERE documentSecurity IS NULL")->execute();
$this->pdo->prepare("UPDATE `{$this->dbForProject->getDatabase()}`.`_{$this->project->getInternalId()}__metadata` SET documentSecurity = 1 WHERE documentSecurity IS NULL")->execute();
} catch (\Throwable $th) {
Console::warning($th->getMessage());
}

View file

@ -28,7 +28,7 @@ class V19 extends Migration
}
Console::log('Migrating Project: ' . $this->project->getAttribute('name') . ' (' . $this->project->getId() . ')');
$this->projectDB->setNamespace("_{$this->project->getInternalId()}");
$this->dbForProject->setNamespace("_{$this->project->getInternalId()}");
Console::info('Migrating Collections');
$this->migrateCollections();
@ -55,7 +55,7 @@ class V19 extends Migration
protected function migrateDomains(): void
{
if ($this->consoleDB->exists($this->consoleDB->getDatabase(), 'domains')) {
if ($this->dbForPlatform->exists($this->dbForPlatform->getDatabase(), 'domains')) {
foreach ($this->documentsIterator('domains') as $domain) {
$status = 'created';
if ($domain->getAttribute('verification', false)) {
@ -82,7 +82,7 @@ class V19 extends Migration
]);
try {
$this->consoleDB->createDocument('rules', $ruleDocument);
$this->dbForPlatform->createDocument('rules', $ruleDocument);
} catch (\Throwable $th) {
Console::warning("Error migrating domain {$domain->getAttribute('domain')}: {$th->getMessage()}");
}
@ -104,8 +104,8 @@ class V19 extends Migration
Console::log("Migrating Bucket {$id} {$bucket->getId()} ({$bucket->getAttribute('name')})");
try {
$this->createAttributeFromCollection($this->projectDB, $id, 'bucketInternalId', 'files');
$this->projectDB->purgeCachedCollection($id);
$this->createAttributeFromCollection($this->dbForProject, $id, 'bucketInternalId', 'files');
$this->dbForProject->purgeCachedCollection($id);
} catch (\Throwable $th) {
Console::warning("'bucketInternalId' from {$id}: {$th->getMessage()}");
}
@ -136,7 +136,7 @@ class V19 extends Migration
Console::log("Migrating Collection \"{$id}\"");
$this->projectDB->setNamespace("_$internalProjectId");
$this->dbForProject->setNamespace("_$internalProjectId");
switch ($id) {
case '_metadata':
@ -148,24 +148,24 @@ class V19 extends Migration
case 'attributes':
case 'indexes':
try {
$this->projectDB->updateAttribute($id, 'databaseInternalId', required: true);
$this->dbForProject->updateAttribute($id, 'databaseInternalId', required: true);
} catch (\Throwable $th) {
Console::warning("'databaseInternalId' from {$id}: {$th->getMessage()}");
}
try {
$this->projectDB->updateAttribute($id, 'collectionInternalId', required: true);
$this->dbForProject->updateAttribute($id, 'collectionInternalId', required: true);
} catch (\Throwable $th) {
Console::warning("'collectionInternalId' from {$id}: {$th->getMessage()}");
}
try {
$this->createAttributeFromCollection($this->projectDB, $id, 'error');
$this->createAttributeFromCollection($this->dbForProject, $id, 'error');
} catch (\Throwable $th) {
Console::warning("'error' from {$id}: {$th->getMessage()}");
}
$this->projectDB->purgeCachedCollection($id);
$this->dbForProject->purgeCachedCollection($id);
break;
case 'buckets':
@ -175,7 +175,7 @@ class V19 extends Migration
];
foreach ($indexesToDelete as $index) {
try {
$this->projectDB->deleteIndex($id, $index);
$this->dbForProject->deleteIndex($id, $index);
} catch (\Throwable $th) {
Console::warning("'$index' from {$id}: {$th->getMessage()}");
}
@ -187,13 +187,13 @@ class V19 extends Migration
foreach ($indexesToCreate as $index) {
try {
$this->createIndexFromCollection($this->projectDB, $id, $index);
$this->createIndexFromCollection($this->dbForProject, $id, $index);
} catch (\Throwable $th) {
Console::warning("'$index' from {$id}: {$th->getMessage()}");
}
}
$this->projectDB->purgeCachedCollection($id);
$this->dbForProject->purgeCachedCollection($id);
break;
case 'builds':
@ -204,45 +204,45 @@ class V19 extends Migration
];
foreach ($attributesToCreate as $attribute) {
try {
$this->createAttributeFromCollection($this->projectDB, $id, $attribute);
$this->createAttributeFromCollection($this->dbForProject, $id, $attribute);
} catch (\Throwable $th) {
Console::warning("$attribute from {$id}: {$th->getMessage()}");
}
}
try {
$this->projectDB->renameAttribute($id, 'outputPath', 'path');
$this->dbForProject->renameAttribute($id, 'outputPath', 'path');
} catch (\Throwable $th) {
Console::warning("'path' from {$id}: {$th->getMessage()}");
}
$this->projectDB->purgeCachedCollection($id);
$this->dbForProject->purgeCachedCollection($id);
break;
case 'certificates':
try {
$this->projectDB->renameAttribute($id, 'log', 'logs');
$this->dbForProject->renameAttribute($id, 'log', 'logs');
} catch (\Throwable $th) {
Console::warning("'logs' from {$id}: {$th->getMessage()}");
}
try {
$this->projectDB->updateAttribute($id, 'logs', size: 1000000);
$this->dbForProject->updateAttribute($id, 'logs', size: 1000000);
} catch (\Throwable $th) {
Console::warning("'logs' from {$id}: {$th->getMessage()}");
}
$this->projectDB->purgeCachedCollection($id);
$this->dbForProject->purgeCachedCollection($id);
break;
case 'databases':
try {
$this->createAttributeFromCollection($this->projectDB, $id, 'enabled');
$this->createAttributeFromCollection($this->dbForProject, $id, 'enabled');
} catch (\Throwable $th) {
Console::warning("'enabled' from {$id}: {$th->getMessage()}");
}
$this->projectDB->purgeCachedCollection($id);
$this->dbForProject->purgeCachedCollection($id);
break;
case 'deployments':
@ -271,7 +271,7 @@ class V19 extends Migration
];
foreach ($attributesToCreate as $attribute) {
try {
$this->createAttributeFromCollection($this->projectDB, $id, $attribute);
$this->createAttributeFromCollection($this->dbForProject, $id, $attribute);
} catch (\Throwable $th) {
Console::warning("$attribute from {$id}: {$th->getMessage()}");
}
@ -286,7 +286,7 @@ class V19 extends Migration
];
foreach ($indexesToDelete as $index) {
try {
$this->projectDB->deleteIndex($id, $index);
$this->dbForProject->deleteIndex($id, $index);
} catch (\Throwable $th) {
Console::warning("'$index' from {$id}: {$th->getMessage()}");
}
@ -299,13 +299,13 @@ class V19 extends Migration
];
foreach ($indexesToCreate as $index) {
try {
$this->createIndexFromCollection($this->projectDB, $id, $index);
$this->createIndexFromCollection($this->dbForProject, $id, $index);
} catch (\Throwable $th) {
Console::warning("'$index' from {$id}: {$th->getMessage()}");
}
}
$this->projectDB->purgeCachedCollection($id);
$this->dbForProject->purgeCachedCollection($id);
break;
case 'executions':
@ -319,7 +319,7 @@ class V19 extends Migration
];
foreach ($attributesToCreate as $attribute) {
try {
$this->createAttributeFromCollection($this->projectDB, $id, $attribute);
$this->createAttributeFromCollection($this->dbForProject, $id, $attribute);
} catch (\Throwable $th) {
Console::warning("$attribute from {$id}: {$th->getMessage()}");
}
@ -330,43 +330,43 @@ class V19 extends Migration
];
foreach ($attributesToDelete as $attribute) {
try {
$this->projectDB->deleteAttribute($id, $attribute);
$this->dbForProject->deleteAttribute($id, $attribute);
} catch (\Throwable $th) {
Console::warning("'$attribute' from {$id}: {$th->getMessage()}");
}
}
try {
$this->projectDB->renameAttribute($id, 'stderr', 'errors');
$this->dbForProject->renameAttribute($id, 'stderr', 'errors');
} catch (\Throwable $th) {
Console::warning("'errors' from {$id}: {$th->getMessage()}");
}
try {
$this->projectDB->renameAttribute($id, 'stdout', 'logs');
$this->dbForProject->renameAttribute($id, 'stdout', 'logs');
} catch (\Throwable $th) {
Console::warning("'logs' from {$id}: {$th->getMessage()}");
}
try {
$this->projectDB->renameAttribute($id, 'statusCode', 'responseStatusCode');
$this->dbForProject->renameAttribute($id, 'statusCode', 'responseStatusCode');
} catch (\Throwable $th) {
Console::warning("'responseStatusCode' from {$id}: {$th->getMessage()}");
}
try {
$this->projectDB->deleteIndex($id, '_key_statusCode');
$this->dbForProject->deleteIndex($id, '_key_statusCode');
} catch (\Throwable $th) {
Console::warning("'_key_statusCode' from {$id}: {$th->getMessage()}");
}
try {
$this->createIndexFromCollection($this->projectDB, $id, '_key_responseStatusCode');
$this->createIndexFromCollection($this->dbForProject, $id, '_key_responseStatusCode');
} catch (\Throwable $th) {
Console::warning("'_key_responseStatusCode' from {$id}: {$th->getMessage()}");
}
$this->projectDB->purgeCachedCollection($id);
$this->dbForProject->purgeCachedCollection($id);
break;
case 'files':
@ -378,7 +378,7 @@ class V19 extends Migration
];
foreach ($indexesToDelete as $index) {
try {
$this->projectDB->deleteIndex($id, $index);
$this->dbForProject->deleteIndex($id, $index);
} catch (\Throwable $th) {
Console::warning("'$index' from {$id}: {$th->getMessage()}");
}
@ -387,13 +387,13 @@ class V19 extends Migration
$indexesToCreate = $indexesToDelete;
foreach ($indexesToCreate as $index) {
try {
$this->createIndexFromCollection($this->projectDB, $id, $index);
$this->createIndexFromCollection($this->dbForProject, $id, $index);
} catch (\Throwable $th) {
Console::warning("'$index' from {$id}: {$th->getMessage()}");
}
}
$this->projectDB->purgeCachedCollection($id);
$this->dbForProject->purgeCachedCollection($id);
break;
case 'functions':
@ -419,7 +419,7 @@ class V19 extends Migration
];
foreach ($attributesToCreate as $attribute) {
try {
$this->createAttributeFromCollection($this->projectDB, $id, $attribute);
$this->createAttributeFromCollection($this->dbForProject, $id, $attribute);
} catch (\Throwable $th) {
Console::warning("'$attribute' from {$id}: {$th->getMessage()}");
}
@ -433,7 +433,7 @@ class V19 extends Migration
];
foreach ($indexesToDelete as $index) {
try {
$this->projectDB->deleteIndex($id, $index);
$this->dbForProject->deleteIndex($id, $index);
} catch (\Throwable $th) {
Console::warning("'$index' from {$id}: {$th->getMessage()}");
}
@ -449,34 +449,34 @@ class V19 extends Migration
];
foreach ($indexesToCreate as $index) {
try {
$this->createIndexFromCollection($this->projectDB, $id, $index);
$this->createIndexFromCollection($this->dbForProject, $id, $index);
} catch (\Throwable $th) {
Console::warning("'$index' from {$id}: {$th->getMessage()}");
}
}
$this->projectDB->purgeCachedCollection($id);
$this->dbForProject->purgeCachedCollection($id);
break;
case 'memberships':
try {
$this->projectDB->updateAttribute($id, 'teamInternalId', required: true);
$this->dbForProject->updateAttribute($id, 'teamInternalId', required: true);
} catch (\Throwable $th) {
Console::warning("'teamInternalId' from {$id}: {$th->getMessage()}");
}
$this->projectDB->purgeCachedCollection($id);
$this->dbForProject->purgeCachedCollection($id);
// Intentional fall through to update memberships.userInternalId
case 'sessions':
case 'tokens':
try {
$this->projectDB->updateAttribute($id, 'userInternalId', required: true);
$this->dbForProject->updateAttribute($id, 'userInternalId', required: true);
} catch (\Throwable $th) {
Console::warning("'userInternalId' from {$id}: {$th->getMessage()}");
}
$this->projectDB->purgeCachedCollection($id);
$this->dbForProject->purgeCachedCollection($id);
break;
case 'domains':
@ -484,12 +484,12 @@ class V19 extends Migration
case 'platforms':
case 'webhooks':
try {
$this->projectDB->updateAttribute($id, 'projectInternalId', required: true);
$this->dbForProject->updateAttribute($id, 'projectInternalId', required: true);
} catch (\Throwable $th) {
Console::warning("'projectInternalId' from {$id}: {$th->getMessage()}");
}
$this->projectDB->purgeCachedCollection($id);
$this->dbForProject->purgeCachedCollection($id);
break;
case 'projects':
@ -500,19 +500,19 @@ class V19 extends Migration
];
foreach ($attributesToCreate as $attribute) {
try {
$this->createAttributeFromCollection($this->projectDB, $id, $attribute);
$this->createAttributeFromCollection($this->dbForProject, $id, $attribute);
} catch (\Throwable $th) {
Console::warning("'$attribute' from {$id}: {$th->getMessage()}");
Console::warning($th->getTraceAsString());
}
}
$this->projectDB->purgeCachedCollection($id);
$this->dbForProject->purgeCachedCollection($id);
break;
case 'stats':
try {
$this->projectDB->updateAttribute($id, 'value', signed: true);
$this->dbForProject->updateAttribute($id, 'value', signed: true);
} catch (\Throwable $th) {
Console::warning("'value' from {$id}: {$th->getMessage()}");
}
@ -539,64 +539,64 @@ class V19 extends Migration
// Console::warning("'_key_metric_period_time' from {$id}: {$th->getMessage()}");
// }
$this->projectDB->purgeCachedCollection($id);
$this->dbForProject->purgeCachedCollection($id);
break;
case 'users':
try {
$this->createAttributeFromCollection($this->projectDB, $id, 'labels');
$this->createAttributeFromCollection($this->dbForProject, $id, 'labels');
} catch (\Throwable $th) {
Console::warning("'labels' from {$id}: {$th->getMessage()}");
}
try {
$this->createAttributeFromCollection($this->projectDB, $id, 'accessedAt');
$this->createAttributeFromCollection($this->dbForProject, $id, 'accessedAt');
} catch (\Throwable $th) {
Console::warning("'accessedAt' from {$id}: {$th->getMessage()}");
}
try {
$this->projectDB->updateAttribute($id, 'search', filters: ['userSearch']);
$this->dbForProject->updateAttribute($id, 'search', filters: ['userSearch']);
} catch (\Throwable $th) {
Console::warning("'search' from {$id}: {$th->getMessage()}");
}
try {
$this->createIndexFromCollection($this->projectDB, $id, '_key_accessedAt');
$this->createIndexFromCollection($this->dbForProject, $id, '_key_accessedAt');
} catch (\Throwable $th) {
Console::warning("'_key_accessedAt' from {$id}: {$th->getMessage()}");
}
$this->projectDB->purgeCachedCollection($id);
$this->dbForProject->purgeCachedCollection($id);
break;
case 'variables':
try {
$this->projectDB->deleteIndex($id, '_key_function');
$this->dbForProject->deleteIndex($id, '_key_function');
} catch (\Throwable $th) {
Console::warning("'_key_function' from {$id}: {$th->getMessage()}");
}
try {
$this->projectDB->deleteIndex($id, '_key_uniqueKey');
$this->dbForProject->deleteIndex($id, '_key_uniqueKey');
} catch (\Throwable $th) {
Console::warning("'_key_uniqueKey' from {$id}: {$th->getMessage()}");
}
try {
$this->createAttributeFromCollection($this->projectDB, $id, 'resourceType');
$this->createAttributeFromCollection($this->dbForProject, $id, 'resourceType');
} catch (\Throwable $th) {
Console::warning("'resourceType' from {$id}: {$th->getMessage()}");
}
try {
$this->projectDB->renameAttribute($id, 'functionInternalId', 'resourceInternalId');
$this->dbForProject->renameAttribute($id, 'functionInternalId', 'resourceInternalId');
} catch (\Throwable $th) {
Console::warning("'resourceInternalId' from {$id}: {$th->getMessage()}");
}
try {
$this->projectDB->renameAttribute($id, 'functionId', 'resourceId');
$this->dbForProject->renameAttribute($id, 'functionId', 'resourceId');
} catch (\Throwable $th) {
Console::warning("'resourceId' from {$id}: {$th->getMessage()}");
}
@ -609,13 +609,13 @@ class V19 extends Migration
];
foreach ($indexesToCreate as $index) {
try {
$this->createIndexFromCollection($this->projectDB, $id, $index);
$this->createIndexFromCollection($this->dbForProject, $id, $index);
} catch (\Throwable $th) {
Console::warning("'$index' from {$id}: {$th->getMessage()}");
}
}
$this->projectDB->purgeCachedCollection($id);
$this->dbForProject->purgeCachedCollection($id);
break;
default:
@ -654,10 +654,10 @@ class V19 extends Migration
]) as $attribute
) {
$attribute->setAttribute('size', Database::LENGTH_KEY);
$this->projectDB->updateDocument('attributes', $attribute->getId(), $attribute);
$this->dbForProject->updateDocument('attributes', $attribute->getId(), $attribute);
$databaseInternalId = $attribute->getAttribute('databaseInternalId');
$collectionInternalId = $attribute->getAttribute('collectionInternalId');
$this->projectDB->updateAttribute('database_' . $databaseInternalId . '_collection_' . $collectionInternalId, $attribute->getAttribute('key'), size: 255);
$this->dbForProject->updateAttribute('database_' . $databaseInternalId . '_collection_' . $collectionInternalId, $attribute->getAttribute('key'), size: 255);
}
}
@ -679,7 +679,7 @@ class V19 extends Migration
break;
case 'builds':
$deploymentId = $document->getAttribute('deploymentId');
$deployment = $this->projectDB->getDocument('deployments', $deploymentId);
$deployment = $this->dbForProject->getDocument('deployments', $deploymentId);
$document->setAttribute('deploymentInternalId', $deployment->getInternalId());
$stdout = $document->getAttribute('stdout', '');
@ -691,12 +691,12 @@ class V19 extends Migration
break;
case 'deployments':
$resourceId = $document->getAttribute('resourceId');
$function = $this->projectDB->getDocument('functions', $resourceId);
$function = $this->dbForProject->getDocument('functions', $resourceId);
$document->setAttribute('resourceInternalId', $function->getInternalId());
$buildId = $document->getAttribute('buildId');
if (!empty($buildId)) {
$build = $this->projectDB->getDocument('builds', $buildId);
$build = $this->dbForProject->getDocument('builds', $buildId);
$document->setAttribute('buildInternalId', $build->getInternalId());
}
@ -706,11 +706,11 @@ class V19 extends Migration
break;
case 'executions':
$functionId = $document->getAttribute('functionId');
$function = $this->projectDB->getDocument('functions', $functionId);
$function = $this->dbForProject->getDocument('functions', $functionId);
$document->setAttribute('functionInternalId', $function->getInternalId());
$deploymentId = $document->getAttribute('deploymentId');
$deployment = $this->projectDB->getDocument('deployments', $deploymentId);
$deployment = $this->dbForProject->getDocument('deployments', $deploymentId);
$document->setAttribute('deploymentInternalId', $deployment->getInternalId());
break;
case 'functions':
@ -720,7 +720,7 @@ class V19 extends Migration
$deploymentId = $document->getAttribute('deployment');
if (!empty($deploymentId)) {
$deployment = $this->projectDB->getDocument('deployments', $deploymentId);
$deployment = $this->dbForProject->getDocument('deployments', $deploymentId);
$document->setAttribute('deploymentInternalId', $deployment->getInternalId());
$document->setAttribute('entrypoint', $deployment->getAttribute('entrypoint'));
}
@ -729,7 +729,7 @@ class V19 extends Migration
$document->setAttribute('commands', $document->getAttribute('commands', $commands));
if (empty($document->getAttribute('scheduleId', null))) {
$schedule = $this->consoleDB->createDocument('schedules', new Document([
$schedule = $this->dbForPlatform->createDocument('schedules', new Document([
'region' => $project->getAttribute('region'),
'resourceType' => 'function',
'resourceId' => $document->getId(),
@ -769,26 +769,26 @@ class V19 extends Migration
private function cleanCollections(): void
{
try {
$this->projectDB->deleteAttribute('projects', 'domains');
$this->dbForProject->deleteAttribute('projects', 'domains');
} catch (\Throwable $th) {
Console::warning("'domains' from projects: {$th->getMessage()}");
}
$this->projectDB->purgeCachedCollection('projects');
$this->dbForProject->purgeCachedCollection('projects');
try {
$this->projectDB->deleteAttribute('builds', 'stderr');
$this->dbForProject->deleteAttribute('builds', 'stderr');
} catch (\Throwable $th) {
Console::warning("'stderr' from builds: {$th->getMessage()}");
}
try {
$this->projectDB->deleteAttribute('builds', 'stdout');
$this->dbForProject->deleteAttribute('builds', 'stdout');
} catch (\Throwable $th) {
Console::warning("'stdout' from builds: {$th->getMessage()}");
}
$this->projectDB->purgeCachedCollection('builds');
$this->dbForProject->purgeCachedCollection('builds');
}
/**
@ -829,7 +829,7 @@ class V19 extends Migration
}
try {
$this->projectDB->updateDocument($document->getCollection(), $document->getId(), $document);
$this->dbForProject->updateDocument($document->getCollection(), $document->getId(), $document);
} catch (\Throwable $th) {
Console::error('Failed to update document: ' . $th->getMessage());
return;

View file

@ -36,7 +36,7 @@ class V20 extends Migration
}
Console::log('Migrating Project: ' . $this->project->getAttribute('name') . ' (' . $this->project->getId() . ')');
$this->projectDB->setNamespace("_{$this->project->getInternalId()}");
$this->dbForProject->setNamespace("_{$this->project->getInternalId()}");
Console::info('Migrating Collections');
$this->migrateCollections();
@ -94,19 +94,19 @@ class V20 extends Migration
) {
if (\in_array($attribute->getAttribute('key'), $index->getAttribute('attributes'))) {
try {
$this->projectDB->deleteIndex($collectionId, $index->getAttribute('key'));
$this->dbForProject->deleteIndex($collectionId, $index->getAttribute('key'));
} catch (Throwable $th) {
Console::warning("Failed to delete index: {$th->getMessage()}");
}
try {
$this->projectDB->deleteDocument('indexes', $index->getId());
$this->dbForProject->deleteDocument('indexes', $index->getId());
} catch (Throwable $th) {
Console::warning("Failed to remove index: {$th->getMessage()}");
}
}
}
$this->projectDB->updateAttribute($collectionId, $attribute['key'], $attribute['type']);
$this->dbForProject->updateAttribute($collectionId, $attribute['key'], $attribute['type']);
}
}
@ -116,19 +116,19 @@ class V20 extends Migration
Console::log("Migrating Collection \"{$id}\"");
$this->projectDB->setNamespace("_$internalProjectId");
$this->dbForProject->setNamespace("_$internalProjectId");
// Support database array type migration
foreach ($collection['attributes'] ?? [] as $attribute) {
if ($attribute['array'] === true) {
foreach ($collection['indexes'] ?? [] as $index) {
if (\in_array($attribute['$id'], $index['attributes'])) {
$this->projectDB->deleteIndex($id, $index['$id']);
$this->dbForProject->deleteIndex($id, $index['$id']);
}
}
try {
$this->projectDB->updateAttribute($id, $attribute['$id'], $attribute['type']);
$this->dbForProject->updateAttribute($id, $attribute['$id'], $attribute['type']);
} catch (Throwable $th) {
Console::warning("'{$attribute['$id']}' from {$id}: {$th->getMessage()}");
}
@ -151,19 +151,19 @@ class V20 extends Migration
// Create resourceType attribute
try {
$this->createAttributeFromCollection($this->projectDB, $id, 'resourceType');
$this->createAttributeFromCollection($this->dbForProject, $id, 'resourceType');
} catch (Throwable $th) {
Console::warning("'resourceType' from {$id}: {$th->getMessage()}");
}
// Create mimeType attribute
try {
$this->createAttributeFromCollection($this->projectDB, $id, 'mimeType');
$this->createAttributeFromCollection($this->dbForProject, $id, 'mimeType');
} catch (Throwable $th) {
Console::warning("'mimeType' from {$id}: {$th->getMessage()}");
}
try {
$this->projectDB->purgeCachedCollection($id);
$this->dbForProject->purgeCachedCollection($id);
} catch (Throwable $th) {
Console::warning("Purge cache from {$id}: {$th->getMessage()}");
}
@ -174,11 +174,11 @@ class V20 extends Migration
/**
* Delete 'type' attribute
*/
$this->projectDB->deleteAttribute($id, 'type');
$this->dbForProject->deleteAttribute($id, 'type');
/**
* Alter `signed` internal type on `value` attr
*/
$this->projectDB->updateAttribute(collection: $id, id: 'value', signed: true);
$this->dbForProject->updateAttribute(collection: $id, id: 'value', signed: true);
} catch (Throwable $th) {
Console::warning("'type' from {$id}: {$th->getMessage()}");
}
@ -187,13 +187,13 @@ class V20 extends Migration
/**
* Ensure 'time' attribute is not required
*/
$this->projectDB->updateAttribute($id, 'time', required: false);
$this->dbForProject->updateAttribute($id, 'time', required: false);
} catch (Throwable $th) {
Console::warning("'time' from {$id}: {$th->getMessage()}");
}
try {
$this->projectDB->purgeCachedCollection($id);
$this->dbForProject->purgeCachedCollection($id);
} catch (Throwable $th) {
Console::warning("Purge cache from {$id}: {$th->getMessage()}");
}
@ -202,13 +202,13 @@ class V20 extends Migration
$index = '_key_metric_period_time';
try {
$this->projectDB->deleteIndex($id, $index);
$this->dbForProject->deleteIndex($id, $index);
} catch (\Throwable $th) {
Console::warning("'$index' from {$id}: {$th->getMessage()}");
}
try {
$this->createIndexFromCollection($this->projectDB, $id, $index);
$this->createIndexFromCollection($this->dbForProject, $id, $index);
} catch (\Throwable $th) {
Console::warning("'$index' from {$id}: {$th->getMessage()}");
}
@ -217,27 +217,27 @@ class V20 extends Migration
case 'sessions':
// Create expire attribute
try {
$this->createAttributeFromCollection($this->projectDB, $id, 'expire');
$this->createAttributeFromCollection($this->dbForProject, $id, 'expire');
} catch (Throwable $th) {
Console::warning("'expire' from {$id}: {$th->getMessage()}");
}
// Create factors attribute
try {
$this->createAttributeFromCollection($this->projectDB, $id, 'factors');
$this->createAttributeFromCollection($this->dbForProject, $id, 'factors');
} catch (Throwable $th) {
Console::warning("'factors' from {$id}: {$th->getMessage()}");
}
// Create mfaRecoveryCodes attribute
try {
$this->createAttributeFromCollection($this->projectDB, $id, 'mfaUpdatedAt');
$this->createAttributeFromCollection($this->dbForProject, $id, 'mfaUpdatedAt');
} catch (Throwable $th) {
Console::warning("'mfaUpdatedAt' from {$id}: {$th->getMessage()}");
}
try {
$this->projectDB->purgeCachedCollection($id);
$this->dbForProject->purgeCachedCollection($id);
} catch (Throwable $th) {
Console::warning("Purge cache from {$id}: {$th->getMessage()}");
}
@ -246,41 +246,41 @@ class V20 extends Migration
case 'users':
// Create targets attribute
try {
$this->createAttributeFromCollection($this->projectDB, $id, 'targets');
$this->createAttributeFromCollection($this->dbForProject, $id, 'targets');
} catch (Throwable $th) {
Console::warning("'targets' from {$id}: {$th->getMessage()}");
}
// Create mfa attribute
try {
$this->createAttributeFromCollection($this->projectDB, $id, 'mfa');
$this->createAttributeFromCollection($this->dbForProject, $id, 'mfa');
} catch (Throwable $th) {
Console::warning("'mfa' from {$id}: {$th->getMessage()}");
}
// Create mfaRecoveryCodes attribute
try {
$this->createAttributeFromCollection($this->projectDB, $id, 'mfaRecoveryCodes');
$this->createAttributeFromCollection($this->dbForProject, $id, 'mfaRecoveryCodes');
} catch (Throwable $th) {
Console::warning("'mfaRecoveryCodes' from {$id}: {$th->getMessage()}");
}
// Create challenges attribute
try {
$this->createAttributeFromCollection($this->projectDB, $id, 'challenges');
$this->createAttributeFromCollection($this->dbForProject, $id, 'challenges');
} catch (Throwable $th) {
Console::warning("'challenges' from {$id}: {$th->getMessage()}");
}
// Create authenticators attribute
try {
$this->createAttributeFromCollection($this->projectDB, $id, 'authenticators');
$this->createAttributeFromCollection($this->dbForProject, $id, 'authenticators');
} catch (Throwable $th) {
Console::warning("'authenticators' from {$id}: {$th->getMessage()}");
}
try {
$this->projectDB->purgeCachedCollection($id);
$this->dbForProject->purgeCachedCollection($id);
} catch (Throwable $th) {
Console::warning("Purge cache from {$id}: {$th->getMessage()}");
}
@ -289,20 +289,20 @@ class V20 extends Migration
case 'projects':
// Rename providers authProviders to oAuthProviders
try {
$this->projectDB->renameAttribute($id, 'authProviders', 'oAuthProviders');
$this->dbForProject->renameAttribute($id, 'authProviders', 'oAuthProviders');
} catch (Throwable $th) {
Console::warning("'oAuthProviders' from {$id}: {$th->getMessage()}");
}
// Create apis attribute
try {
$this->createAttributeFromCollection($this->projectDB, $id, 'apis');
$this->createAttributeFromCollection($this->dbForProject, $id, 'apis');
} catch (Throwable $th) {
Console::warning("'apis' from {$id}: {$th->getMessage()}");
}
try {
$this->projectDB->purgeCachedCollection($id);
$this->dbForProject->purgeCachedCollection($id);
} catch (Throwable $th) {
Console::warning("Purge cache from {$id}: {$th->getMessage()}");
}
@ -311,27 +311,27 @@ class V20 extends Migration
case 'webhooks':
// Create enabled attribute
try {
$this->createAttributeFromCollection($this->projectDB, $id, 'enabled');
$this->createAttributeFromCollection($this->dbForProject, $id, 'enabled');
} catch (Throwable $th) {
Console::warning("'enabled' from {$id}: {$th->getMessage()}");
}
// Create logs attribute
try {
$this->createAttributeFromCollection($this->projectDB, $id, 'logs');
$this->createAttributeFromCollection($this->dbForProject, $id, 'logs');
} catch (Throwable $th) {
Console::warning("'logs' from {$id}: {$th->getMessage()}");
}
// Create attempts attribute
try {
$this->createAttributeFromCollection($this->projectDB, $id, 'attempts');
$this->createAttributeFromCollection($this->dbForProject, $id, 'attempts');
} catch (Throwable $th) {
Console::warning("'attempts' from {$id}: {$th->getMessage()}");
}
try {
$this->projectDB->purgeCachedCollection($id);
$this->dbForProject->purgeCachedCollection($id);
} catch (Throwable $th) {
Console::warning("Purge cache from {$id}: {$th->getMessage()}");
}
@ -339,25 +339,25 @@ class V20 extends Migration
break;
case 'topics':
try {
$this->projectDB->updateAttributeDefault($id, 'emailTotal', 0);
$this->dbForProject->updateAttributeDefault($id, 'emailTotal', 0);
} catch (Throwable $th) {
Console::warning("'topics' from {$id}: {$th->getMessage()}");
}
try {
$this->projectDB->updateAttributeDefault($id, 'pushTotal', 0);
$this->dbForProject->updateAttributeDefault($id, 'pushTotal', 0);
} catch (Throwable $th) {
Console::warning("'topics' from {$id}: {$th->getMessage()}");
}
try {
$this->projectDB->updateAttributeDefault($id, 'smsTotal', 0);
$this->dbForProject->updateAttributeDefault($id, 'smsTotal', 0);
} catch (Throwable $th) {
Console::warning("'topics' from {$id}: {$th->getMessage()}");
}
try {
$this->projectDB->purgeCachedCollection($id);
$this->dbForProject->purgeCachedCollection($id);
} catch (Throwable $th) {
Console::warning("Purge cache from {$id}: {$th->getMessage()}");
}
@ -382,7 +382,7 @@ class V20 extends Migration
*/
Console::info('Migrating Sessions metric');
$sessionsCreated = $this->projectDB->sum('stats', 'value', [
$sessionsCreated = $this->dbForProject->sum('stats', 'value', [
Query::equal('metric', [
'sessions.email-password.requests.create',
'sessions.magic-url.requests.create',
@ -394,7 +394,7 @@ class V20 extends Migration
Query::equal('period', ['1d']),
]);
$query = $this->projectDB->findOne('stats', [
$query = $this->dbForProject->findOne('stats', [
Query::equal('metric', ['sessions.$all.requests.delete']),
Query::equal('period', ['1d']),
]);
@ -420,7 +420,7 @@ class V20 extends Migration
*/
Console::log("Creating inf metric to {$metric}");
$id = \md5("_inf_{$metric}");
$this->projectDB->createDocument('stats', new Document([
$this->dbForProject->createDocument('stats', new Document([
'$id' => $id,
'metric' => $metric,
'period' => 'inf',
@ -448,7 +448,7 @@ class V20 extends Migration
str_contains($from, '$all') ||
str_contains($from, '.total')
) {
$query = $this->projectDB->sum('stats', 'value', [
$query = $this->dbForProject->sum('stats', 'value', [
Query::equal('metric', [$from]),
Query::equal('period', ['1d']),
]);
@ -470,7 +470,7 @@ class V20 extends Migration
if ($latestDocument !== null) {
$paginationQueries[] = Query::cursorAfter($latestDocument);
}
$stats = $this->projectDB->find('stats', \array_merge($paginationQueries, [
$stats = $this->dbForProject->find('stats', \array_merge($paginationQueries, [
Query::equal('metric', [$from]),
]));
@ -479,10 +479,10 @@ class V20 extends Migration
foreach ($stats as $stat) {
$format = $stat['period'] === '1d' ? 'Y-m-d 00:00' : 'Y-m-d H:00';
$time = date($format, strtotime($stat['time']));
$this->projectDB->deleteDocument('stats', $stat->getId());
$this->dbForProject->deleteDocument('stats', $stat->getId());
$stat->setAttribute('$id', \md5("{$time}_{$stat['period']}_{$to}"));
$stat->setAttribute('metric', $to);
$this->projectDB->createDocument('stats', $stat);
$this->dbForProject->createDocument('stats', $stat);
Console::log("deleting metric {$from} and creating {$to}");
}
$latestDocument = !empty(array_key_last($stats)) ? $stats[array_key_last($stats)] : null;
@ -610,7 +610,7 @@ class V20 extends Migration
'identifier' => $document->getAttribute('email'),
]);
try {
$this->projectDB->createDocument('targets', $target);
$this->dbForProject->createDocument('targets', $target);
} catch (Duplicate $th) {
Console::warning("Email target for user {$document->getId()} already exists.");
}
@ -625,7 +625,7 @@ class V20 extends Migration
'identifier' => $document->getAttribute('phone'),
]);
try {
$this->projectDB->createDocument('targets', $target);
$this->dbForProject->createDocument('targets', $target);
} catch (Duplicate $th) {
Console::warning("Email target for user {$document->getId()} already exists.");
}

View file

@ -29,7 +29,7 @@ class V21 extends Migration
}
Console::log('Migrating Project: ' . $this->project->getAttribute('name') . ' (' . $this->project->getId() . ')');
$this->projectDB->setNamespace("_{$this->project->getInternalId()}");
$this->dbForProject->setNamespace("_{$this->project->getInternalId()}");
Console::info('Migrating Collections');
$this->migrateCollections();
@ -63,13 +63,13 @@ class V21 extends Migration
Console::log("Migrating Collection \"{$id}\"");
$this->projectDB->setNamespace("_$internalProjectId");
$this->dbForProject->setNamespace("_$internalProjectId");
switch ($id) {
case 'projects':
// Create accessedAt attribute
try {
$this->createAttributeFromCollection($this->projectDB, $id, 'accessedAt');
$this->createAttributeFromCollection($this->dbForProject, $id, 'accessedAt');
} catch (Throwable $th) {
Console::warning("'accessedAt' from {$id}: {$th->getMessage()}");
}
@ -77,7 +77,7 @@ class V21 extends Migration
case 'platforms':
// Increase 'type' length to 255
try {
$this->projectDB->updateAttribute($id, 'type', size: 255);
$this->dbForProject->updateAttribute($id, 'type', size: 255);
} catch (Throwable $th) {
Console::warning("'type' from {$id}: {$th->getMessage()}");
}
@ -85,7 +85,7 @@ class V21 extends Migration
case 'migrations':
// Create destination attribute
try {
$this->createAttributeFromCollection($this->projectDB, $id, 'destination');
$this->createAttributeFromCollection($this->dbForProject, $id, 'destination');
} catch (Throwable $th) {
Console::warning("'destination' from {$id}: {$th->getMessage()}");
}
@ -93,7 +93,7 @@ class V21 extends Migration
case 'schedules':
// Create data attribute
try {
$this->createAttributeFromCollection($this->projectDB, $id, 'data');
$this->createAttributeFromCollection($this->dbForProject, $id, 'data');
} catch (Throwable $th) {
Console::warning("'data' from {$id}: {$th->getMessage()}");
}
@ -102,7 +102,7 @@ class V21 extends Migration
case 'databases':
// Create originalId attribute
try {
$this->createAttributeFromCollection($this->projectDB, $id, 'originalId');
$this->createAttributeFromCollection($this->dbForProject, $id, 'originalId');
} catch (Throwable $th) {
Console::warning("'originalId' from {$id}: {$th->getMessage()}");
}
@ -110,14 +110,14 @@ class V21 extends Migration
case 'functions':
// Create scopes attribute
try {
$this->createAttributeFromCollection($this->projectDB, $id, 'scopes');
$this->createAttributeFromCollection($this->dbForProject, $id, 'scopes');
} catch (Throwable $th) {
Console::warning("'scopes' from {$id}: {$th->getMessage()}");
}
// Create specification attribute
try {
$this->createAttributeFromCollection($this->projectDB, $id, 'specification');
$this->createAttributeFromCollection($this->dbForProject, $id, 'specification');
} catch (Throwable $th) {
Console::warning("'specification' from {$id}: {$th->getMessage()}");
}
@ -126,21 +126,21 @@ class V21 extends Migration
case 'executions':
// Create requestMethod index
try {
$this->createIndexFromCollection($this->projectDB, $id, '_key_requestMethod');
$this->createIndexFromCollection($this->dbForProject, $id, '_key_requestMethod');
} catch (\Throwable $th) {
Console::warning("'_key_requestMethod' from {$id}: {$th->getMessage()}");
}
// Create requestPath index
try {
$this->createIndexFromCollection($this->projectDB, $id, '_key_requestPath');
$this->createIndexFromCollection($this->dbForProject, $id, '_key_requestPath');
} catch (\Throwable $th) {
Console::warning("'_key_requestPath' from {$id}: {$th->getMessage()}");
}
// Create deployment index
try {
$this->createIndexFromCollection($this->projectDB, $id, '_key_deployment');
$this->createIndexFromCollection($this->dbForProject, $id, '_key_deployment');
} catch (\Throwable $th) {
Console::warning("'_key_deployment' from {$id}: {$th->getMessage()}");
}
@ -149,7 +149,7 @@ class V21 extends Migration
/**
* Create 'scheduledAt' attribute
*/
$this->createAttributeFromCollection($this->projectDB, $id, 'scheduledAt');
$this->createAttributeFromCollection($this->dbForProject, $id, 'scheduledAt');
} catch (\Throwable $th) {
Console::warning("'scheduledAt' from {$id}: {$th->getMessage()}");
}
@ -158,7 +158,7 @@ class V21 extends Migration
/**
* Create 'scheduleInternalId' attribute
*/
$this->createAttributeFromCollection($this->projectDB, $id, 'scheduleInternalId');
$this->createAttributeFromCollection($this->dbForProject, $id, 'scheduleInternalId');
} catch (\Throwable $th) {
Console::warning("'scheduleInternalId' from {$id}: {$th->getMessage()}");
}
@ -167,7 +167,7 @@ class V21 extends Migration
/**
* Create 'scheduleId' attribute
*/
$this->createAttributeFromCollection($this->projectDB, $id, 'scheduleId');
$this->createAttributeFromCollection($this->dbForProject, $id, 'scheduleId');
} catch (\Throwable $th) {
Console::warning("'scheduleId' from {$id}: {$th->getMessage()}");
}
@ -218,8 +218,8 @@ class V21 extends Migration
$bucketId = 'bucket_' . $bucket['$internalId'];
try {
$this->projectDB->updateAttribute($bucketId, 'metadata', size: 65534);
$this->projectDB->purgeCachedCollection($bucketId);
$this->dbForProject->updateAttribute($bucketId, 'metadata', size: 65534);
$this->dbForProject->purgeCachedCollection($bucketId);
} catch (\Throwable $th) {
Console::warning("'bucketId' from {$bucketId}: {$th->getMessage()}");
}

View file

@ -50,27 +50,27 @@ class V22 extends Migration
Console::log("Migrating Collection \"{$id}\"");
$this->projectDB->setNamespace("_$internalProjectId");
$this->dbForProject->setNamespace("_$internalProjectId");
switch ($id) {
case 'installations':
// Create personalAccessToken attribute
try {
$this->createAttributeFromCollection($this->projectDB, $id, 'personalAccessToken');
$this->createAttributeFromCollection($this->dbForProject, $id, 'personalAccessToken');
} catch (Throwable $th) {
Console::warning("'personalAccessToken' from {$id}: {$th->getMessage()}");
}
// Create personalAccessTokenExpiry attribute
try {
$this->createAttributeFromCollection($this->projectDB, $id, 'personalAccessTokenExpiry');
$this->createAttributeFromCollection($this->dbForProject, $id, 'personalAccessTokenExpiry');
} catch (Throwable $th) {
Console::warning("'personalAccessTokenExpiry' from {$id}: {$th->getMessage()}");
}
// Create personalRefreshToken attribute
try {
$this->createAttributeFromCollection($this->projectDB, $id, 'personalRefreshToken');
$this->createAttributeFromCollection($this->dbForProject, $id, 'personalRefreshToken');
} catch (Throwable $th) {
Console::warning("'personalRefreshToken' from {$id}: {$th->getMessage()}");
}

View file

@ -7,6 +7,11 @@ use Exception;
use Throwable;
use Utopia\CLI\Console;
use Utopia\Database\Database;
use Utopia\Database\Document;
use Utopia\Database\Exception\Conflict;
use Utopia\Database\Exception\Structure;
use Utopia\Database\Exception\Timeout;
use Utopia\Database\Query;
class V23 extends Migration
{
@ -16,9 +21,9 @@ class V23 extends Migration
public function execute(): void
{
/**
* Disable SubQueries for Performance.
*/
foreach (['subQueryIndexes', 'subQueryPlatforms', 'subQueryDomains', 'subQueryKeys', 'subQueryWebhooks', 'subQuerySessions', 'subQueryTokens', 'subQueryMemberships', 'subQueryVariables', 'subQueryChallenges', 'subQueryProjectVariables', 'subQueryTargets', 'subQueryTopicTargets'] as $name) {
* 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,
@ -26,8 +31,14 @@ class V23 extends Migration
);
}
Console::info('Migrating Collections');
Console::info('Migrating collections');
$this->migrateCollections();
Console::info('Migrating documents');
$this->forEachDocument($this->migrateDocument(...));
Console::info('Cleaning up collections');
$this->cleanCollections();
}
/**
@ -38,8 +49,428 @@ class V23 extends Migration
*/
private function migrateCollections(): void
{
$internalProjectId = $this->project->getInternalId();
$collectionType = match ($internalProjectId) {
$projectInternalId = $this->project->getInternalId();
if (empty($projectInternalId)) {
throw new Exception('Project ID is null');
}
$collectionType = match ($projectInternalId) {
'console' => 'console',
default => 'projects',
};
$collections = $this->collections[$collectionType];
foreach ($collections as $collection) {
$id = $collection['$id'];
if (empty($id)) {
continue;
}
Console::log("Migrating collection \"{$id}\"");
switch ($id) {
case '_metadata':
$this->createCollection('sites');
$this->createCollection('resourceTokens');
if ($projectInternalId === 'console') {
$this->createCollection('devKeys');
}
break;
case 'identities':
$attributes = [
'scopes',
'expire',
];
try {
$this->createAttributesFromCollection($this->dbForProject, $id, $attributes);
} catch (\Throwable $th) {
Console::warning('Failed to create attributes "' . \implode(', ', $attributes) . "\" in collection {$id}: {$th->getMessage()}");
}
$this->dbForProject->purgeCachedCollection($id);
break;
case 'projects':
try {
$attributes = [
'devKeys',
];
$this->createAttributesFromCollection($this->dbForProject, $id, $attributes);
} catch (\Throwable $th) {
Console::warning('Failed to create attributes "' . \implode(', ', $attributes) . "\" in collection {$id}: {$th->getMessage()}");
}
$this->dbForProject->purgeCachedCollection($id);
break;
case 'rules':
$attributes = [
'type',
'trigger',
'redirectUrl',
'redirectStatusCode',
'deploymentResourceType',
'deploymentId',
'deploymentInternalId',
'deploymentResourceId',
'deploymentResourceInternalId',
'deploymentVcsProviderBranch',
'search'
];
try {
$this->createAttributesFromCollection($this->dbForProject, $id, $attributes);
} catch (\Throwable $th) {
Console::warning('Failed to create attributes "' . \implode(', ', $attributes) . "\" in collection {$id}: {$th->getMessage()}");
}
$indexes = [
'_key_search',
'_key_type',
'_key_trigger',
'_key_deploymentResourceType',
'_key_deploymentResourceId',
'_key_deploymentResourceInternalId',
'_key_deploymentId',
'_key_deploymentInternalId',
'_key_deploymentVcsProviderBranch',
];
foreach ($indexes as $index) {
try {
$this->createIndexFromCollection($this->dbForProject, $id, $index);
} catch (\Throwable $th) {
Console::warning("Failed to create index \"$index\" from {$id}: {$th->getMessage()}");
}
}
$this->dbForProject->purgeCachedCollection($id);
break;
case 'memberships':
$indexes = [
'_key_roles',
];
foreach ($indexes as $index) {
try {
$this->createIndexFromCollection($this->dbForProject, $id, $index);
} catch (Throwable $th) {
Console::warning("Failed to create index \"$index\" from {$id}: {$th->getMessage()}");
}
}
$this->dbForProject->purgeCachedCollection($id);
break;
case 'migrations':
$attributes = [
'options',
'resourceId',
'resourceType'
];
try {
$this->createAttributesFromCollection($this->dbForProject, $id, $attributes);
} catch (\Throwable $th) {
Console::warning('Failed to create attributes "' . \implode(', ', $attributes) . "\" in collection {$id}: {$th->getMessage()}");
}
$indexes = [
'_key_resource_id',
];
foreach ($indexes as $index) {
try {
$this->createIndexFromCollection($this->dbForProject, $id, $index);
} catch (Throwable $th) {
Console::warning("Failed to create index \"$index\" from {$id}: {$th->getMessage()}");
}
}
$this->dbForProject->purgeCachedCollection($id);
break;
case 'functions':
$attributes = [
'deploymentId',
'deploymentCreatedAt',
'latestDeploymentId',
'latestDeploymentInternalId',
'latestDeploymentCreatedAt',
'latestDeploymentStatus',
];
try {
$this->createAttributesFromCollection($this->dbForProject, $id, $attributes);
} catch (\Throwable $th) {
Console::warning('Failed to create attributes "' . \implode(', ', $attributes) . "\" in collection {$id}: {$th->getMessage()}");
}
$indexes = [
'_key_deploymentId',
];
foreach ($indexes as $index) {
try {
$this->createIndexFromCollection($this->dbForProject, $id, $index);
} catch (Throwable $th) {
Console::warning("Failed to create index \"$index\" from {$id}: {$th->getMessage()}");
}
}
$this->dbForProject->purgeCachedCollection($id);
break;
case 'deployments':
$attributes = [
'buildCommands',
'sourcePath',
'buildOutput',
'adapter',
'fallbackFile',
'sourceSize',
'sourceMetadata',
'sourceChunksTotal',
'sourceChunksUploaded',
'screenshotLight',
'screenshotDark',
'buildStartedAt',
'buildEndedAt',
'buildDuration',
'buildSize',
'status',
'buildPath',
'buildLogs',
'totalSize',
];
try {
$this->createAttributesFromCollection($this->dbForProject, $id, $attributes);
} catch (\Throwable $th) {
Console::warning('Failed to create attributes "' . \implode(', ', $attributes) . "\" in collection {$id}: {$th->getMessage()}");
}
$indexes = [
'_key_sourceSize',
'_key_buildSize',
'_key_totalSize',
'_key_buildDuration',
'_key_type',
'_key_status',
];
foreach ($indexes as $index) {
try {
$this->createIndexFromCollection($this->dbForProject, $id, $index);
} catch (\Throwable $th) {
Console::warning("Failed to create index \"$index\" from {$id}: {$th->getMessage()}");
}
}
$this->dbForProject->purgeCachedCollection($id);
break;
case 'executions':
$attributes = [
'resourceInternalId',
'resourceId',
'resourceType'
];
try {
$this->createAttributesFromCollection($this->dbForProject, $id, $attributes);
} catch (\Throwable $th) {
Console::warning('Failed to create attributes "' . \implode(', ', $attributes) . "\" in collection {$id}: {$th->getMessage()}");
}
$indexes = [
'_key_resource',
];
foreach ($indexes as $index) {
try {
$this->createIndexFromCollection($this->dbForProject, $id, $index);
} catch (\Throwable $th) {
Console::warning("Failed to create index \"$index\" from {$id}: {$th->getMessage()}");
}
}
$this->dbForProject->purgeCachedCollection($id);
break;
case 'variables':
$attributes = [
'secret',
];
try {
$this->createAttributesFromCollection($this->dbForProject, $id, $attributes);
} catch (\Throwable $th) {
Console::warning('Failed to create attributes "' . \implode(', ', $attributes) . "\" in collection {$id}: {$th->getMessage()}");
}
$this->dbForProject->purgeCachedCollection($id);
break;
default:
break;
}
}
}
/**
* Fix run on each document
*
* @param Document $document
* @return Document
* @throws Conflict
* @throws Structure
* @throws Timeout
* @throws \Utopia\Database\Exception
* @throws \Utopia\Database\Exception\Authorization
* @throws \Utopia\Database\Exception\Query
*/
private function migrateDocument(Document $document): Document
{
switch ($document->getCollection()) {
case 'rules':
/*
1. Convert "resourceType" to "type". Convert "function" to "deployment"
2. Convert "resourceId" to "deploymentResourceId"
3. Convert "resourceInternalId" to "deploymentResourceInternalId"
4. Fill "trigger" with "manual"
5. Fill "deploymentResourceType". If "resourceType" is "function", set "deploymentResourceType" to "function"
6. Fill "search" with "{$id} {domain}"
7. Fill "deploymentId" and "deploymentInternalId". If "deploymentResourceType" is "function", get project DB, and find function with ID "resourceId". Then fill rule's "deploymentId" with function's "deployment", and "deploymentId" as backup
*/
$deploymentResourceType = null;
$type = $document->getAttribute('resourceType', $document->getAttribute('type', ''));
if ($type === 'function') {
$type = 'deployment';
$deploymentResourceType = 'function';
}
$resourceId = $document->getAttribute('resourceId', $document->getAttribute('deploymentResourceId'));
$resourceInternalId = $document->getAttribute('resourceInternalId', $document->getAttribute('deploymentResourceInternalId'));
$document
->setAttribute('type', $type)
->setAttribute('trigger', 'manual')
->setAttribute('deploymentResourceId', $resourceId)
->setAttribute('deploymentResourceInternalId', $resourceInternalId)
->setAttribute('deploymentResourceType', $document->getAttribute('deploymentResourceType', $deploymentResourceType))
->setAttribute('search', \implode(' ', [$document->getId(), $document->getAttribute('domain', '')]));
if ($deploymentResourceType === 'function') {
$project = $this->dbForProject->getDocument('projects', $document->getAttribute('projectId'));
$dbForOwnerProject = ($this->getProjectDB)($project);
$function = $dbForOwnerProject->getDocument('functions', $resourceId);
$deploymentId = $function->getAttribute('deployment', $function->getAttribute('deploymentId', $document->getAttribute('deploymentId')));
$deploymentInternalId = $function->getAttribute('deploymentInternalId', $document->getAttribute('deploymentInternalId', ''));
$document
->setAttribute('deploymentId', $deploymentId)
->setAttribute('deploymentInternalId', $deploymentInternalId);
}
break;
case 'variables':
/*
1. Fill "secret" with "false"
*/
$document->setAttribute('secret', $document->getAttribute('secret', false));
break;
case 'executions':
/*
1. Convert "functionInternalId" to "resourceInternalId"
2. Convert "functionId" to "resourceId"
3. Fill "resourceType" with "functions"
*/
$document
->setAttribute('resourceInternalId', $document->getAttribute('functionInternalId', $document->getAttribute('resourceInternalId')))
->setAttribute('resourceId', $document->getAttribute('functionId', $document->getAttribute('resourceId', '')))
->setAttribute('resourceType', $document->getAttribute('resourceType', 'functions'));
break;
case 'functions':
/*
1. Convert "deployment" to "deploymentId"
--- Fetch activeDeployment from "deploymentId"
2. Fill "deploymentCreatedAt" with deployment's "$createdAt"
--- Fetch latestDeployment using find()
3. Fill latestDeploymentId with latestDeployment's "$id"
4. Fill latestDeploymentInternalId with latestDeployment's "$internalId"
5. Fill latestDeploymentCreatedAt with latestDeployment's "$createdAt"
6. Fill latestDeploymentStatus with latestDeployment's build's "status"
*/
if ($document->getAttribute('deployment')) {
$document->setAttribute('deploymentId', $document->getAttribute('deployment', $document->getAttribute('deploymentId', '')));
}
$deploymentId = $document->getAttribute('deploymentId');
$deployment = $this->dbForProject->getDocument('deployments', $deploymentId);
$document->setAttribute('deploymentCreatedAt', $deployment->getCreatedAt());
$latestDeployment = $this->dbForProject->findOne('deployments', [
Query::orderDesc(),
Query::equal('resourceId', [$document->getId()]),
Query::equal('resourceType', ['functions']),
]);
$latestBuild = $this->dbForProject->getDocument('builds', $latestDeployment->getAttribute('buildId', ''));
$document
->setAttribute('latestDeploymentId', $latestDeployment->getId())
->setAttribute('latestDeploymentInternalId', $latestDeployment->getInternalId())
->setAttribute('latestDeploymentCreatedAt', $latestDeployment->getCreatedAt())
->setAttribute('latestDeploymentStatus', $latestBuild->getAttribute('status', $document->getAttribute('latestDeploymentStatus', '')));
break;
case 'deployments':
/*
6. Convert "commands" to "buildCommands"
7. Convert "path" to "sourcePath"
8. Convert "size" to "sourceSize"
9. Convert "metadata" to "sourceMetadata"
10. Convert "chunksTotal" to "sourceChunksTotal"
11. Convert "chunksUploaded" to "sourceChunksUploaded"
--- Get build of deployment
12. Convert build's "startTime" to "buildStartedAt"
13. Convert build's "endTime" to "buildEndedAt"
14. Convert build's "duration" to "buildDuration"
15. Convert build's "size" to "buildSize"
16. Convert build's "status" to "status"
17. Convert build's "path" to "buildPath"
18. Convert build's "logs" to "buildLogs"
19. Fill "totalSize" with "buildSize" plus "sourceSize"
*/
$document
->setAttribute('buildCommands', $document->getAttribute('commands', $document->getAttribute('buildCommands', '')))
->setAttribute('sourcePath', $document->getAttribute('path', $document->getAttribute('sourcePath', '')))
->setAttribute('sourceSize', $document->getAttribute('size', $document->getAttribute('sourceSize', 0)))
->setAttribute('sourceMetadata', $document->getAttribute('metadata', $document->getAttribute('sourceMetadata', [])))
->setAttribute('sourceChunksTotal', $document->getAttribute('chunksTotal', $document->getAttribute('sourceChunksTotal', 0)))
->setAttribute('sourceChunksUploaded', $document->getAttribute('chunksUploaded', $document->getAttribute('sourceChunksUploaded', 0)));
$build = new Document();
if (!empty($document->getAttribute('buildId'))) {
$build = $this->dbForProject->getDocument('builds', $document->getAttribute('buildId'));
}
$document
->setAttribute('buildStartedAt', $build->getAttribute('startTime', $document->getAttribute('buildStartTime', '')))
->setAttribute('buildEndedAt', $build->getAttribute('endTime', $document->getAttribute('buildEndTime', '')))
->setAttribute('buildDuration', $build->getAttribute('duration', $document->getAttribute('buildDuration', 0)))
->setAttribute('buildSize', $build->getAttribute('size', $document->getAttribute('buildSize', 0)))
->setAttribute('status', $build->getAttribute('status', $document->getAttribute('status', '')))
->setAttribute('buildPath', $build->getAttribute('path', $document->getAttribute('buildPath', '')))
->setAttribute('buildLogs', $build->getAttribute('logs', $document->getAttribute('buildLogs', '')));
$totalSize = $document->getAttribute('buildSize', 0)
+ $document->getAttribute('sourceSize', 0);
$document->setAttribute('totalSize', $totalSize);
break;
case 'migrations':
/*
1. Fill "options" with "[]"
*/
$document->setAttribute('options', $document->getAttribute('options', []));
break;
default:
break;
}
return $document;
}
private function cleanCollections(): void
{
$projectInternalId = $this->project->getInternalId();
$collectionType = match ($projectInternalId) {
'console' => 'console',
default => 'projects',
};
@ -48,22 +479,129 @@ class V23 extends Migration
foreach ($collections as $collection) {
$id = $collection['$id'];
Console::log("Migrating Collection \"{$id}\"");
$this->projectDB->setNamespace("_$internalProjectId");
Console::log("Cleaning up collection \"{$id}\"");
switch ($id) {
case 'memberships':
// Create roles index
try {
$this->createIndexFromCollection($this->projectDB, $id, '_key_roles');
} catch (Throwable $th) {
Console::warning("'_key_roles' from {$id}: {$th->getMessage()}");
case '_metadata':
if (!$this->dbForProject->getCollection('builds')->isEmpty()) {
$this->dbForProject->deleteCollection('builds');
}
break;
}
case 'rules':
$attributes = [
'resourceId',
'resourceInternalId',
'resourceType',
];
foreach ($attributes as $attribute) {
try {
$this->dbForProject->deleteAttribute($id, $attribute);
} catch (\Throwable $th) {
Console::warning("Failed to delete attribute \"$attribute\" from collection {$id}: {$th->getMessage()}");
}
}
usleep(50000);
$indexesToDelete = [
'_key_resourceId',
'_key_resourceInternalId',
'_key_resourceType',
];
foreach ($indexesToDelete as $index) {
try {
$this->dbForProject->deleteIndex($id, $index);
} catch (\Throwable $th) {
Console::warning("Failed to delete index \"$index\" from collection {$id}: {$th->getMessage()}");
}
}
$this->dbForProject->purgeCachedCollection($id);
break;
case 'functions':
try {
$this->dbForProject->deleteAttribute($id, 'deployment');
} catch (\Throwable $th) {
Console::warning("Failed to delete attribute \"deployment\" from collection {$id}: {$th->getMessage()}");
}
$indexesToDelete = [
'_key_deployment'
];
foreach ($indexesToDelete as $index) {
try {
$this->dbForProject->deleteIndex($id, $index);
} catch (\Throwable $th) {
Console::warning("Failed to delete index \"$index\" from collection {$id}: {$th->getMessage()}");
}
}
$this->dbForProject->purgeCachedCollection($id);
break;
case 'deployments':
$attributes = [
'buildInternalId',
'buildId',
'commands',
'path',
'size',
'metadata',
'chunksTotal',
'chunksUploaded',
'search'
];
foreach ($attributes as $attribute) {
try {
$this->dbForProject->deleteAttribute($id, $attribute);
} catch (\Throwable $th) {
Console::warning("Failed to delete attribute \"$attribute\" from collection {$id}: {$th->getMessage()}");
}
}
$indexesToDelete = [
'_key_buildId',
'_key_size',
'_key_search'
];
foreach ($indexesToDelete as $index) {
try {
$this->dbForProject->deleteIndex($id, $index);
} catch (\Throwable $th) {
Console::warning("Failed to delete index \"$index\" from collection {$id}: {$th->getMessage()}");
}
}
$this->dbForProject->purgeCachedCollection($id);
break;
case 'executions':
$attributes = [
'functionId',
'functionInternalId',
'search'
];
foreach ($attributes as $attribute) {
try {
$this->dbForProject->deleteAttribute($id, $attribute);
} catch (\Throwable $th) {
Console::warning("Failed to delete attribute \"$attribute\" from collection {$id}: {$th->getMessage()}");
}
}
$indexesToDelete = [
'_key_function',
'_fulltext_search'
];
foreach ($indexesToDelete as $index) {
try {
$this->dbForProject->deleteIndex($id, $index);
} catch (\Throwable $th) {
Console::warning("Failed to delete index \"$index\" from collection {$id}: {$th->getMessage()}");
}
}
$this->dbForProject->purgeCachedCollection($id);
break;
default:
break;
}
}
}
}

View file

@ -8,11 +8,10 @@ use Utopia\App;
use Utopia\CLI\Console;
use Utopia\Database\Database;
use Utopia\Database\Document;
use Utopia\Database\Query;
use Utopia\Database\Exception;
use Utopia\Database\Validator\Authorization;
use Utopia\Platform\Action;
use Utopia\Registry\Registry;
use Utopia\System\System;
use Utopia\Validator\Text;
class Migrate extends Action
@ -28,7 +27,6 @@ class Migrate extends Action
{
$this
->desc('Migrate Appwrite to new version')
/** @TODO APP_VERSION_STABLE needs to be defined */
->param('version', APP_VERSION_STABLE, new Text(8), 'Version to migrate to.', true)
->inject('dbForPlatform')
->inject('getProjectDB')
@ -36,106 +34,68 @@ class Migrate extends Action
->callback($this->action(...));
}
private function clearProjectsCache(Document $project)
{
try {
$iterator = null;
do {
$pattern = "default-cache-_{$project->getInternalId()}:*";
$keys = $this->redis->scan($iterator, $pattern, 1000);
if ($keys !== false) {
foreach ($keys as $key) {
$this->redis->del($key);
}
}
} while ($iterator > 0);
} catch (\Throwable $th) {
Console::error('Failed to clear project ("' . $project->getId() . '") cache with error: ' . $th->getMessage());
}
}
public function action(string $version, Database $dbForPlatform, callable $getProjectDB, Registry $register)
{
/**
* @param string $version
* @param Database $dbForPlatform
* @param callable(Document): Database $getProjectDB
* @param Registry $register
* @return void
* @throws Exception
*/
public function action(
string $version,
Database $dbForPlatform,
callable $getProjectDB,
Registry $register,
): void {
Authorization::disable();
if (!array_key_exists($version, Migration::$versions)) {
if (!\array_key_exists($version, Migration::$versions)) {
Console::error("Version {$version} not found.");
Console::exit(1);
return;
}
$this->redis = new Redis();
$this->redis->connect(
System::getEnv('_APP_REDIS_HOST', null),
System::getEnv('_APP_REDIS_PORT', 6379),
3,
null,
10
);
$app = new App('UTC');
Console::success('Starting Data Migration to version ' . $version);
$console = $app->getResource('console');
$limit = 30;
$sum = 30;
$offset = 0;
/**
* @var \Utopia\Database\Document[] $projects
*/
$projects = [$console];
$count = 0;
try {
$totalProjects = $dbForPlatform->count('projects') + 1;
} catch (\Throwable $th) {
$dbForPlatform->setNamespace('_console');
$totalProjects = $dbForPlatform->count('projects') + 1;
}
$class = 'Appwrite\\Migration\\Version\\' . Migration::$versions[$version];
/** @var Migration $migration */
$migration = new $class();
while (!empty($projects)) {
foreach ($projects as $project) {
/**
* Skip user projects with id 'console'
*/
if ($project->getId() === 'console' && $project->getInternalId() !== 'console') {
continue;
}
$count = 0;
$total = $dbForPlatform->count('projects') + 1;
$this->clearProjectsCache($project);
$dbForPlatform->foreach('projects', function (Document $project) use ($dbForPlatform, $getProjectDB, $register, $migration, &$count, $total) {
/** @var Database $dbForProject */
$dbForProject = $getProjectDB($project);
$dbForProject->disableValidation();
try {
// TODO: Iterate through all project DBs
/** @var Database $projectDB */
$projectDB = $getProjectDB($project);
$projectDB->disableValidation();
$migration
->setProject($project, $projectDB, $dbForPlatform)
->setPDO($register->get('db', true))
->execute();
} catch (\Throwable $th) {
Console::error('Failed to update project ("' . $project->getId() . '") version with error: ' . $th->getMessage());
throw $th;
}
$this->clearProjectsCache($project);
try {
$migration
->setProject($project, $dbForProject, $dbForPlatform, $getProjectDB)
->setPDO($register->get('db', true))
->execute();
} catch (\Throwable $th) {
Console::error('Failed to migrate project "' . $project->getId() . '" with error: ' . $th->getMessage());
throw $th;
}
$sum = \count($projects);
$projects = $dbForPlatform->find('projects', [Query::limit($limit), Query::offset($offset)]);
Console::log('Migrated ' . ++$count . '/' . $total . ' projects...');
});
$offset = $offset + $limit;
$count = $count + $sum;
$console = (new App('UTC'))->getResource('console');
Console::log('Migrated ' . $count . '/' . $totalProjects . ' projects...');
try {
$migration
->setProject($console, $getProjectDB($console), $dbForPlatform, $getProjectDB)
->setPDO($register->get('db', true))
->execute();
} catch (\Throwable $th) {
Console::error('Failed to migrate project "console" with error: ' . $th->getMessage());
throw $th;
}
Console::success('Data Migration Completed');
Console::success('Migration completed');
}
}

View file

@ -1,12 +1,11 @@
<?php
namespace Tests\E2E\Services\Projects;
namespace Tests\E2E\Services\Sites;
use Tests\E2E\Client;
use Tests\E2E\Scopes\ProjectCustom;
use Tests\E2E\Scopes\Scope;
use Tests\E2E\Scopes\SideConsole;
use Tests\E2E\Services\Sites\SitesBase;
use Utopia\Database\Helpers\ID;
class SitesConsoleClientTest extends Scope