1.7 KiB · text History 263b40b
use sea_orm::entity::prelude::*;
use serde::{Deserialize, Serialize};

#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Serialize, Deserialize)]
#[sea_orm(table_name = "post_revisions")]
pub struct Model {
    #[sea_orm(primary_key, auto_increment = false)]
    pub id: Uuid,
    pub post_id: Uuid,
    /// Who authored this version (None if that user was later deleted).
    pub editor_id: Option<Uuid>,
    /// 1-based; revision 1 is the original.
    pub revision_number: i32,
    #[sea_orm(column_type = "Text")]
    pub raw: String,
    #[sea_orm(column_type = "Text")]
    pub cooked: String,
    pub created_at: DateTimeWithTimeZone,
    /// `edit` (including revision 1), `moderation` (a staff note replaced
    /// the body) or `restore` (staff put the pre-moderation body back).
    pub kind: String,
    /// Staff hid this version's content from non-staff.
    pub hidden_at: Option<DateTimeWithTimeZone>,
    pub hidden_by_id: Option<Uuid>,
}

#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {
    #[sea_orm(
        belongs_to = "super::posts::Entity",
        from = "Column::PostId",
        to = "super::posts::Column::Id",
        on_update = "Cascade",
        on_delete = "Cascade"
    )]
    Posts,
    #[sea_orm(
        belongs_to = "super::users::Entity",
        from = "Column::EditorId",
        to = "super::users::Column::Id",
        on_update = "Cascade",
        on_delete = "SetNull"
    )]
    Users,
}

impl Related<super::posts::Entity> for Entity {
    fn to() -> RelationDef {
        Relation::Posts.def()
    }
}

impl Related<super::users::Entity> for Entity {
    fn to() -> RelationDef {
        Relation::Users.def()
    }
}

impl ActiveModelBehavior for ActiveModel {}