Skip to content
Clone
194c44c
57 lines 1.6 KB Rust
use sea_orm::entity::prelude::*;
use serde::{Deserialize, Serialize};
use time::OffsetDateTime;
use uuid::Uuid;
/// Upload lifecycle: a row is created before the bytes exist (`Pending`) and
/// only an `Uploaded` row may be referenced by an issue.
#[derive(
Debug,
Clone,
Copy,
PartialEq,
Eq,
Default,
EnumIter,
DeriveActiveEnum,
Serialize,
Deserialize,
utoipa::ToSchema,
)]
#[serde(rename_all = "snake_case")]
#[sea_orm(rs_type = "i16", db_type = "SmallInteger")]
pub enum IssueAttachmentStatus {
#[default]
#[sea_orm(num_value = 0)]
Pending,
#[sea_orm(num_value = 1)]
Uploaded,
}
#[sea_orm::model]
#[derive(Clone, Debug, PartialEq, Eq, DeriveEntityModel)]
#[sea_orm(table_name = "issue_attachment")]
pub struct Model {
#[sea_orm(primary_key, auto_increment = false)]
pub id: Uuid,
/// `None` while the upload belongs to a draft the caller has not submitted.
#[sea_orm(indexed)]
pub issue_id: Option<Uuid>,
#[sea_orm(indexed)]
pub uploader_id: i64,
pub filename: String,
pub content_type: String,
pub size: i64,
pub bucket: String,
pub s3_key: String,
#[sea_orm(default_value = 0)]
pub status: IssueAttachmentStatus,
pub created_at: OffsetDateTime,
pub updated_at: OffsetDateTime,
#[sea_orm(belongs_to, from = "issue_id", to = "id")]
pub issue: BelongsTo<Option<super::issue_item::Entity>>,
#[sea_orm(belongs_to, from = "uploader_id", to = "uid")]
pub uploader: BelongsTo<super::super::users::user::Entity>,
}
impl ActiveModelBehavior for ActiveModel {}