Undefine query

An Undefine query removes type and rule definition from a schema.

Undefine queries can be used only in a schema session and write transaction. For more information on the limitations of a schema session, see the Schema integrity enforcement.

For more information about basics of data modeling with TypeQL, see the Fundamentals page.

Behavior

A Undefine query deletes existing types and rules.

An undefine clause uses without variables to declare a piece of schema to delete.

Undefine queries are validated with TypeQL syntax. A database’s schema is validated after applying a given query to validate its consistency. Undefining a type also undefines all ownerships of attribute types and all roles it could play.

A deleted type must exist in a schema and have neither subtypes nor instances of data. If any subtypes or instances of that type exist in a database, they need to be removed prior to removing the type or in the same query. Undefining the same type definition or rule definition twice will result in an error because of an attempt to remove a non-existent definition from a schema.

Undefine query returns a Promise of an empty response.

Syntax

An Undefine query consists of a single undefine clause and always starts with the undefine keyword.

Undefine queries are written in TypeQL with the following syntax:

undefine <schema statements>

Schema statements in an undefine clause use TypeQL to declare types, type definitions, and rules that need to be removed.

Undefine clause

An undefine clause is used in an Undefine query to specify types and rules to be removed from a schema.

Rules are removed by using the rule keyword and their label. See example.

Types can be removed completely by using the sub keyword with a supertype. It can be a direct supertype, or non-direct, up to a root type.

Alternatively, we can remove some parts of type definition, like an ownership of an attribute type or a role to play.

Examples

The following examples use a database with the IAM schema for Undefine queries.

Undefine a type

Undefining a type example
undefine

validity sub attribute;
change-request sub relation;
operation-set sub entity;
user-role sub user-group;

The above example undefines four types from the IAM schema.

Note that operation-set is not a direct subtype of the entity root type.

Undefine ownership

Undefining ownership
undefine

subject owns credential;

The above query removes an ability for subject type (and all its subtypes) to own a credential attribute type.

Note that the credential type ownership is defined for the subject type. Subtypes of the subject type also inherit the credential ownership, but we can’t undefine it from them because it is not defined for them in a schema.

Undefine a role played

Undefining a role played
undefine

subject plays segregation-violation:subject;

The above query removes the ability for the subject type to play the role of subject in the segregation-violation relation type.

Undefine relation’s role

Undefining role
undefine

segregation-violation relates subject;

The above query removes the role of subject from the segregation-violation relation.

Undefine a rule

Undefining a rule
undefine

rule add-view-permission;

Undefine a type with a subtype

We must first undefine all subtypes of a type, before undefining the type itself. We can use the same query to remove both the supertype and all its subtypes from a schema.

Undefining a type with a subtype
undefine

object sub entity;
resource sub object;

The above query undefines both object and its subtype resource.

If you are using the same query to undefine supertype and all its subtypes, make sure to use the supertype label in the subtype undefine statements (directly right from the sub keyword). Otherwise, the query might fail validation, due to one of the deleted types having subtypes.

Provide Feedback