1
0
Fork 0
mirror of synced 2024-10-03 19:53:33 +13:00

fix: migration for 1.5.x

This commit is contained in:
Torsten Dittmann 2024-03-05 16:22:02 +01:00
parent 3d059e470a
commit 740a6a1e2d

View file

@ -93,13 +93,13 @@ class V20 extends Migration
]) as $index
) {
if (in_array($attribute->getAttribute('key'), $index->getAttribute('attributes'))) {
try {
$this->projectDB->deleteIndex($collectionId, $index->getId());
} catch (Throwable $th) {
Console::warning("Failed to delete index: {$th->getMessage()}");
} finally {
$foundIndex = true;
}
try {
$this->projectDB->deleteIndex($collectionId, $index->getId());
} catch (Throwable $th) {
Console::warning("Failed to delete index: {$th->getMessage()}");
} finally {
$foundIndex = true;
}
}
}
if ($foundIndex === true) {
@ -142,24 +142,6 @@ class V20 extends Migration
$this->createCollection('challenges');
$this->createCollection('authenticators');
break;
case 'cache':
// Create resourceType attribute
try {
$this->createAttributeFromCollection($this->projectDB, $id, 'resourceType');
$this->projectDB->purgeCachedCollection($id);
} catch (Throwable $th) {
Console::warning("'resourceType' from {$id}: {$th->getMessage()}");
}
// Create mimeType attribute
try {
$this->createAttributeFromCollection($this->projectDB, $id, 'mimeType');
$this->projectDB->purgeCachedCollection($id);
} catch (Throwable $th) {
Console::warning("'mimeType' from {$id}: {$th->getMessage()}");
}
break;
case 'stats':
try {
@ -171,11 +153,16 @@ class V20 extends Migration
* Alter `signed` internal type on `value` attr
*/
$this->projectDB->updateAttribute(collection: $id, id: 'value', signed: true);
$this->projectDB->purgeCachedCollection($id);
} catch (Throwable $th) {
Console::warning("'type' from {$id}: {$th->getMessage()}");
}
try {
$this->projectDB->purgeCachedCollection($id);
} catch (Throwable $th) {
Console::warning("Purge cache from {$id}: {$th->getMessage()}");
}
// update stats index
$index = '_key_metric_period_time';
@ -196,7 +183,6 @@ class V20 extends Migration
// Create expire attribute
try {
$this->createAttributeFromCollection($this->projectDB, $id, 'expire');
$this->projectDB->purgeCachedCollection($id);
} catch (Throwable $th) {
Console::warning("'expire' from {$id}: {$th->getMessage()}");
}
@ -204,17 +190,28 @@ class V20 extends Migration
// Create factors attribute
try {
$this->createAttributeFromCollection($this->projectDB, $id, 'factors');
$this->projectDB->purgeCachedCollection($id);
} catch (Throwable $th) {
Console::warning("'factors' from {$id}: {$th->getMessage()}");
}
// Create mfaRecoveryCodes attribute
try {
$this->createAttributeFromCollection($this->projectDB, $id, 'mfaUpdatedAt');
} catch (Throwable $th) {
Console::warning("'mfaUpdatedAt' from {$id}: {$th->getMessage()}");
}
try {
$this->projectDB->purgeCachedCollection($id);
} catch (Throwable $th) {
Console::warning("Purge cache from {$id}: {$th->getMessage()}");
}
break;
case 'users':
// Create targets attribute
try {
$this->createAttributeFromCollection($this->projectDB, $id, 'targets');
$this->projectDB->purgeCachedCollection($id);
} catch (Throwable $th) {
Console::warning("'targets' from {$id}: {$th->getMessage()}");
}
@ -222,7 +219,6 @@ class V20 extends Migration
// Create mfa attribute
try {
$this->createAttributeFromCollection($this->projectDB, $id, 'mfa');
$this->projectDB->purgeCachedCollection($id);
} catch (Throwable $th) {
Console::warning("'mfa' from {$id}: {$th->getMessage()}");
}
@ -230,23 +226,13 @@ class V20 extends Migration
// Create mfaRecoveryCodes attribute
try {
$this->createAttributeFromCollection($this->projectDB, $id, 'mfaRecoveryCodes');
$this->projectDB->purgeCachedCollection($id);
} catch (Throwable $th) {
Console::warning("'mfa' from {$id}: {$th->getMessage()}");
}
// Create mfaRecoveryCodes attribute
try {
$this->createAttributeFromCollection($this->projectDB, $id, 'mfaUpdatedAt');
$this->projectDB->purgeCachedCollection($id);
} catch (Throwable $th) {
Console::warning("'mfa' from {$id}: {$th->getMessage()}");
Console::warning("'mfaRecoveryCodes' from {$id}: {$th->getMessage()}");
}
// Create challenges attribute
try {
$this->createAttributeFromCollection($this->projectDB, $id, 'challenges');
$this->projectDB->purgeCachedCollection($id);
} catch (Throwable $th) {
Console::warning("'challenges' from {$id}: {$th->getMessage()}");
}
@ -254,30 +240,60 @@ class V20 extends Migration
// Create authenticators attribute
try {
$this->createAttributeFromCollection($this->projectDB, $id, 'authenticators');
$this->projectDB->purgeCachedCollection($id);
} catch (Throwable $th) {
Console::warning("'authenticators' from {$id}: {$th->getMessage()}");
}
try {
$this->projectDB->purgeCachedCollection($id);
} catch (Throwable $th) {
Console::warning("Purge cache from {$id}: {$th->getMessage()}");
}
break;
case 'projects':
// Rename providers authProviders to oAuthProviders
try {
$this->projectDB->renameAttribute($id, 'authProviders', 'oAuthProviders');
$this->projectDB->purgeCachedCollection($id);
} catch (Throwable $th) {
Console::warning("'oAuthProviders' from {$id}: {$th->getMessage()}");
}
break;
case 'webhooks':
try {
$this->createAttributeFromCollection($this->projectDB, $id, 'enabled');
$this->createAttributeFromCollection($this->projectDB, $id, 'logs');
$this->createAttributeFromCollection($this->projectDB, $id, 'attempts');
$this->projectDB->purgeCachedCollection($id);
} catch (Throwable $th) {
Console::warning("'webhooks' from {$id}: {$th->getMessage()}");
Console::warning("Purge cache from {$id}: {$th->getMessage()}");
}
break;
case 'webhooks':
// Create enabled attribute
try {
$this->createAttributeFromCollection($this->projectDB, $id, 'enabled');
} catch (Throwable $th) {
Console::warning("'enabled' from {$id}: {$th->getMessage()}");
}
// Create logs attribute
try {
$this->createAttributeFromCollection($this->projectDB, $id, 'logs');
} catch (Throwable $th) {
Console::warning("'logs' from {$id}: {$th->getMessage()}");
}
// Create attempts attribute
try {
$this->createAttributeFromCollection($this->projectDB, $id, 'attempts');
} catch (Throwable $th) {
Console::warning("'attempts' from {$id}: {$th->getMessage()}");
}
try {
$this->projectDB->purgeCachedCollection($id);
} catch (Throwable $th) {
Console::warning("Purge cache from {$id}: {$th->getMessage()}");
}
break;
}
@ -285,8 +301,6 @@ class V20 extends Migration
}
}
/**
* @return void
* @throws Authorization
@ -336,7 +350,7 @@ class V20 extends Migration
/**
* Creating inf metric
*/
console::log("Creating inf metric to {$metric}");
Console::log("Creating inf metric to {$metric}");
$id = \md5("_inf_{$metric}");
$this->projectDB->createDocument('stats', new Document([
'$id' => $id,
@ -347,7 +361,7 @@ class V20 extends Migration
'region' => 'default',
]));
} catch (Duplicate $th) {
console::log("Error while creating inf metric: duplicate id {$metric} {$id}");
Console::warning("Error while creating inf metric: duplicate id {$metric} {$id}");
}
}
@ -401,7 +415,7 @@ class V20 extends Migration
$stat->setAttribute('$id', \md5("{$time}_{$stat['period']}_{$to}"));
$stat->setAttribute('metric', $to);
$this->projectDB->createDocument('stats', $stat);
console::log("deleting metric {$from} and creating {$to}");
Console::log("deleting metric {$from} and creating {$to}");
}
$latestDocument = !empty(array_key_last($stats)) ? $stats[array_key_last($stats)] : null;
}