diff --git a/CHANGELOG.md b/CHANGELOG.md index 1ffcff2..b94ebcc 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 c1ae38e..25ccef6 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 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/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', ]; /** 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';