import Since from '@components/shared/Since.astro' import RailroadDiagram from '@components/RailroadDiagram.astro' import Tabs from '@components/Tabs/Tabs.astro' import TabItem from '@components/Tabs/TabItem.astro'
ALTER USER statement
The ALTER USER statement can be used to modify an existing defined database user.
Statement syntax
SurrealQL Syntax
ALTER USER [ IF EXISTS ] @name
ON [ ROOT | NAMESPACE | DATABASE ]
[ PASSWORD @pass | PASSHASH @hash ]
[ ROLES @role, ... ]
[ DURATION FOR TOKEN [ @duration | NONE ] ]
[ DURATION FOR SESSION [ @duration | NONE ] ]
[ COMMENT @string | DROP COMMENT ]
export const alterAst = { type: "Diagram", padding: [10, 20, 10, 20], children: [ { type: "Sequence", children: [ { type: "Terminal", text: "ALTER USER" }, { type: "Optional", child: { type: "Sequence", children: [ { type: "Terminal", text: "IF" }, { type: "Terminal", text: "EXISTS" }, ], }, }, { type: "Terminal", text: "@name" }, { type: "Terminal", text: "ON" }, { type: "Choice", index: 0, children: [ { type: "Terminal", text: "ROOT" }, { type: "Terminal", text: "NAMESPACE" }, { type: "Terminal", text: "DATABASE" }, ], }, { type: "Optional", child: { type: "Choice", index: 0, children: [ { type: "Sequence", children: [ { type: "Terminal", text: "PASSWORD" }, { type: "NonTerminal", text: "@pass" }, ], }, { type: "Sequence", children: [ { type: "Terminal", text: "PASSHASH" }, { type: "NonTerminal", text: "@hash" }, ], }, ], }, }, { type: "Optional", child: { type: "Sequence", children: [ { type: "Terminal", text: "ROLES" }, { type: "NonTerminal", text: "@role" }, { type: "ZeroOrMore", child: { type: "Sequence", children: [ { type: "Terminal", text: "," }, { type: "NonTerminal", text: "@role" }, ], }, repeat: { type: "Skip" }, }, ], }, }, { type: "Optional", child: { type: "Sequence", children: [ { type: "Terminal", text: "DURATION" }, { type: "Terminal", text: "FOR" }, { type: "Terminal", text: "TOKEN" }, { type: "Choice", index: 0, children: [ { type: "NonTerminal", text: "@duration" }, { type: "Terminal", text: "NONE" }, ], }, ], }, }, { type: "Optional", child: { type: "Sequence", children: [ { type: "Terminal", text: "DURATION" }, { type: "Terminal", text: "FOR" }, { type: "Terminal", text: "SESSION" }, { type: "Choice", index: 0, children: [ { type: "NonTerminal", text: "@duration" }, { type: "Terminal", text: "NONE" }, ], }, ], }, }, { type: "Optional", child: { type: "Choice", index: 0, children: [ { type: "Sequence", children: [ { type: "Terminal", text: "COMMENT" }, { type: "Terminal", text: "@string" }, ], }, { type: "Sequence", children: [ { type: "Terminal", text: "DROP" }, { type: "Terminal", text: "COMMENT" }, ], }, ], }, }, ], }, ], };
Example usage
-- Define a user with viewer role
DEFINE USER billy ON DATABASE PASSWORD "example" ROLES VIEWER;
-- Congrats on your promotion billy,
-- be sure to use this power for good
ALTER USER billy ON DATABASE ROLES EDITOR;