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.
<label>;
<interface_definition> from <type_label>;
<@annotation> from <type_label_or_interface>;
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
-
relates … from
statements undefine existing relates and role types. -
as … from relates
statements undefine existing relates specializations. -
plays … from
statements undefine existing roleplayings. -
owns … from
statements undefine existing ownerships. -
value … from
statements undefine existing attribute types' value types. -
sub … from
statements undefine existing subtyping connections. -
@annotation … from
statements undefine existing annotations. Only the type of the annotation is required, so annotations with arguments can be undefined without their arguments specification. -
fun …
statements undefine existing functions.
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
#!test[schema, rollback]
undefine user;
#!test[schema, rollback]
undefine fathership; email;
Undefining interfaces
#!test[schema]
undefine relates child from parentship;
#!test[schema]
undefine as parent from fathership relates father;
#!test[schema]
# Note, this requires the specialisation to have been undefined first.
undefine sub parentship from fathership;
#!test[schema]
undefine plays parentship:parent from user;
#!test[schema, fail_at=runtime]
undefine value string from email;
#!test[schema, rollback]
undefine owns email from user;
Undefining annotations
#!test[schema]
undefine @abstract from parentship;
#!test[schema]
undefine @regex from email value string;
#!test[schema]
undefine
@card from user owns email;
@independent from email;