-- Device token table — slimmed migration. Stores APN / FCM / WebPush -- device tokens for push delivery. Upstream stored-helper-functions -- and cross-plugin record refs are deferred until those sibling -- plugins land on genesis (see openspec/changes/add-api-plugin-notifications). DEFINE TABLE OVERWRITE device_token SCHEMAFULL; DEFINE FIELD OVERWRITE user_id ON device_token TYPE record ASSERT $value != NONE; DEFINE FIELD OVERWRITE site ON device_token TYPE option>; DEFINE FIELD OVERWRITE device_id ON device_token TYPE string ASSERT $value != NONE AND string::len($value) > 0 AND string::len($value) <= 255; DEFINE FIELD OVERWRITE token ON device_token TYPE string ASSERT $value != NONE AND string::len($value) > 0 AND string::len($value) <= 1000; DEFINE FIELD OVERWRITE platform ON device_token TYPE string ASSERT $value INSIDE ['ios', 'android', 'web'] DEFAULT 'ios'; DEFINE FIELD OVERWRITE environment ON device_token TYPE string ASSERT $value INSIDE ['production', 'sandbox', 'development'] DEFAULT 'sandbox'; DEFINE FIELD OVERWRITE app_version ON device_token TYPE option; DEFINE FIELD OVERWRITE os_version ON device_token TYPE option; DEFINE FIELD OVERWRITE is_active ON device_token TYPE bool DEFAULT true; DEFINE FIELD OVERWRITE last_used ON device_token TYPE datetime DEFAULT time::now() VALUE time::now(); DEFINE FIELD OVERWRITE created_at ON device_token TYPE datetime DEFAULT time::now() VALUE $before OR time::now(); DEFINE FIELD OVERWRITE updated_at ON device_token TYPE datetime DEFAULT time::now() VALUE time::now(); DEFINE INDEX OVERWRITE device_token_user_idx ON device_token FIELDS user_id; DEFINE INDEX OVERWRITE device_token_token_idx ON device_token FIELDS token UNIQUE; DEFINE INDEX OVERWRITE device_token_active_idx ON device_token FIELDS is_active; DEFINE INDEX OVERWRITE device_token_platform_idx ON device_token FIELDS platform;