From 94445b3e33bc901af555d7d700dd20dd0cb66d38 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Wed, 17 Dec 2025 18:54:30 +1300 Subject: [PATCH 1/4] Add full schema collection create --- docs/databases.md | 2 ++ docs/examples/account/create-anonymous-session.md | 3 ++- .../account/create-email-password-session.md | 3 ++- docs/examples/account/create-email-token.md | 3 ++- docs/examples/account/create-jwt.md | 3 ++- docs/examples/account/create-magic-url-token.md | 3 ++- docs/examples/account/create-mfa-challenge.md | 3 ++- docs/examples/account/create-o-auth-2-token.md | 3 ++- docs/examples/account/create-phone-token.md | 3 ++- docs/examples/account/create-session.md | 3 ++- docs/examples/account/create.md | 3 ++- docs/examples/account/update-magic-url-session.md | 3 ++- docs/examples/account/update-phone-session.md | 3 ++- docs/examples/databases/create-collection.md | 4 +++- docs/examples/tablesdb/create-table.md | 4 +++- docs/tablesdb.md | 2 ++ src/Appwrite/Services/Databases.php | 12 +++++++++++- src/Appwrite/Services/TablesDB.php | 12 +++++++++++- 18 files changed, 56 insertions(+), 16 deletions(-) diff --git a/docs/databases.md b/docs/databases.md index c1ae38e..b98d700 100644 --- a/docs/databases.md +++ b/docs/databases.md @@ -186,6 +186,8 @@ POST https://cloud.appwrite.io/v1/databases/{databaseId}/collections | permissions | array | An array of permissions strings. By default, no user is granted with any permissions. [Learn more about permissions](https://appwrite.io/docs/permissions). | | | documentSecurity | boolean | 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). | | | enabled | 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. | 1 | +| attributes | array | Array of attribute definitions to create. Each attribute should contain: key (string), type (string: string, integer, float, boolean, datetime, relationship), size (integer, required for string type), required (boolean, optional), default (mixed, optional), array (boolean, optional), and type-specific options. | [] | +| indexes | array | Array of index definitions to create. Each index should contain: key (string), type (string: key, fulltext, unique, spatial), attributes (array of attribute keys), orders (array of ASC/DESC, optional), and lengths (array of integers, optional). | [] | ```http request diff --git a/docs/examples/account/create-anonymous-session.md b/docs/examples/account/create-anonymous-session.md index b3e811e..9959a3f 100644 --- a/docs/examples/account/create-anonymous-session.md +++ b/docs/examples/account/create-anonymous-session.md @@ -5,7 +5,8 @@ use Appwrite\Services\Account; $client = (new Client()) ->setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint - ->setProject(''); // Your project ID + ->setProject('') // Your project ID + ->setSession(''); // The user session to authenticate with $account = new Account($client); diff --git a/docs/examples/account/create-email-password-session.md b/docs/examples/account/create-email-password-session.md index 827b129..3ffa5a5 100644 --- a/docs/examples/account/create-email-password-session.md +++ b/docs/examples/account/create-email-password-session.md @@ -5,7 +5,8 @@ use Appwrite\Services\Account; $client = (new Client()) ->setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint - ->setProject(''); // Your project ID + ->setProject('') // Your project ID + ->setSession(''); // The user session to authenticate with $account = new Account($client); diff --git a/docs/examples/account/create-email-token.md b/docs/examples/account/create-email-token.md index b2c5532..f1405da 100644 --- a/docs/examples/account/create-email-token.md +++ b/docs/examples/account/create-email-token.md @@ -5,7 +5,8 @@ use Appwrite\Services\Account; $client = (new Client()) ->setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint - ->setProject(''); // Your project ID + ->setProject('') // Your project ID + ->setSession(''); // The user session to authenticate with $account = new Account($client); diff --git a/docs/examples/account/create-jwt.md b/docs/examples/account/create-jwt.md index 3dc4865..458405e 100644 --- a/docs/examples/account/create-jwt.md +++ b/docs/examples/account/create-jwt.md @@ -5,7 +5,8 @@ use Appwrite\Services\Account; $client = (new Client()) ->setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint - ->setProject(''); // Your project ID + ->setProject('') // Your project ID + ->setSession(''); // The user session to authenticate with $account = new Account($client); diff --git a/docs/examples/account/create-magic-url-token.md b/docs/examples/account/create-magic-url-token.md index 639b199..6e738e6 100644 --- a/docs/examples/account/create-magic-url-token.md +++ b/docs/examples/account/create-magic-url-token.md @@ -5,7 +5,8 @@ use Appwrite\Services\Account; $client = (new Client()) ->setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint - ->setProject(''); // Your project ID + ->setProject('') // Your project ID + ->setSession(''); // The user session to authenticate with $account = new Account($client); diff --git a/docs/examples/account/create-mfa-challenge.md b/docs/examples/account/create-mfa-challenge.md index 64471ef..6f0ecf8 100644 --- a/docs/examples/account/create-mfa-challenge.md +++ b/docs/examples/account/create-mfa-challenge.md @@ -6,7 +6,8 @@ use Appwrite\Enums\AuthenticationFactor; $client = (new Client()) ->setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint - ->setProject(''); // Your project ID + ->setProject('') // Your project ID + ->setSession(''); // The user session to authenticate with $account = new Account($client); diff --git a/docs/examples/account/create-o-auth-2-token.md b/docs/examples/account/create-o-auth-2-token.md index 1f91db7..721ed36 100644 --- a/docs/examples/account/create-o-auth-2-token.md +++ b/docs/examples/account/create-o-auth-2-token.md @@ -6,7 +6,8 @@ use Appwrite\Enums\OAuthProvider; $client = (new Client()) ->setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint - ->setProject(''); // Your project ID + ->setProject('') // Your project ID + ->setSession(''); // The user session to authenticate with $account = new Account($client); diff --git a/docs/examples/account/create-phone-token.md b/docs/examples/account/create-phone-token.md index 93c1854..a2b45f7 100644 --- a/docs/examples/account/create-phone-token.md +++ b/docs/examples/account/create-phone-token.md @@ -5,7 +5,8 @@ use Appwrite\Services\Account; $client = (new Client()) ->setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint - ->setProject(''); // Your project ID + ->setProject('') // Your project ID + ->setSession(''); // The user session to authenticate with $account = new Account($client); diff --git a/docs/examples/account/create-session.md b/docs/examples/account/create-session.md index 2ff630a..02525f7 100644 --- a/docs/examples/account/create-session.md +++ b/docs/examples/account/create-session.md @@ -5,7 +5,8 @@ use Appwrite\Services\Account; $client = (new Client()) ->setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint - ->setProject(''); // Your project ID + ->setProject('') // Your project ID + ->setSession(''); // The user session to authenticate with $account = new Account($client); diff --git a/docs/examples/account/create.md b/docs/examples/account/create.md index f92155b..9168434 100644 --- a/docs/examples/account/create.md +++ b/docs/examples/account/create.md @@ -5,7 +5,8 @@ use Appwrite\Services\Account; $client = (new Client()) ->setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint - ->setProject(''); // Your project ID + ->setProject('') // Your project ID + ->setSession(''); // The user session to authenticate with $account = new Account($client); diff --git a/docs/examples/account/update-magic-url-session.md b/docs/examples/account/update-magic-url-session.md index fc42cbe..ef6b8cc 100644 --- a/docs/examples/account/update-magic-url-session.md +++ b/docs/examples/account/update-magic-url-session.md @@ -5,7 +5,8 @@ use Appwrite\Services\Account; $client = (new Client()) ->setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint - ->setProject(''); // Your project ID + ->setProject('') // Your project ID + ->setSession(''); // The user session to authenticate with $account = new Account($client); diff --git a/docs/examples/account/update-phone-session.md b/docs/examples/account/update-phone-session.md index 12d71c2..42f7fb9 100644 --- a/docs/examples/account/update-phone-session.md +++ b/docs/examples/account/update-phone-session.md @@ -5,7 +5,8 @@ use Appwrite\Services\Account; $client = (new Client()) ->setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint - ->setProject(''); // Your project ID + ->setProject('') // Your project ID + ->setSession(''); // The user session to authenticate with $account = new Account($client); diff --git a/docs/examples/databases/create-collection.md b/docs/examples/databases/create-collection.md index 9ac9e36..aabfa03 100644 --- a/docs/examples/databases/create-collection.md +++ b/docs/examples/databases/create-collection.md @@ -18,5 +18,7 @@ $result = $databases->createCollection( name: '', permissions: [Permission::read(Role::any())], // optional documentSecurity: false, // optional - enabled: false // optional + enabled: false, // optional + attributes: [], // optional + indexes: [] // optional ); \ No newline at end of file diff --git a/docs/examples/tablesdb/create-table.md b/docs/examples/tablesdb/create-table.md index aff821c..aef39e5 100644 --- a/docs/examples/tablesdb/create-table.md +++ b/docs/examples/tablesdb/create-table.md @@ -18,5 +18,7 @@ $result = $tablesDB->createTable( name: '', permissions: [Permission::read(Role::any())], // optional rowSecurity: false, // optional - enabled: false // optional + enabled: false, // optional + columns: [], // optional + indexes: [] // optional ); \ No newline at end of file diff --git a/docs/tablesdb.md b/docs/tablesdb.md index 7005a2d..e92f32b 100644 --- a/docs/tablesdb.md +++ b/docs/tablesdb.md @@ -186,6 +186,8 @@ POST https://cloud.appwrite.io/v1/tablesdb/{databaseId}/tables | permissions | array | An array of permissions strings. By default, no user is granted with any permissions. [Learn more about permissions](https://appwrite.io/docs/permissions). | | | rowSecurity | boolean | 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). | | | enabled | 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. | 1 | +| columns | array | Array of column definitions to create. Each column should contain: key (string), type (string: string, integer, float, boolean, datetime, relationship), size (integer, required for string type), required (boolean, optional), default (mixed, optional), array (boolean, optional), and type-specific options. | [] | +| indexes | array | Array of index definitions to create. Each index should contain: key (string), type (string: key, fulltext, unique, spatial), attributes (array of column keys), orders (array of ASC/DESC, optional), and lengths (array of integers, optional). | [] | ```http request diff --git a/src/Appwrite/Services/Databases.php b/src/Appwrite/Services/Databases.php index 5074468..e9796fa 100644 --- a/src/Appwrite/Services/Databases.php +++ b/src/Appwrite/Services/Databases.php @@ -458,13 +458,15 @@ public function listCollections(string $databaseId, ?array $queries = null, ?str * @param ?array $permissions * @param ?bool $documentSecurity * @param ?bool $enabled + * @param ?array $attributes + * @param ?array $indexes * @throws AppwriteException * @return array * * @deprecated This API has been deprecated since 1.8.0. Please use `createTable` instead. * @see TablesDB::createTable */ - public function createCollection(string $databaseId, string $collectionId, string $name, ?array $permissions = null, ?bool $documentSecurity = null, ?bool $enabled = null): array + public function createCollection(string $databaseId, string $collectionId, string $name, ?array $permissions = null, ?bool $documentSecurity = null, ?bool $enabled = null, ?array $attributes = null, ?array $indexes = null): array { $apiPath = str_replace( ['{databaseId}'], @@ -486,6 +488,14 @@ public function createCollection(string $databaseId, string $collectionId, strin $apiParams['enabled'] = $enabled; } + if (!is_null($attributes)) { + $apiParams['attributes'] = $attributes; + } + + if (!is_null($indexes)) { + $apiParams['indexes'] = $indexes; + } + $apiHeaders = []; $apiHeaders['content-type'] = 'application/json'; diff --git a/src/Appwrite/Services/TablesDB.php b/src/Appwrite/Services/TablesDB.php index 6ef4f47..a7fd576 100644 --- a/src/Appwrite/Services/TablesDB.php +++ b/src/Appwrite/Services/TablesDB.php @@ -440,10 +440,12 @@ public function listTables(string $databaseId, ?array $queries = null, ?string $ * @param ?array $permissions * @param ?bool $rowSecurity * @param ?bool $enabled + * @param ?array $columns + * @param ?array $indexes * @throws AppwriteException * @return array */ - public function createTable(string $databaseId, string $tableId, string $name, ?array $permissions = null, ?bool $rowSecurity = null, ?bool $enabled = null): array + public function createTable(string $databaseId, string $tableId, string $name, ?array $permissions = null, ?bool $rowSecurity = null, ?bool $enabled = null, ?array $columns = null, ?array $indexes = null): array { $apiPath = str_replace( ['{databaseId}'], @@ -465,6 +467,14 @@ public function createTable(string $databaseId, string $tableId, string $name, ? $apiParams['enabled'] = $enabled; } + if (!is_null($columns)) { + $apiParams['columns'] = $columns; + } + + if (!is_null($indexes)) { + $apiParams['indexes'] = $indexes; + } + $apiHeaders = []; $apiHeaders['content-type'] = 'application/json'; From 3901b7eeb2c7c40f70608477f85a00e8db7e78de Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Wed, 17 Dec 2025 19:21:19 +1300 Subject: [PATCH 2/4] Update version --- CHANGELOG.md | 4 ++++ src/Appwrite/Client.php | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1ffcff2..0896065 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Change Log +## 19.1.0 + +* Added ability to create attributes and indexes synchronously while creating a collection + ## 19.0.0 * Rename `VCSDeploymentType` enum to `VCSReferenceType` diff --git a/src/Appwrite/Client.php b/src/Appwrite/Client.php index a829fd7..9ade612 100644 --- a/src/Appwrite/Client.php +++ b/src/Appwrite/Client.php @@ -37,11 +37,11 @@ class Client */ protected array $headers = [ 'content-type' => '', - 'user-agent' => 'AppwritePHPSDK/19.0.0 ()', + 'user-agent' => 'AppwritePHPSDK/19.1.0 ()', 'x-sdk-name'=> 'PHP', 'x-sdk-platform'=> 'server', 'x-sdk-language'=> 'php', - 'x-sdk-version'=> '19.0.0', + 'x-sdk-version'=> '19.1.0', ]; /** From 3b9f17724017b54046837690873e4a0bc3ed9462 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Thu, 18 Dec 2025 20:31:03 +1300 Subject: [PATCH 3/4] Remove invalid type --- docs/databases.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/databases.md b/docs/databases.md index b98d700..25ccef6 100644 --- a/docs/databases.md +++ b/docs/databases.md @@ -186,7 +186,7 @@ POST https://cloud.appwrite.io/v1/databases/{databaseId}/collections | permissions | array | An array of permissions strings. By default, no user is granted with any permissions. [Learn more about permissions](https://appwrite.io/docs/permissions). | | | documentSecurity | boolean | 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). | | | enabled | 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. | 1 | -| attributes | array | Array of attribute definitions to create. Each attribute should contain: key (string), type (string: string, integer, float, boolean, datetime, relationship), size (integer, required for string type), required (boolean, optional), default (mixed, optional), array (boolean, optional), and type-specific options. | [] | +| attributes | array | Array of attribute definitions to create. Each attribute should contain: key (string), type (string: string, integer, float, boolean, datetime), size (integer, required for string type), required (boolean, optional), default (mixed, optional), array (boolean, optional), and type-specific options. | [] | | indexes | array | Array of index definitions to create. Each index should contain: key (string), type (string: key, fulltext, unique, spatial), attributes (array of attribute keys), orders (array of ASC/DESC, optional), and lengths (array of integers, optional). | [] | From 4a95a7fb9b51af0dbcda1aa43b0202568ca9418b Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Thu, 18 Dec 2025 20:34:34 +1300 Subject: [PATCH 4/4] Update changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0896065..b94ebcc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ ## 19.1.0 -* Added ability to create attributes and indexes synchronously while creating a collection +* Added ability to create columns and indexes synchronously while creating a table ## 19.0.0