diff --git a/CHANGELOG.md b/CHANGELOG.md index 1ffcff2a..b94ebcc7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Change Log +## 19.1.0 + +* Added ability to create columns and indexes synchronously while creating a table + ## 19.0.0 * Rename `VCSDeploymentType` enum to `VCSReferenceType` diff --git a/docs/databases.md b/docs/databases.md index c1ae38e4..25ccef6b 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), 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 b3e811e1..9959a3fe 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 827b1292..3ffa5a5a 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 b2c55329..f1405da5 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 3dc48650..458405ed 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 639b1997..6e738e64 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 64471ef7..6f0ecf87 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 1f91db79..721ed364 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 93c18547..a2b45f76 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 2ff630a2..02525f74 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 f92155b6..91684345 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 fc42cbe6..ef6b8cc0 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 12d71c2f..42f7fb93 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 9ac9e365..aabfa033 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 aff821c8..aef39e54 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 7005a2de..e92f32b8 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/Client.php b/src/Appwrite/Client.php index a829fd7b..9ade6122 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', ]; /** diff --git a/src/Appwrite/Services/Databases.php b/src/Appwrite/Services/Databases.php index 50744681..e9796fa1 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 6ef4f47d..a7fd576a 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';