From 67e2104e9815addf75604e9859f6fb508890ad8a Mon Sep 17 00:00:00 2001 From: Chirag Aggarwal Date: Fri, 23 Jan 2026 19:40:36 +0530 Subject: [PATCH] chore: make name update optional in databases and tables --- app/config/specs/open-api3-1.8.x-console.json | 23 ++++--------------- app/config/specs/open-api3-1.8.x-server.json | 23 ++++--------------- .../specs/open-api3-latest-console.json | 23 ++++--------------- app/config/specs/open-api3-latest-server.json | 23 ++++--------------- app/config/specs/swagger2-1.8.x-console.json | 23 ++++--------------- app/config/specs/swagger2-1.8.x-server.json | 23 ++++--------------- app/config/specs/swagger2-latest-console.json | 23 ++++--------------- app/config/specs/swagger2-latest-server.json | 23 ++++--------------- .../Http/Databases/Collections/Update.php | 13 +++++++---- .../Databases/Http/Databases/Update.php | 13 +++++++---- .../Databases/Http/TablesDB/Tables/Update.php | 2 +- .../Databases/Http/TablesDB/Update.php | 2 +- 12 files changed, 60 insertions(+), 154 deletions(-) diff --git a/app/config/specs/open-api3-1.8.x-console.json b/app/config/specs/open-api3-1.8.x-console.json index 02d537fa75..d83d7c20ba 100644 --- a/app/config/specs/open-api3-1.8.x-console.json +++ b/app/config/specs/open-api3-1.8.x-console.json @@ -6957,8 +6957,7 @@ "enabled" ], "required": [ - "databaseId", - "name" + "databaseId" ], "responses": [ { @@ -7013,10 +7012,7 @@ "description": "Is database enabled? When set to 'disabled', users cannot access the database but Server SDKs with an API key can still read and write to the database. No data is lost when this is toggled.", "x-example": false } - }, - "required": [ - "name" - ] + } } } } @@ -7516,10 +7512,7 @@ "description": "Is collection enabled? When set to 'disabled', users cannot access the collection but Server SDKs with and API key can still read and write to the collection. No data is lost when this is toggled.", "x-example": false } - }, - "required": [ - "name" - ] + } } } } @@ -37112,10 +37105,7 @@ "description": "Is database enabled? When set to 'disabled', users cannot access the database but Server SDKs with an API key can still read and write to the database. No data is lost when this is toggled.", "x-example": false } - }, - "required": [ - "name" - ] + } } } } @@ -37579,10 +37569,7 @@ "description": "Is table enabled? When set to 'disabled', users cannot access the table but Server SDKs with and API key can still read and write to the table. No data is lost when this is toggled.", "x-example": false } - }, - "required": [ - "name" - ] + } } } } diff --git a/app/config/specs/open-api3-1.8.x-server.json b/app/config/specs/open-api3-1.8.x-server.json index 35bbbbb952..6b4e836a43 100644 --- a/app/config/specs/open-api3-1.8.x-server.json +++ b/app/config/specs/open-api3-1.8.x-server.json @@ -6427,8 +6427,7 @@ "enabled" ], "required": [ - "databaseId", - "name" + "databaseId" ], "responses": [ { @@ -6484,10 +6483,7 @@ "description": "Is database enabled? When set to 'disabled', users cannot access the database but Server SDKs with an API key can still read and write to the database. No data is lost when this is toggled.", "x-example": false } - }, - "required": [ - "name" - ] + } } } } @@ -6993,10 +6989,7 @@ "description": "Is collection enabled? When set to 'disabled', users cannot access the collection but Server SDKs with and API key can still read and write to the collection. No data is lost when this is toggled.", "x-example": false } - }, - "required": [ - "name" - ] + } } } } @@ -26760,10 +26753,7 @@ "description": "Is database enabled? When set to 'disabled', users cannot access the database but Server SDKs with an API key can still read and write to the database. No data is lost when this is toggled.", "x-example": false } - }, - "required": [ - "name" - ] + } } } } @@ -27232,10 +27222,7 @@ "description": "Is table enabled? When set to 'disabled', users cannot access the table but Server SDKs with and API key can still read and write to the table. No data is lost when this is toggled.", "x-example": false } - }, - "required": [ - "name" - ] + } } } } diff --git a/app/config/specs/open-api3-latest-console.json b/app/config/specs/open-api3-latest-console.json index 02d537fa75..d83d7c20ba 100644 --- a/app/config/specs/open-api3-latest-console.json +++ b/app/config/specs/open-api3-latest-console.json @@ -6957,8 +6957,7 @@ "enabled" ], "required": [ - "databaseId", - "name" + "databaseId" ], "responses": [ { @@ -7013,10 +7012,7 @@ "description": "Is database enabled? When set to 'disabled', users cannot access the database but Server SDKs with an API key can still read and write to the database. No data is lost when this is toggled.", "x-example": false } - }, - "required": [ - "name" - ] + } } } } @@ -7516,10 +7512,7 @@ "description": "Is collection enabled? When set to 'disabled', users cannot access the collection but Server SDKs with and API key can still read and write to the collection. No data is lost when this is toggled.", "x-example": false } - }, - "required": [ - "name" - ] + } } } } @@ -37112,10 +37105,7 @@ "description": "Is database enabled? When set to 'disabled', users cannot access the database but Server SDKs with an API key can still read and write to the database. No data is lost when this is toggled.", "x-example": false } - }, - "required": [ - "name" - ] + } } } } @@ -37579,10 +37569,7 @@ "description": "Is table enabled? When set to 'disabled', users cannot access the table but Server SDKs with and API key can still read and write to the table. No data is lost when this is toggled.", "x-example": false } - }, - "required": [ - "name" - ] + } } } } diff --git a/app/config/specs/open-api3-latest-server.json b/app/config/specs/open-api3-latest-server.json index 35bbbbb952..6b4e836a43 100644 --- a/app/config/specs/open-api3-latest-server.json +++ b/app/config/specs/open-api3-latest-server.json @@ -6427,8 +6427,7 @@ "enabled" ], "required": [ - "databaseId", - "name" + "databaseId" ], "responses": [ { @@ -6484,10 +6483,7 @@ "description": "Is database enabled? When set to 'disabled', users cannot access the database but Server SDKs with an API key can still read and write to the database. No data is lost when this is toggled.", "x-example": false } - }, - "required": [ - "name" - ] + } } } } @@ -6993,10 +6989,7 @@ "description": "Is collection enabled? When set to 'disabled', users cannot access the collection but Server SDKs with and API key can still read and write to the collection. No data is lost when this is toggled.", "x-example": false } - }, - "required": [ - "name" - ] + } } } } @@ -26760,10 +26753,7 @@ "description": "Is database enabled? When set to 'disabled', users cannot access the database but Server SDKs with an API key can still read and write to the database. No data is lost when this is toggled.", "x-example": false } - }, - "required": [ - "name" - ] + } } } } @@ -27232,10 +27222,7 @@ "description": "Is table enabled? When set to 'disabled', users cannot access the table but Server SDKs with and API key can still read and write to the table. No data is lost when this is toggled.", "x-example": false } - }, - "required": [ - "name" - ] + } } } } diff --git a/app/config/specs/swagger2-1.8.x-console.json b/app/config/specs/swagger2-1.8.x-console.json index 79835bb9d5..0bb1a47f0a 100644 --- a/app/config/specs/swagger2-1.8.x-console.json +++ b/app/config/specs/swagger2-1.8.x-console.json @@ -7080,8 +7080,7 @@ "enabled" ], "required": [ - "databaseId", - "name" + "databaseId" ], "responses": [ { @@ -7135,10 +7134,7 @@ "default": true, "x-example": false } - }, - "required": [ - "name" - ] + } } } ] @@ -7634,10 +7630,7 @@ "default": true, "x-example": false } - }, - "required": [ - "name" - ] + } } } ] @@ -37153,10 +37146,7 @@ "default": true, "x-example": false } - }, - "required": [ - "name" - ] + } } } ] @@ -37616,10 +37606,7 @@ "default": true, "x-example": false } - }, - "required": [ - "name" - ] + } } } ] diff --git a/app/config/specs/swagger2-1.8.x-server.json b/app/config/specs/swagger2-1.8.x-server.json index 04ff342583..ba941164e2 100644 --- a/app/config/specs/swagger2-1.8.x-server.json +++ b/app/config/specs/swagger2-1.8.x-server.json @@ -6534,8 +6534,7 @@ "enabled" ], "required": [ - "databaseId", - "name" + "databaseId" ], "responses": [ { @@ -6590,10 +6589,7 @@ "default": true, "x-example": false } - }, - "required": [ - "name" - ] + } } } ] @@ -7095,10 +7091,7 @@ "default": true, "x-example": false } - }, - "required": [ - "name" - ] + } } } ] @@ -26857,10 +26850,7 @@ "default": true, "x-example": false } - }, - "required": [ - "name" - ] + } } } ] @@ -27325,10 +27315,7 @@ "default": true, "x-example": false } - }, - "required": [ - "name" - ] + } } } ] diff --git a/app/config/specs/swagger2-latest-console.json b/app/config/specs/swagger2-latest-console.json index 79835bb9d5..0bb1a47f0a 100644 --- a/app/config/specs/swagger2-latest-console.json +++ b/app/config/specs/swagger2-latest-console.json @@ -7080,8 +7080,7 @@ "enabled" ], "required": [ - "databaseId", - "name" + "databaseId" ], "responses": [ { @@ -7135,10 +7134,7 @@ "default": true, "x-example": false } - }, - "required": [ - "name" - ] + } } } ] @@ -7634,10 +7630,7 @@ "default": true, "x-example": false } - }, - "required": [ - "name" - ] + } } } ] @@ -37153,10 +37146,7 @@ "default": true, "x-example": false } - }, - "required": [ - "name" - ] + } } } ] @@ -37616,10 +37606,7 @@ "default": true, "x-example": false } - }, - "required": [ - "name" - ] + } } } ] diff --git a/app/config/specs/swagger2-latest-server.json b/app/config/specs/swagger2-latest-server.json index 04ff342583..ba941164e2 100644 --- a/app/config/specs/swagger2-latest-server.json +++ b/app/config/specs/swagger2-latest-server.json @@ -6534,8 +6534,7 @@ "enabled" ], "required": [ - "databaseId", - "name" + "databaseId" ], "responses": [ { @@ -6590,10 +6589,7 @@ "default": true, "x-example": false } - }, - "required": [ - "name" - ] + } } } ] @@ -7095,10 +7091,7 @@ "default": true, "x-example": false } - }, - "required": [ - "name" - ] + } } } ] @@ -26857,10 +26850,7 @@ "default": true, "x-example": false } - }, - "required": [ - "name" - ] + } } } ] @@ -27325,10 +27315,7 @@ "default": true, "x-example": false } - }, - "required": [ - "name" - ] + } } } ] diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Update.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Update.php index 304ce5c88e..a2d696813b 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Update.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Update.php @@ -64,7 +64,7 @@ class Update extends Action )) ->param('databaseId', '', new UID(), 'Database ID.') ->param('collectionId', '', new UID(), 'Collection ID.') - ->param('name', null, new Text(128), 'Collection name. Max length: 128 chars.') + ->param('name', null, new Text(128), 'Collection name. Max length: 128 chars.', true) ->param('permissions', null, new Nullable(new Permissions(APP_LIMIT_ARRAY_PARAMS_SIZE)), 'An array of permission strings. By default, the current permissions are inherited. [Learn more about permissions](https://appwrite.io/docs/permissions).', true) ->param('documentSecurity', false, new Boolean(true), 'Enables configuring permissions for individual documents. A user needs one of document or collection level permissions to access a document. [Learn more about permissions](https://appwrite.io/docs/permissions).', true) ->param('enabled', true, new Boolean(), 'Is collection enabled? When set to \'disabled\', users cannot access the collection but Server SDKs with and API key can still read and write to the collection. No data is lost when this is toggled.', true) @@ -75,7 +75,7 @@ class Update extends Action ->callback($this->action(...)); } - public function action(string $databaseId, string $collectionId, string $name, ?array $permissions, bool $documentSecurity, bool $enabled, UtopiaResponse $response, Database $dbForProject, Event $queueForEvents, Authorization $authorization): void + public function action(string $databaseId, string $collectionId, ?string $name, ?array $permissions, bool $documentSecurity, bool $enabled, UtopiaResponse $response, Database $dbForProject, Event $queueForEvents, Authorization $authorization): void { $database = $authorization->skip(fn () => $dbForProject->getDocument('databases', $databaseId)); if ($database->isEmpty()) { @@ -87,6 +87,12 @@ class Update extends Action throw new Exception($this->getNotFoundException(), params: [$collectionId]); } + if ($name) { + $collection = $collection->setAttribute('name', $name); + } + + $searchName = $name ?? $collection->getAttribute('name'); + $permissions ??= $collection->getPermissions(); // Map aggregate permissions into the multiple permissions they represent. @@ -98,11 +104,10 @@ class Update extends Action 'database_' . $database->getSequence(), $collectionId, $collection - ->setAttribute('name', $name) ->setAttribute('$permissions', $permissions) ->setAttribute('documentSecurity', $documentSecurity) ->setAttribute('enabled', $enabled) - ->setAttribute('search', \implode(' ', [$collectionId, $name])) + ->setAttribute('search', \implode(' ', [$collectionId, $searchName])) ); $dbForProject->updateCollection('database_' . $database->getSequence() . '_collection_' . $collection->getSequence(), $permissions, $documentSecurity); diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Update.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Update.php index 231b13deee..3a073079e0 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Update.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Update.php @@ -57,7 +57,7 @@ class Update extends Action ), ]) ->param('databaseId', '', new UID(), 'Database ID.') - ->param('name', null, new Text(128), 'Database name. Max length: 128 chars.') + ->param('name', null, new Text(128), 'Database name. Max length: 128 chars.', true) ->param('enabled', true, new Boolean(), 'Is database enabled? When set to \'disabled\', users cannot access the database but Server SDKs with an API key can still read and write to the database. No data is lost when this is toggled.', true) ->inject('response') ->inject('dbForProject') @@ -65,7 +65,7 @@ class Update extends Action ->callback($this->action(...)); } - public function action(string $databaseId, string $name, bool $enabled, UtopiaResponse $response, Database $dbForProject, Event $queueForEvents): void + public function action(string $databaseId, ?string $name, bool $enabled, UtopiaResponse $response, Database $dbForProject, Event $queueForEvents): void { $database = $dbForProject->getDocument('databases', $databaseId); @@ -73,10 +73,15 @@ class Update extends Action throw new Exception(Exception::DATABASE_NOT_FOUND, params: [$databaseId]); } + if ($name) { + $database = $database->setAttribute('name', $name); + } + + $searchName = $name ?? $database->getAttribute('name'); + $database = $dbForProject->updateDocument('databases', $databaseId, $database - ->setAttribute('name', $name) ->setAttribute('enabled', $enabled) - ->setAttribute('search', implode(' ', [$databaseId, $name]))); + ->setAttribute('search', implode(' ', [$databaseId, $searchName]))); $queueForEvents->setParam('databaseId', $database->getId()); diff --git a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Update.php b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Update.php index 0d3bc9afc1..32376eaea1 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Update.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Update.php @@ -55,7 +55,7 @@ class Update extends CollectionUpdate )) ->param('databaseId', '', new UID(), 'Database ID.') ->param('tableId', '', new UID(), 'Table ID.') - ->param('name', null, new Text(128), 'Table name. Max length: 128 chars.') + ->param('name', null, new Text(128), 'Table name. Max length: 128 chars.', true) ->param('permissions', null, new Nullable(new Permissions(APP_LIMIT_ARRAY_PARAMS_SIZE)), 'An array of permission strings. By default, the current permissions are inherited. [Learn more about permissions](https://appwrite.io/docs/permissions).', true) ->param('rowSecurity', false, new Boolean(true), 'Enables configuring permissions for individual rows. A user needs one of row or table-level permissions to access a row. [Learn more about permissions](https://appwrite.io/docs/permissions).', true) ->param('enabled', true, new Boolean(), 'Is table enabled? When set to \'disabled\', users cannot access the table but Server SDKs with and API key can still read and write to the table. No data is lost when this is toggled.', true) diff --git a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Update.php b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Update.php index 3a45c94814..81cb9c781c 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Update.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Update.php @@ -47,7 +47,7 @@ class Update extends DatabaseUpdate contentType: ContentType::JSON )) ->param('databaseId', '', new UID(), 'Database ID.') - ->param('name', null, new Text(128), 'Database name. Max length: 128 chars.') + ->param('name', null, new Text(128), 'Database name. Max length: 128 chars.', true) ->param('enabled', true, new Boolean(), 'Is database enabled? When set to \'disabled\', users cannot access the database but Server SDKs with an API key can still read and write to the database. No data is lost when this is toggled.', true) ->inject('response') ->inject('dbForProject')