use sea_orm::entity::prelude::*;
use super::state::WorkerState;
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)]
#[sea_orm(table_name = "workers")]
pub struct Model {
#[sea_orm(primary_key)]
pub id: i64,
#[sea_orm(unique)]
pub worker_id: Uuid,
pub creator_id: i64,
pub tags: Vec<String>,
pub labels: Vec<String>,
pub created_at: TimeDateTimeWithTimeZone,
pub updated_at: TimeDateTimeWithTimeZone,
pub state: WorkerState,
pub last_heartbeat: TimeDateTimeWithTimeZone,
pub assigned_task_id: Option<i64>,
}
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {
#[sea_orm(has_many = "super::group_worker::Entity")]
GroupWorker,
#[sea_orm(
belongs_to = "super::users::Entity",
from = "Column::CreatorId",
to = "super::users::Column::Id",
on_update = "Cascade",
on_delete = "Restrict"
)]
Users,
}
impl Related<super::group_worker::Entity> for Entity {
fn to() -> RelationDef {
Relation::GroupWorker.def()
}
}
impl Related<super::users::Entity> for Entity {
fn to() -> RelationDef {
Relation::Users.def()
}
}
impl ActiveModelBehavior for ActiveModel {}