1
0
Fork 0
mirror of synced 2024-06-03 03:14:50 +12:00
This commit is contained in:
Torsten Dittmann 2022-09-09 19:50:05 +02:00
parent 4822e326f2
commit 21d40f4849
2 changed files with 31 additions and 1 deletions

View file

@ -45,6 +45,9 @@ $cli
$limit = 30;
$sum = 30;
$offset = 0;
/**
* @var \Utopia\Database\Document[] $projects
*/
$projects = [$console];
$count = 0;
@ -60,6 +63,13 @@ $cli
while (!empty($projects)) {
foreach ($projects as $project) {
/**
* Skip user projects with id 'console'
*/
if ($project->getId() === 'console' && $project->getInternalId() !== 'console') {
continue;
}
try {
$migration
->setProject($project, $projectDB, $consoleDB)

View file

@ -28,7 +28,7 @@ class V15 extends Migration
/**
* Disable SubQueries for Performance.
*/
foreach (['subQueryAttributes', 'subQueryIndexes', 'subQueryPlatforms', 'subQueryDomains', 'subQueryKeys', 'subQueryWebhooks', 'subQuerySessions', 'subQueryTokens', 'subQueryMemberships', 'subqueryVariables'] as $name) {
foreach (['subQueryIndexes', 'subQueryPlatforms', 'subQueryDomains', 'subQueryKeys', 'subQueryWebhooks', 'subQuerySessions', 'subQueryTokens', 'subQueryMemberships', 'subqueryVariables'] as $name) {
Database::addFilter(
$name,
fn () => null,
@ -151,12 +151,32 @@ class V15 extends Migration
$this->projectDB->updateDocument($databaseTable, $collection->getId(), $collection);
Console::info("Migrating Documents of {$collection->getId()} ({$collection->getAttribute('name')})");
$requiredAttributes = array_reduce($collection->getAttribute('attributes', []), function (array $carry, Document $item) {
if ($item->getAttribute('required', false)) {
$carry = array_merge($carry, [
$item->getAttribute('key') => $item->getAttribute('default')
]);
}
return $carry;
}, []);
foreach ($this->documentsIterator($collectionTable) as $document) {
foreach ($document->getAttributes() as $attribute => $default) {
if (array_key_exists($attribute, $requiredAttributes)) {
if (is_null($default)) {
Console::warning("Skipping migration for Document {$document->getId()} in Collection {$collection->getId()} ({$collection->getAttribute('name')}) because of missing required attribute \"{$attribute}\" without default value.");
continue 2;
}
$document->setAttribute($attribute, $default);
}
}
$this->populatePermissionsAttribute(
document: $document,
table: $collectionTable,
addCreatePermission: false
);
$this->projectDB->updateDocument($collectionTable, $document->getId(), $document);
}
$this->removeWritePermissions($collectionTable);