Use db loop methods, update names

This commit is contained in:
Jake Barnby 2025-05-16 17:24:11 +12:00
parent 56fda6a34b
commit 7344733165
No known key found for this signature in database
GPG key ID: C437A8CC85B96E9C
9 changed files with 410 additions and 405 deletions

View file

@ -7,6 +7,11 @@ 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\Exception\Timeout;
use Utopia\Database\Helpers\ID;
use Utopia\Database\PDO;
use Utopia\Database\Query;
@ -15,33 +20,18 @@ use Utopia\System\System;
abstract class Migration
{
/**
* @var int
*/
protected int $limit = 100;
/**
* @var Document
*/
protected Document $project;
/**
* @var Database
*/
protected Database $projectDB;
protected Database $dbForProject;
/**
* @var Database
*/
protected Database $consoleDB;
protected Database $dbForPlatform;
/**
* @var PDO
*/
protected PDO $pdo;
/**
* @var array
* @var array<string, string>
*/
public static array $versions = [
'1.0.0-RC1' => 'V15',
@ -95,7 +85,7 @@ abstract class Migration
];
/**
* @var array
* @var array<string, array<string, mixed>>
*/
protected array $collections;
@ -106,34 +96,34 @@ abstract class Migration
$this->collections = Config::getParam('collections', []);
$projectCollections = $this->collections['projects'];
$this->collections['projects'] = array_merge([
$this->collections['projects'][] = [
'_metadata' => [
'$id' => ID::custom('_metadata'),
'$collection' => Database::METADATA
],
]
];
$this->collections['projects'][] = [
'audit' => [
'$id' => ID::custom('audit'),
'$collection' => Database::METADATA
],
], $projectCollections);
];
}
/**
* 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): self
{
$this->project = $project;
$this->projectDB = $projectDB;
$this->consoleDB = $consoleDB;
$this->dbForProject = $dbForProject;
$this->dbForPlatform = $dbForPlatform;
return $this;
}
@ -142,7 +132,7 @@ abstract class Migration
* Set PDO for Migration.
*
* @param PDO $pdo
* @return \Appwrite\Migration\Migration
* @return Migration
*/
public function setPDO(PDO $pdo): self
{
@ -155,87 +145,51 @@ 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 collection ' . $collection['$id'] . '...');
foreach ($this->documentsIterator($collection['$id']) as $document) {
$this->dbForProject->foreach($collection['$id'], function(Document $document) use ($collection, $callback) {
if (empty($document->getId()) || empty($document->getCollection())) {
continue;
return;
}
$old = $document->getArrayCopy();
$new = call_user_func($callback, $document);
$new = $callback($document);
if (is_null($new) || $new->getArrayCopy() == $old) {
continue;
if ($new === null || $new->getArrayCopy() == $old) {
return;
}
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());
continue;
Console::error("Failed to update document \"{$document->getId()}\" in collection \"{$collection['$id']}\":" . $th->getMessage());
return;
}
}
});
}
}
/**
* 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);
}
}
$documents = $this->projectDB->find($collectionId, $queries);
$count = count($documents);
$sum += $count;
Console::log($sum . ' / ' . $collectionCount);
foreach ($documents as $document) {
yield $document;
}
if ($count !== $this->limit) {
$nextDocument = null;
} else {
$nextDocument = end($documents);
}
} while (!is_null($nextDocument));
}
/**
* Creates collection from the config collection.
*
@ -253,54 +207,42 @@ abstract class Migration
default => 'projects',
};
if (!$this->projectDB->exists(System::getEnv('_APP_DB_SCHEMA', 'appwrite'), $name)) {
if (!$this->dbForProject->getCollection($id)->isEmpty()) {
$attributes = [];
$indexes = [];
$collection = $this->collections[$collectionType][$id];
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'],
]);
$attributes[] = new Document($attribute);
}
foreach ($collection['indexes'] as $index) {
$indexes[] = new Document([
'$id' => $index['$id'],
'type' => $index['type'],
'attributes' => $index['attributes'],
'lengths' => $index['lengths'],
'orders' => $index['orders'],
]);
$indexes[] = new Document($index);
}
try {
$this->projectDB->createCollection($name, $attributes, $indexes);
} catch (\Throwable $th) {
throw $th;
}
$this->dbForProject->createCollection($name, $attributes, $indexes);
}
}
/**
* 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;
@ -315,13 +257,75 @@ abstract class Migration
$collection = $this->collections[$collectionType][$from] ?? null;
if (is_null($collection)) {
if ($collection === null) {
throw new Exception("Collection {$from} not found");
}
$attributes = [];
foreach ($attributeIds as $attributeId) {
$attribute = $collection['attributes'][$attributeId] ?? null;
if ($attribute === null) {
throw new Exception("Attribute {$attributeId} not found");
}
$attribute['filters'] ??= [];
$attribute['default'] ??= null;
$attribute['default'] = \in_array('json', $attribute['filters'])
? \json_encode($attribute['default'])
: $attribute['default'];
$attributes[] = $attribute;
}
$database->createAttributes(
collection: $collectionId,
attributes: $attributes,
);
}
/**
* 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");
@ -336,9 +340,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'] ?? [],
@ -349,14 +353,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
{
@ -369,13 +373,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");
@ -400,10 +404,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()}");
}