From f3d7e7dcfda8e8300b629854122d97d40b4e6577 Mon Sep 17 00:00:00 2001 From: ArnabChatterjee20k Date: Tue, 7 Jul 2026 15:36:28 +0530 Subject: [PATCH 1/7] updated database collection schema --- app/config/collections/projects.php | 11 +++++++++++ src/Appwrite/Migration/Version/V25.php | 11 +++++++++++ 2 files changed, 22 insertions(+) diff --git a/app/config/collections/projects.php b/app/config/collections/projects.php index 157422f29e..12f1534377 100644 --- a/app/config/collections/projects.php +++ b/app/config/collections/projects.php @@ -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' => [ diff --git a/src/Appwrite/Migration/Version/V25.php b/src/Appwrite/Migration/Version/V25.php index 800b9b451f..581cace46b 100644 --- a/src/Appwrite/Migration/Version/V25.php +++ b/src/Appwrite/Migration/Version/V25.php @@ -63,6 +63,17 @@ 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); + } + break; } } } From 1daf39c737e12855eea911b5ba6d33e0517f6d03 Mon Sep 17 00:00:00 2001 From: ArnabChatterjee20k Date: Tue, 7 Jul 2026 15:36:50 +0530 Subject: [PATCH 2/7] updated response model and route --- .../Databases/Http/Databases/Create.php | 3 ++- .../Utopia/Response/Model/Database.php | 24 +++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Create.php index 09b1c274ec..51bef56c47 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Create.php @@ -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]); diff --git a/src/Appwrite/Utopia/Response/Model/Database.php b/src/Appwrite/Utopia/Response/Model/Database.php index df9ad2e1f5..2cbf4ace63 100644 --- a/src/Appwrite/Utopia/Response/Model/Database.php +++ b/src/Appwrite/Utopia/Response/Model/Database.php @@ -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 * From 8d1c57d0e73170fc725ab42c5b599d9e3c26e58f Mon Sep 17 00:00:00 2001 From: ArnabChatterjee20k Date: Tue, 7 Jul 2026 15:36:56 +0530 Subject: [PATCH 3/7] added tests --- .../e2e/Services/Databases/DatabasesBase.php | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/tests/e2e/Services/Databases/DatabasesBase.php b/tests/e2e/Services/Databases/DatabasesBase.php index e3efe3bbd9..4beed77479 100644 --- a/tests/e2e/Services/Databases/DatabasesBase.php +++ b/tests/e2e/Services/Databases/DatabasesBase.php @@ -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(); From a2e6106804462946cff078913a9f1bd6c443ffee Mon Sep 17 00:00:00 2001 From: ArnabChatterjee20k Date: Tue, 7 Jul 2026 20:00:10 +0530 Subject: [PATCH 4/7] added backfiling --- src/Appwrite/Migration/Version/V25.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/Appwrite/Migration/Version/V25.php b/src/Appwrite/Migration/Version/V25.php index 581cace46b..f59f4e3542 100644 --- a/src/Appwrite/Migration/Version/V25.php +++ b/src/Appwrite/Migration/Version/V25.php @@ -7,6 +7,7 @@ use Exception; use Throwable; use Utopia\Console; use Utopia\Database\Database; +use Utopia\Database\Query; class V25 extends Migration { @@ -72,6 +73,15 @@ class V25 extends Migration 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. + foreach ($this->documentsIterator($id, [Query::isNull('status')]) as $database) { + try { + $this->dbForProject->updateDocument($id, $database->getId(), $database->setAttribute('status', 'ready')); + } catch (Throwable $th) { + Console::warning("Failed to backfill \"status\" for database {$database->getId()}: {$th->getMessage()}"); + } + } } break; } From 272dc4816f00fd5ce54bab312041ee7c658148b2 Mon Sep 17 00:00:00 2001 From: ArnabChatterjee20k Date: Thu, 9 Jul 2026 11:35:15 +0530 Subject: [PATCH 5/7] updated --- src/Appwrite/Migration/Version/V25.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/Appwrite/Migration/Version/V25.php b/src/Appwrite/Migration/Version/V25.php index f59f4e3542..06127a3229 100644 --- a/src/Appwrite/Migration/Version/V25.php +++ b/src/Appwrite/Migration/Version/V25.php @@ -75,9 +75,15 @@ class V25 extends Migration $this->dbForProject->purgeCachedCollection($id); // Backfill existing databases so the stored value matches the intended default. - foreach ($this->documentsIterator($id, [Query::isNull('status')]) as $database) { + // 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(), $database->setAttribute('status', 'ready')); + $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()}"); } From 251dd4d4c77c6495204a831b4efe7cafcba07cb6 Mon Sep 17 00:00:00 2001 From: ArnabChatterjee20k Date: Thu, 9 Jul 2026 11:48:09 +0530 Subject: [PATCH 6/7] updated --- src/Appwrite/Migration/Version/V25.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Appwrite/Migration/Version/V25.php b/src/Appwrite/Migration/Version/V25.php index 06127a3229..3a997c865d 100644 --- a/src/Appwrite/Migration/Version/V25.php +++ b/src/Appwrite/Migration/Version/V25.php @@ -7,6 +7,7 @@ use Exception; use Throwable; use Utopia\Console; use Utopia\Database\Database; +use Utopia\Database\Document; use Utopia\Database\Query; class V25 extends Migration From d56bf294f69ea875a409260c600db101ebea7e3f Mon Sep 17 00:00:00 2001 From: ArnabChatterjee20k Date: Thu, 9 Jul 2026 11:53:07 +0530 Subject: [PATCH 7/7] updated migration --- composer.json | 2 +- composer.lock | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/composer.json b/composer.json index 66498d9f5d..0439d13034 100644 --- a/composer.json +++ b/composer.json @@ -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.*", diff --git a/composer.lock b/composer.lock index 7e4b64cfab..d337d7e4ea 100644 --- a/composer.lock +++ b/composer.lock @@ -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",