Undefine query

Undefine queries are used to remove existing types, constraints, or functions from the schema.

Syntax

Undefine queries start with the undefine keyword following by undefinition statements.

undefine
  <undefinition_statements>

Undefinition statements are similar to definition statements, but they have a different structure to highlight which part of the definition is to be undefined, in some cases using the from keyword.

Type undefinition statement
<label>;
interface undefinition statement
<interface_definition> from <type_label>;
Annotation undefinition statement
<@annotation> from <type_label_or_interface>;
Function undefinition statement
fun <function name>;

Statements should be separated by semicolons. Schema statements in an undefine query cannot use variables or values.

Behavior

An undefine query removes the parts of the schema specified in its undefine clause, including types, interfaces, annotations, and functions. Undefining a type also undefines all its interfaces and annotations. Undefining a interface also undefines all its interfaces and annotations.

An error is returned (on execution or on commit), and no changes are preserved, if:

  • There is no existing definition to undefine.

  • The query results in an invalid schema.

Statements

Examples

Schema for the following examples
#!test[schema, commit]
define
  entity content owns id;
  entity page sub content,
    owns page-id,
    owns name;
  entity profile sub page,
    owns username;
  entity user sub profile,
    owns phone,
    owns karma;

  attribute id value string;
  attribute page-id sub id;
  attribute username sub page-id;
  attribute name value string;
  attribute phone value string;
  attribute karma value double;
attribute bio value string;
attribute profile-picture value string;
attribute email @independent, value string @regex("^.*@.*\.com");
user owns bio, owns profile-picture;
attribute tag value string;
entity post owns tag @card(0..);
relation parentship @abstract, relates parent, relates child;
relation fathership sub parentship, relates father as parent;
user plays parentship:parent;
user owns email @card(0..1);

Undefining types

Undefining a type
#!test[schema, rollback]
undefine user;
Undefining types
#!test[schema, rollback]
undefine fathership; email;

Undefining interfaces

Undefining relation type’s relates
#!test[schema]
undefine relates child from parentship;
Undefining relates specialization
#!test[schema]
undefine as parent from fathership relates father;
Undefining relation type’s subtyping
#!test[schema]
# Note, this requires the specialisation to have been undefined first.
undefine sub parentship from fathership;
Undefining type’s roleplaying
#!test[schema]
undefine plays parentship:parent from user;
Undefining attribute type’s value type
#!test[schema, fail_at=runtime]
undefine value string from email;
Undefining type’s ownership
#!test[schema, rollback]
undefine owns email from user;

Undefining annotations

Undefining type’s annotation without arguments
#!test[schema]
undefine @abstract from parentship;
Undefining value type’s annotation with arguments
#!test[schema]
undefine @regex from email value string;
Undefining type’s and type’s ownership’s annotations
#!test[schema]
undefine
  @card from user owns email;
  @independent from email;

Undefining functions

To undefine a function, specify the fun keyword and its name.

#!test[schema]
undefine
  fun karma_with_squared_value;