-- @suaveplan/api-plugin-events — SurrealDB schema -- -- This migration ships a slimmed-down version of the upstream -- `event.surql` covering only the tables the repositories actually -- read / write. The upstream PERMISSIONS rules, stored helper -- functions, and the `event_update` table are scoped out per -- `openspec/changes/add-api-plugin-events/proposal.md` because they -- transitively depend on sibling plugins (site, group, notifications, -- bitwise) that have not yet been migrated to genesis. Permission -- enforcement lives at the route / repository layer in the meantime. -- Event Table DEFINE TABLE OVERWRITE event SCHEMAFULL; DEFINE FIELD OVERWRITE title ON event TYPE string ASSERT $value != NONE AND string::len(string::trim($value)) > 0; DEFINE FIELD OVERWRITE description ON event TYPE option; DEFINE FIELD OVERWRITE creator ON event TYPE record ASSERT $value != NONE; DEFINE FIELD OVERWRITE location ON event TYPE option; DEFINE FIELD OVERWRITE location.name ON event TYPE option; DEFINE FIELD OVERWRITE location.address ON event TYPE option; DEFINE FIELD OVERWRITE location.coordinates ON event TYPE option; DEFINE FIELD OVERWRITE location.coordinates.lat ON event TYPE option; DEFINE FIELD OVERWRITE location.coordinates.lng ON event TYPE option; DEFINE FIELD OVERWRITE start_time ON event TYPE datetime ASSERT $value != NONE; DEFINE FIELD OVERWRITE end_time ON event TYPE datetime ASSERT $value != NONE AND $value > start_time; DEFINE FIELD OVERWRITE timezone ON event TYPE string DEFAULT 'UTC'; DEFINE FIELD OVERWRITE status ON event TYPE int ASSERT $value != NONE AND $value >= 0 AND $value <= 2 DEFAULT 1; DEFINE FIELD OVERWRITE attendee_count ON event TYPE object; DEFINE FIELD OVERWRITE attendee_count.going ON event TYPE int DEFAULT 0; DEFINE FIELD OVERWRITE attendee_count.maybe ON event TYPE int DEFAULT 0; DEFINE FIELD OVERWRITE attendee_count.invited ON event TYPE int DEFAULT 0; DEFINE FIELD OVERWRITE created_at ON event TYPE datetime VALUE time::now(); DEFINE FIELD OVERWRITE updated_at ON event TYPE datetime VALUE time::now(); -- Event RSVP Table DEFINE TABLE OVERWRITE event_rsvp SCHEMAFULL; DEFINE FIELD OVERWRITE event ON event_rsvp TYPE record ASSERT $value != NONE; DEFINE FIELD OVERWRITE user ON event_rsvp TYPE record ASSERT $value != NONE; DEFINE FIELD OVERWRITE status ON event_rsvp TYPE string ASSERT $value INSIDE ['invited', 'going', 'maybe', 'not_going'] DEFAULT 'invited'; DEFINE FIELD OVERWRITE created_at ON event_rsvp TYPE datetime VALUE time::now(); DEFINE FIELD OVERWRITE updated_at ON event_rsvp TYPE datetime VALUE time::now(); -- Indexes DEFINE INDEX OVERWRITE event_start_idx ON event FIELDS start_time; DEFINE INDEX OVERWRITE event_rsvp_unique_idx ON event_rsvp FIELDS event, user UNIQUE;