USE NAMESPACE noteboek;
USE DATABASE noteboek;

DEFINE TABLE user SCHEMAFULL;
DEFINE FIELD email ON TABLE user TYPE string VALUE string::lowercase($value) ASSERT string::is::email($value);
DEFINE FIELD username ON TABLE user TYPE string;
DEFINE FIELD password ON TABLE user TYPE string;
DEFINE INDEX unique_email ON TABLE user COLUMNS email UNIQUE;

DEFINE TABLE permission SCHEMAFULL;
DEFINE FIELD aspect ON TABLE permission TYPE string;
DEFINE FIELD subject ON TABLE permission TYPE option<record>;

DEFINE TABLE group SCHEMAFULL;
DEFINE FIELD description ON TABLE group TYPE string;

DEFINE TABLE member_of SCHEMAFULL;
DEFINE FIELD in ON TABLE member_of TYPE record<user>;
DEFINE FIELD out ON TABLE member_of TYPE record<group>;

DEFINE TABLE granted SCHEMAFULL;
DEFINE FIELD in ON TABLE granted TYPE record<user | group>;
DEFINE FIELD out ON TABLE granted TYPE record<permission>;