1
0
Fork 0
mirror of synced 2024-09-28 07:21:35 +12:00

Merge pull request #3405 from appwrite/fix-internal-indexes

Feat: Allow internal indexes
This commit is contained in:
Torsten Dittmann 2022-06-28 14:21:27 +02:00 committed by GitHub
commit f438d4695d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 60 additions and 5 deletions

View file

@ -1498,7 +1498,7 @@ App::post('/v1/databases/:databaseId/collections/:collectionId/indexes')
->param('collectionId', '', new UID(), 'Collection ID. You can create a new collection using the Database service [server integration](https://appwrite.io/docs/server/database#createCollection).')
->param('key', null, new Key(), 'Index Key.')
->param('type', null, new WhiteList([Database::INDEX_KEY, Database::INDEX_FULLTEXT, Database::INDEX_UNIQUE, Database::INDEX_SPATIAL, Database::INDEX_ARRAY]), 'Index type.')
->param('attributes', null, new ArrayList(new Key(), APP_LIMIT_ARRAY_PARAMS_SIZE), 'Array of attributes to index. Maximum of ' . APP_LIMIT_ARRAY_PARAMS_SIZE . ' attributes are allowed, each 32 characters long.')
->param('attributes', null, new ArrayList(new Key(true), APP_LIMIT_ARRAY_PARAMS_SIZE), 'Array of attributes to index. Maximum of ' . APP_LIMIT_ARRAY_PARAMS_SIZE . ' attributes are allowed, each 32 characters long.')
->param('orders', [], new ArrayList(new WhiteList(['ASC', 'DESC'], false, Database::VAR_STRING), APP_LIMIT_ARRAY_PARAMS_SIZE), 'Array of index orders. Maximum of ' . APP_LIMIT_ARRAY_PARAMS_SIZE . ' orders are allowed.', true)
->inject('response')
->inject('dbForProject')
@ -1533,6 +1533,38 @@ App::post('/v1/databases/:databaseId/collections/:collectionId/indexes')
// Convert Document[] to array of attribute metadata
$oldAttributes = \array_map(fn ($a) => $a->getArrayCopy(), $collection->getAttribute('attributes'));
$oldAttributes[] = [
'key' => '$id',
'type' => 'string',
'status' => 'available',
'required' => true,
'array' => false,
'default' => null,
'size' => 36
];
$oldAttributes[] = [
'key' => '$createdAt',
'type' => 'integer',
'status' => 'available',
'signed' => false,
'required' => false,
'array' => false,
'default' => null,
'size' => 0
];
$oldAttributes[] = [
'key' => '$updatedAt',
'type' => 'integer',
'status' => 'available',
'signed' => false,
'required' => false,
'array' => false,
'default' => null,
'size' => 0
];
// lengths hidden by default
$lengths = [];

View file

@ -1161,8 +1161,11 @@ $logs = $this->getParam('logs', null);
<div data-forms-clone="" data-label="Add Attribute" data-target="attributes-section" data-first="1">
<div class="row responsive thin margin-bottom-tiny">
<div class="col span-7 margin-bottom-small">
<select data-duplications data-ls-attrs="name=attributes" data-ls-loop="project-collection.attributes" data-ls-as="option" data-cast-to="array" class="margin-bottom-no">
<option data-ls-attrs="value={{option.key}}" data-ls-bind="{{option.key}}"></option>
<select data-duplications data-ls-attrs="name=attributes" class="margin-bottom-no">
<option value="$id">$id</option>
<option value="$createdAt">$createdAt</option>
<option value="$updatedAt">$updatedAt</option>
<option data-ls-loop="project-collection.attributes" data-ls-as="option" data-cast-to="array" data-ls-attrs="value={{option.key}}" data-ls-bind="{{option.key}}"></option>
</select>
</div>
<div class="col span-4 margin-bottom-small">

View file

@ -103,7 +103,7 @@ services:
- ./phpunit.xml:/usr/src/code/phpunit.xml
- ./tests:/usr/src/code/tests
- ./app:/usr/src/code/app
# - ./vendor:/usr/src/code/vendor
# - ./vendor/utopia/database:/usr/src/code/vendor/utopia/database
- ./docs:/usr/src/code/docs
- ./public:/usr/src/code/public
- ./src:/usr/src/code/src

View file

@ -727,6 +727,24 @@ trait DatabasesBase
$this->assertCount(1, $releaseYearIndex['body']['attributes']);
$this->assertEquals('releaseYear', $releaseYearIndex['body']['attributes'][0]);
$releaseWithDate = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $data['moviesId'] . '/indexes', array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
'x-appwrite-key' => $this->getProject()['apiKey']
]), [
'key' => 'releaseYearDated',
'type' => 'key',
'attributes' => ['releaseYear', '$createdAt', '$updatedAt'],
]);
$this->assertEquals(201, $releaseWithDate['headers']['status-code']);
$this->assertEquals('releaseYearDated', $releaseWithDate['body']['key']);
$this->assertEquals('key', $releaseWithDate['body']['type']);
$this->assertCount(3, $releaseWithDate['body']['attributes']);
$this->assertEquals('releaseYear', $releaseWithDate['body']['attributes'][0]);
$this->assertEquals('$createdAt', $releaseWithDate['body']['attributes'][1]);
$this->assertEquals('$updatedAt', $releaseWithDate['body']['attributes'][2]);
// wait for database worker to create index
sleep(2);
@ -737,11 +755,13 @@ trait DatabasesBase
]), []);
$this->assertIsArray($movies['body']['indexes']);
$this->assertCount(2, $movies['body']['indexes']);
$this->assertCount(3, $movies['body']['indexes']);
$this->assertEquals($titleIndex['body']['key'], $movies['body']['indexes'][0]['key']);
$this->assertEquals($releaseYearIndex['body']['key'], $movies['body']['indexes'][1]['key']);
$this->assertEquals($releaseWithDate['body']['key'], $movies['body']['indexes'][2]['key']);
$this->assertEquals('available', $movies['body']['indexes'][0]['status']);
$this->assertEquals('available', $movies['body']['indexes'][1]['status']);
$this->assertEquals('available', $movies['body']['indexes'][2]['status']);
return $data;
}