Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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`
Expand Down
2 changes: 2 additions & 0 deletions docs/databases.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion docs/examples/account/create-anonymous-session.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ use Appwrite\Services\Account;

$client = (new Client())
->setEndpoint('https://<REGION>.cloud.appwrite.io/v1') // Your API Endpoint
->setProject('<YOUR_PROJECT_ID>'); // Your project ID
->setProject('<YOUR_PROJECT_ID>') // Your project ID
->setSession(''); // The user session to authenticate with
Comment on lines +8 to +9
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

Remove setSession('') before createAnonymousSession().

The createAnonymousSession() method creates a session for unauthenticated users, making the preceding setSession('') call logically contradictory. Official SDK examples across multiple languages omit this pattern, and setting an empty session string causes authorization failures in subsequent API calls.

🤖 Prompt for AI Agents
In docs/examples/account/create-anonymous-session.md around lines 8-9, remove
the call to setSession('') that precedes createAnonymousSession(); the empty
session string conflicts with the anonymous session flow and causes auth
failures—update the example to only setProject('<YOUR_PROJECT_ID>') (or any
required config) and then call createAnonymousSession(), ensuring no empty
session is set before creating the anonymous session.


$account = new Account($client);

Expand Down
3 changes: 2 additions & 1 deletion docs/examples/account/create-email-password-session.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ use Appwrite\Services\Account;

$client = (new Client())
->setEndpoint('https://<REGION>.cloud.appwrite.io/v1') // Your API Endpoint
->setProject('<YOUR_PROJECT_ID>'); // Your project ID
->setProject('<YOUR_PROJECT_ID>') // Your project ID
->setSession(''); // The user session to authenticate with
Comment on lines +8 to +9
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Check all account examples to see which operations use setSession
rg -n "setSession\(|->create.*Session\(" docs/examples/account/ -A 2 -B 2 2>/dev/null | head -200

Repository: appwrite/sdk-for-php

Length of output: 15547


Remove setSession('') from examples that create new sessions.

Official Appwrite PHP Server SDK documentation shows session creation methods should be called without setSession(). The empty string pattern appears across all account examples in this PR but should only apply to operations on existing sessions or when implementing SSR authentication for subsequent requests. Session creation operations (like createEmailPasswordSession, createAnonymousSession, createSession) should work with an unauthenticated client or admin client with an API key.

🤖 Prompt for AI Agents
In docs/examples/account/create-email-password-session.md around lines 8 to 9,
the example incorrectly calls setSession('') when creating a new session; remove
the setSession('') call from this and any other session-creation examples in the
PR so the client is unauthenticated (or uses an API key) for session creation
methods like createEmailPasswordSession/createAnonymousSession/createSession;
update examples to rely on an unauthenticated client or admin API key instead of
passing an empty session string.


$account = new Account($client);

Expand Down
3 changes: 2 additions & 1 deletion docs/examples/account/create-email-token.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ use Appwrite\Services\Account;

$client = (new Client())
->setEndpoint('https://<REGION>.cloud.appwrite.io/v1') // Your API Endpoint
->setProject('<YOUR_PROJECT_ID>'); // Your project ID
->setProject('<YOUR_PROJECT_ID>') // Your project ID
->setSession(''); // The user session to authenticate with

$account = new Account($client);

Expand Down
3 changes: 2 additions & 1 deletion docs/examples/account/create-jwt.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ use Appwrite\Services\Account;

$client = (new Client())
->setEndpoint('https://<REGION>.cloud.appwrite.io/v1') // Your API Endpoint
->setProject('<YOUR_PROJECT_ID>'); // Your project ID
->setProject('<YOUR_PROJECT_ID>') // Your project ID
->setSession(''); // The user session to authenticate with

$account = new Account($client);

Expand Down
3 changes: 2 additions & 1 deletion docs/examples/account/create-magic-url-token.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ use Appwrite\Services\Account;

$client = (new Client())
->setEndpoint('https://<REGION>.cloud.appwrite.io/v1') // Your API Endpoint
->setProject('<YOUR_PROJECT_ID>'); // Your project ID
->setProject('<YOUR_PROJECT_ID>') // Your project ID
->setSession(''); // The user session to authenticate with
Comment on lines +8 to +9
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Remove setSession('') from the client configuration.

The createMagicURLToken endpoint is unauthenticated and does not require session configuration on the client. The magic URL authentication flow initiates the login process without a session, and the session is only created afterward using the token secret from the email link. Remove the setSession('') line entirely, as it adds no value and misleads developers into thinking session setup is necessary for this step.

🤖 Prompt for AI Agents
In docs/examples/account/create-magic-url-token.md around lines 8-9, remove the
call to setSession('') from the client configuration because createMagicURLToken
is an unauthenticated endpoint; update the example by deleting that line so the
client only sets the project (and any other needed non-session config), ensuring
the example does not suggest a session is required for initiating the magic URL
flow.


$account = new Account($client);

Expand Down
3 changes: 2 additions & 1 deletion docs/examples/account/create-mfa-challenge.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ use Appwrite\Enums\AuthenticationFactor;

$client = (new Client())
->setEndpoint('https://<REGION>.cloud.appwrite.io/v1') // Your API Endpoint
->setProject('<YOUR_PROJECT_ID>'); // Your project ID
->setProject('<YOUR_PROJECT_ID>') // Your project ID
->setSession(''); // The user session to authenticate with

$account = new Account($client);

Expand Down
3 changes: 2 additions & 1 deletion docs/examples/account/create-o-auth-2-token.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ use Appwrite\Enums\OAuthProvider;

$client = (new Client())
->setEndpoint('https://<REGION>.cloud.appwrite.io/v1') // Your API Endpoint
->setProject('<YOUR_PROJECT_ID>'); // Your project ID
->setProject('<YOUR_PROJECT_ID>') // Your project ID
->setSession(''); // The user session to authenticate with

$account = new Account($client);

Expand Down
3 changes: 2 additions & 1 deletion docs/examples/account/create-phone-token.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ use Appwrite\Services\Account;

$client = (new Client())
->setEndpoint('https://<REGION>.cloud.appwrite.io/v1') // Your API Endpoint
->setProject('<YOUR_PROJECT_ID>'); // Your project ID
->setProject('<YOUR_PROJECT_ID>') // Your project ID
->setSession(''); // The user session to authenticate with

$account = new Account($client);

Expand Down
3 changes: 2 additions & 1 deletion docs/examples/account/create-session.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ use Appwrite\Services\Account;

$client = (new Client())
->setEndpoint('https://<REGION>.cloud.appwrite.io/v1') // Your API Endpoint
->setProject('<YOUR_PROJECT_ID>'); // Your project ID
->setProject('<YOUR_PROJECT_ID>') // Your project ID
->setSession(''); // The user session to authenticate with

$account = new Account($client);

Expand Down
3 changes: 2 additions & 1 deletion docs/examples/account/create.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ use Appwrite\Services\Account;

$client = (new Client())
->setEndpoint('https://<REGION>.cloud.appwrite.io/v1') // Your API Endpoint
->setProject('<YOUR_PROJECT_ID>'); // Your project ID
->setProject('<YOUR_PROJECT_ID>') // Your project ID
->setSession(''); // The user session to authenticate with

$account = new Account($client);

Expand Down
3 changes: 2 additions & 1 deletion docs/examples/account/update-magic-url-session.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ use Appwrite\Services\Account;

$client = (new Client())
->setEndpoint('https://<REGION>.cloud.appwrite.io/v1') // Your API Endpoint
->setProject('<YOUR_PROJECT_ID>'); // Your project ID
->setProject('<YOUR_PROJECT_ID>') // Your project ID
->setSession(''); // The user session to authenticate with

$account = new Account($client);

Expand Down
3 changes: 2 additions & 1 deletion docs/examples/account/update-phone-session.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ use Appwrite\Services\Account;

$client = (new Client())
->setEndpoint('https://<REGION>.cloud.appwrite.io/v1') // Your API Endpoint
->setProject('<YOUR_PROJECT_ID>'); // Your project ID
->setProject('<YOUR_PROJECT_ID>') // Your project ID
->setSession(''); // The user session to authenticate with

$account = new Account($client);

Expand Down
4 changes: 3 additions & 1 deletion docs/examples/databases/create-collection.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,7 @@ $result = $databases->createCollection(
name: '<NAME>',
permissions: [Permission::read(Role::any())], // optional
documentSecurity: false, // optional
enabled: false // optional
enabled: false, // optional
attributes: [], // optional
indexes: [] // optional
);
4 changes: 3 additions & 1 deletion docs/examples/tablesdb/create-table.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,7 @@ $result = $tablesDB->createTable(
name: '<NAME>',
permissions: [Permission::read(Role::any())], // optional
rowSecurity: false, // optional
enabled: false // optional
enabled: false, // optional
columns: [], // optional
indexes: [] // optional
);
2 changes: 2 additions & 0 deletions docs/tablesdb.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/Appwrite/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
];

/**
Expand Down
12 changes: 11 additions & 1 deletion src/Appwrite/Services/Databases.php
Original file line number Diff line number Diff line change
Expand Up @@ -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}'],
Expand All @@ -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';

Expand Down
12 changes: 11 additions & 1 deletion src/Appwrite/Services/TablesDB.php
Original file line number Diff line number Diff line change
Expand Up @@ -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}'],
Expand All @@ -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';

Expand Down