Add 'type' attribute to database creation and update tests

This commit is contained in:
ArnabChatterjee20k
2025-08-05 16:48:05 +05:30
parent e6f0804272
commit f06af411ba
5 changed files with 74 additions and 1 deletions
+9
View File
@@ -51,6 +51,15 @@ return [
'default' => null,
'array' => false,
],
[
'$id' => ID::custom('type'),
'type' => Database::VAR_STRING,
'size' => 128,
'required' => true,
'signed' => true,
'array' => false,
'filters' => [],
],
],
'indexes' => [
[
@@ -80,13 +80,14 @@ class Create extends Action
->param('databaseId', '', new CustomId(), 'Unique Id. Choose a custom ID or generate a random ID with `ID.unique()`. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can\'t start with a special char. Max length is 36 chars.')
->param('name', '', new Text(128), 'Database name. Max length: 128 chars.')
->param('enabled', true, new Boolean(), 'Is the 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)
->param('type', 'mysql', new Text(128), 'Database type.', true)
->inject('response')
->inject('dbForProject')
->inject('queueForEvents')
->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, string $type, UtopiaResponse $response, Database $dbForProject, Event $queueForEvents): void
{
$databaseId = $databaseId == 'unique()' ? ID::unique() : $databaseId;
@@ -96,6 +97,7 @@ class Create extends Action
'name' => $name,
'enabled' => $enabled,
'search' => implode(' ', [$databaseId, $name]),
'type' => $type
]));
} catch (DuplicateException) {
throw new Exception(Exception::DATABASE_ALREADY_EXISTS);
@@ -40,6 +40,12 @@ class Database extends Model
'default' => true,
'example' => false,
])
->addRule('type', [
'type' => self::TYPE_STRING,
'description' => 'Database type.',
'default' => 'mysql',
'example' => 'mysql',
])
;
}
@@ -32,6 +32,34 @@ trait DatabasesBase
$this->assertNotEmpty($database['body']['$id']);
$this->assertEquals(201, $database['headers']['status-code']);
$this->assertEquals('Test Database', $database['body']['name']);
$this->assertEquals('mysql', $database['body']['type']);
// testing to create a database with type
$database2 = $this->client->call(Client::METHOD_POST, '/databases', [
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
'x-appwrite-key' => $this->getProject()['apiKey']
], [
'databaseId' => ID::unique(),
'name' => 'Test Database with type',
'type' => 'mongodb'
]);
$this->assertNotEmpty($database2['body']['$id']);
$this->assertEquals(201, $database2['headers']['status-code']);
$this->assertEquals('Test Database with type', $database2['body']['name']);
$this->assertEquals('mongodb', $database2['body']['type']);
// cleanup(for database2)
$databaseId = $database2['body']['$id'];
$response = $this->client->call(Client::METHOD_DELETE, '/databases/' . $databaseId, [
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
'x-appwrite-key' => $this->getProject()['apiKey']
]);
$this->assertEquals(204, $response['headers']['status-code']);
return ['databaseId' => $database['body']['$id']];
}
@@ -32,6 +32,34 @@ trait DatabasesBase
$this->assertNotEmpty($database['body']['$id']);
$this->assertEquals(201, $database['headers']['status-code']);
$this->assertEquals('Test Database', $database['body']['name']);
$this->assertEquals('mysql', $database['body']['type']);
// testing to create a database with type
$database2 = $this->client->call(Client::METHOD_POST, '/databases', [
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
'x-appwrite-key' => $this->getProject()['apiKey']
], [
'databaseId' => ID::unique(),
'name' => 'Test Database with type',
'type' => 'mongodb'
]);
$this->assertNotEmpty($database2['body']['$id']);
$this->assertEquals(201, $database2['headers']['status-code']);
$this->assertEquals('Test Database with type', $database2['body']['name']);
$this->assertEquals('mongodb', $database2['body']['type']);
// cleanup(for database2)
$databaseId = $database2['body']['$id'];
$response = $this->client->call(Client::METHOD_DELETE, '/databases/' . $databaseId, [
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
'x-appwrite-key' => $this->getProject()['apiKey']
]);
$this->assertEquals(204, $response['headers']['status-code']);
return ['databaseId' => $database['body']['$id']];
}