Merge pull request #12807 from appwrite/db-status-attribute

Db status attribute
This commit is contained in:
ArnabChatterjee20k authored and GitHub committed 2026-07-09 13:49:43 +05:30
commit cd34d90066
7 files changed
+112 -9

No files matched your search

+11
View File
@@ -69,6 +69,17 @@ return [
'signed' => true,
'array' => false,
'filters' => [],
],
[
'$id' => ID::custom('status'),
'type' => Database::VAR_STRING,
'format' => '',
'size' => 16,
'signed' => true,
'required' => false,
'default' => null,
'array' => false,
'filters' => [],
]
],
'indexes' => [
+1 -1
View File
@@ -83,7 +83,7 @@
"utopia-php/lock": "0.2.*",
"utopia-php/logger": "0.8.*",
"utopia-php/messaging": "^1.2",
"utopia-php/migration": "1.14.*",
"utopia-php/migration": "1.16.*",
"utopia-php/platform": "^1.0@RC",
"utopia-php/pools": "1.*",
"utopia-php/span": "3.0.*",
Generated
+7 -7
View File
@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "9fb1fb88559be6ad0be7d51248fd86dd",
"content-hash": "50b6e587a70f02a5896790012248f50f",
"packages": [
{
"name": "adhocore/jwt",
@@ -4409,16 +4409,16 @@
},
{
"name": "utopia-php/migration",
"version": "1.14.1",
"version": "1.16.0",
"source": {
"type": "git",
"url": "https://github.com/utopia-php/migration.git",
"reference": "926556113c770b3646cabeb042153969e3e0cadf"
"reference": "3bb4428e4fb7a29f120f73f87d0a2519a2a414a4"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/utopia-php/migration/zipball/926556113c770b3646cabeb042153969e3e0cadf",
"reference": "926556113c770b3646cabeb042153969e3e0cadf",
"url": "https://api.github.com/repos/utopia-php/migration/zipball/3bb4428e4fb7a29f120f73f87d0a2519a2a414a4",
"reference": "3bb4428e4fb7a29f120f73f87d0a2519a2a414a4",
"shasum": ""
},
"require": {
@@ -4458,9 +4458,9 @@
],
"support": {
"issues": "https://github.com/utopia-php/migration/issues",
"source": "https://github.com/utopia-php/migration/tree/1.14.1"
"source": "https://github.com/utopia-php/migration/tree/1.16.0"
},
"time": "2026-06-30T13:18:56+00:00"
"time": "2026-07-09T05:46:44+00:00"
},
{
"name": "utopia-php/mongo",
+28
View File
@@ -7,6 +7,8 @@ use Exception;
use Throwable;
use Utopia\Console;
use Utopia\Database\Database;
use Utopia\Database\Document;
use Utopia\Database\Query;
class V25 extends Migration
{
@@ -63,6 +65,32 @@ class V25 extends Migration
}
$this->dbForProject->purgeCachedCollection($id);
break;
case 'databases':
if ($collectionType === 'projects') {
try {
$this->createAttributeFromCollection($this->dbForProject, $id, 'status');
} catch (Throwable $th) {
Console::warning("Failed to create attribute \"status\" in collection {$id}: {$th->getMessage()}");
}
$this->dbForProject->purgeCachedCollection($id);
// Backfill existing databases so the stored value matches the intended default.
// Materialize the matched documents before updating any of them: updating
// "status" removes rows from the isNull() set, and the offset-based iterator
// would otherwise skip un-processed rows as the filtered set shrinks mid-scan.
$databases = \iterator_to_array($this->documentsIterator($id, [Query::isNull('status')]));
foreach ($databases as $database) {
try {
$this->dbForProject->updateDocument($id, $database->getId(), new Document([
'status' => 'ready',
]));
} catch (Throwable $th) {
Console::warning("Failed to backfill \"status\" for database {$database->getId()}: {$th->getMessage()}");
}
}
}
break;
}
}
}
@@ -190,7 +190,8 @@ class Create extends Action
'enabled' => $enabled,
'search' => implode(' ', [$databaseId, $name]),
'type' => $this->getDatabaseType(),
'database' => $this->getDatabaseDSN($project)
'database' => $this->getDatabaseDSN($project),
'status' => 'ready',
]));
} catch (DuplicateException) {
throw new Exception(Exception::DATABASE_ALREADY_EXISTS, params: [$databaseId]);
@@ -4,6 +4,7 @@ namespace Appwrite\Utopia\Response\Model;
use Appwrite\Utopia\Response;
use Appwrite\Utopia\Response\Model;
use Utopia\Database\Document;
class Database extends Model
{
@@ -46,9 +47,32 @@ class Database extends Model
'default' => 'legacy',
'example' => 'legacy',
'enum' => ['legacy', 'tablesdb', 'documentsdb', 'vectorsdb'],
])
->addRule('status', [
'type' => self::TYPE_ENUM,
'description' => 'Database status. Possible values: `provisioning`, `ready` or `failed`',
'default' => 'ready',
'example' => 'ready',
'enum' => ['provisioning', 'ready', 'failed'],
'enumSDKName' => 'DatabaseStatus',
]);
}
/**
* A null status is treated as ready.
*
* @param Document $document
* @return Document
*/
public function filter(Document $document): Document
{
if (empty($document->getAttribute('status'))) {
$document->setAttribute('status', 'ready');
}
return $document;
}
/**
* Get Name
*
@@ -776,6 +776,45 @@ trait DatabasesBase
$this->assertEquals($this->getDatabaseType(), $database['body']['type']);
}
public function testDatabaseStatus(): void
{
if ($this->getSide() === 'client') {
// Databases are created and read with a server API key.
$this->expectNotToPerformAssertions();
return;
}
$headers = [
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
'x-appwrite-key' => $this->getProject()['apiKey'],
];
/**
* Test for SUCCESS
* A newly created database defaults to the "ready" status.
*/
$database = $this->client->call(Client::METHOD_POST, $this->getApiBasePath(), $headers, [
'databaseId' => ID::unique(),
'name' => 'Status Database',
]);
$this->assertEquals(201, $database['headers']['status-code']);
$this->assertArrayHasKey('status', $database['body']);
$this->assertEquals('ready', $database['body']['status']);
$databaseId = $database['body']['$id'];
/**
* The status is persisted and returned on read.
*/
$response = $this->client->call(Client::METHOD_GET, $this->getApiBasePath() . '/' . $databaseId, $headers);
$this->assertEquals(200, $response['headers']['status-code']);
$this->assertArrayHasKey('status', $response['body']);
$this->assertEquals('ready', $response['body']['status']);
}
public function testCreateCollection(): void
{
$data = $this->setupDatabase();