Check out v4 of the Fauna CLI
v4 of the Fauna CLI is now in beta. The new version introduces enhancements to the developer experience, including an improved authentication workflow. To get started, check out the CLI v4 quick start. |
role.update()
Learn: Roles |
---|
We recommend you use FSL to create and update user-defined roles. See FSL role schema. |
Update a user-defined role.
Description
Updates a user-defined role, represented as an
Role
document, with fields
from a provided data object.
During the update, fields from the data object are copied to the document, creating new fields or updating existing fields. The operation is similar to a merge.
Role
documents are FQL versions of a database’s FSL
role schema. See Roles.
Nested fields
Fields with nested objects in the data object are merged with the identically named nested object in the document.
Staged schema
If a database has staged schema, this method interacts with the database’s staged schema, not the active schema.
You can’t rename a role while a database has staged schema.
If the database has no staged schema, using this method is equivalent to making an unstaged schema change. Changes are applied immediately to the database’s active schema.
Avoid concurrent schema changes
Concurrent unstaged schema changes can cause contended transactions, even if the changes affect different resources. This includes unstaged changes made using:
-
The Fauna CLI
-
The Fauna Dashboard
-
The Fauna Core HTTP API’s Schema endpoints
A schema change triggers a transaction that validates the entire database schema. To avoid errors, do one of the following instead:
-
Perform unstaged schema changes sequentially
Parameters
Parameter | Type | Required | Description |
---|---|---|---|
data |
Document fields for the For supported document fields, see
The object can’t include the following metadata fields: * |
Return value
Type | Description |
---|---|
The updated |
Examples
Role.byName("manager")?.update({
membership: [
{
resource: "Manager"
}
],
privileges: [
{
resource: "Order",
actions: {
create: false,
delete: false,
read: true,
write: false
}
}, {
resource: "Product",
actions: {
create: true
}
}
],
data: {
custom: "some data"
}
})
{
name: "manager",
coll: Role,
ts: Time("2099-07-27T22:40:32.735Z"),
privileges: [
{
resource: "Order",
actions: {
create: false,
delete: false,
read: true,
write: false
}
},
{
resource: "Product",
actions: {
create: true
}
}
],
membership: [
{
resource: "Manager"
}
],
data: {
custom: "some data"
}
}
Is this article helpful?
Tell Fauna how the article can be improved:
Visit Fauna's forums
or email docs@fauna.com
Thank you for your feedback!