809 B · text History 02765fe
use sea_orm::entity::prelude::*;
use serde::{Deserialize, Serialize};

/// A long-lived API token; see `crate::auth::api_tokens`. The token itself
/// is never stored, only its hash.
#[derive(Clone, Debug, PartialEq, Eq, DeriveEntityModel, Serialize, Deserialize)]
#[sea_orm(table_name = "api_tokens")]
pub struct Model {
    #[sea_orm(primary_key, auto_increment = false)]
    pub id: Uuid,
    pub user_id: Uuid,
    #[serde(skip)]
    #[sea_orm(unique)]
    pub token_hash: String,
    pub prefix: String,
    pub label: Option<String>,
    pub last_used_at: Option<DateTimeWithTimeZone>,
    pub expires_at: Option<DateTimeWithTimeZone>,
    pub created_at: DateTimeWithTimeZone,
}

#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {}

impl ActiveModelBehavior for ActiveModel {}