Conversation
| ### API Changes | ||
| <!-- Do we need new API endpoints? List and describe them and their API signatures --> | ||
| We need 2 new API endpoints in `databases.php` for creating and deleting server-defined attributes. | ||
| - POST `/v1/databases/:databaseId/collections/:collectionId/attributes/server` |
There was a problem hiding this comment.
Lets also have endpoint for listing them, so we don't need to hard-code then on Console. Its better to have config for it in Appwrite or library.
|
|
||
| ## Summary | ||
| <!-- Describe the problem we want to solve and suggested solution in a few paragraphs --> | ||
| This RFC proposes the addition of optional server-defined attributes in all the project collections that can only be added by server and cannot be modified by the client. The user can add them to each collection through the API or console. Some useful sttributes can be `createdBy`, `updatedBy`, `ip` etc. |
There was a problem hiding this comment.
Let's have exact list of all internal attributes we will have
There was a problem hiding this comment.
it would also be good to clarify exactly what the behavior of each would be.
|
The idea, in general, would help a lot on the part of Appwrite-console administrators (That can be a new market title 😉) and would help in setting pre-defined field structures for validations. One way of expanding it would be to add a Example 1 - Next appointment date. POST https://cloud.appwrite/v1/databases/:databaseId/collections/:collectionId/attributes/server
Content-Type: application/json
origin: https://localhost
{
"id" : "next_appointment",
"type" : "datetime",
"format" : "",
"size" : 0,
"required": false,
"default" : "[FUNCTION_ID]",
"array" : false,
"filters" : []
}Then, the function would run when the default value is empty, something like 👇, for example. module.exports = async (context) => {
try {
// Set another appointment in 90 days.
const next = new Date(+new Date() + (84600 * 90 * 1000));
return context.res.json({ value: next });
} catch (e) {
return context.res.json({ value: '' });
}
};Example 2 - Adding search attribute POST https://cloud.appwrite/v1/databases/:databaseId/collections/:collectionId/attributes/server
Content-Type: application/json
origin: https://localhost
{
"id" : "search",
"type" : "string",
"format" : "",
"size" : 512,
"required": false,
"default" : "%name% %email% %address% %country% %phone%",
"array" : false,
"filters" : []
} |
| # Optional server-defined attributes | ||
|
|
||
| * Creator: Khushboo Verma | ||
| * Relevant Issues: N/A |
There was a problem hiding this comment.
| * Relevant Issues: N/A | |
| * Relevant Issues: | |
| * https://github.com/appwrite/appwrite/issues/3623 |
|
|
||
| We can allow users to create indexes for new attributes from the `createIndex` endpoint. | ||
|
|
||
| We need to add a check in `createDocument` and `updateDocument` endpoints to populate the values of these attributes if they exist for client-side requests. |
There was a problem hiding this comment.
We do updates at the utopia-php/database level as well so we might need to do it there instead. For example, updatedAt and createdAt are handled in utopia: https://github.com/utopia-php/database/blob/4199fe8f00f4e181c7782c4a6862845d591c1f03/src/Database/Database.php#L3050-L3051
|
|
||
| ## Summary | ||
| <!-- Describe the problem we want to solve and suggested solution in a few paragraphs --> | ||
| This RFC proposes the addition of optional server-defined attributes in all the project collections that can only be added by server and cannot be modified by the client. The user can add them to each collection through the API or console. Some useful sttributes can be `createdBy`, `updatedBy`, `ip` etc. |
There was a problem hiding this comment.
it would also be good to clarify exactly what the behavior of each would be.
|
👀👀🔥 definitely checking this out |
What does this PR do?
RFC to add optional server-defined attributes to user
Test Plan
(Write your test plan here. If you changed any code, please provide us with clear instructions on how you verified your changes work.)
Related PRs and Issues
(If this PR is related to any other PR or resolves any issue or related to any issue link all related PR and issues here.)
Have you read the Contributing Guidelines on issues?
(Write your answer here.)