The Designer view inside Surrealist is able to show the link between the town
and place
tables, but the other regular tables and graph tables are just floating around on top. You can experiment for yourself by pasting all of our queries so far into Surrealist, which should give you the following view.
At the moment, the relation tables in particular are vulnerable because they have not been defined as relation tables. Without this definition, a regular works_at
table could be created and the database would accept it.
CREATE works_at SET name = ...
This can be fixed by using DEFINE TABLE
along with three clauses:
TYPE RELATION
to ensure that it can only be used as a graph table,IN record_name OUT record_name
to set the record types that can be used, andOVERWRITE
after DEFINE TABLE
, because currently the existing tables are defined as schemaless, non-relation tables. Without OVERWRITE
, the database will return an error saying that the table already exists.Since we have four graph relations set up, four DEFINE TABLE
statements will be enough to improve the schema output.
DEFINE TABLE OVERWRITE works_at TYPE RELATION IN person OUT place; DEFINE TABLE OVERWRITE wrote TYPE RELATION IN person OUT book; DEFINE TABLE OVERWRITE has TYPE RELATION IN place OUT book; DEFINE TABLE OVERWRITE customer_of TYPE RELATION IN person OUT place;
Surrealist is now able to say for sure that these tables are used for relations, which allows all the types inside the schema to be joined together.