use sea_orm::entity::Set; use sea_orm::entity::prelude::*; use uuid::Uuid; #[sea_orm::model] #[derive(Clone, Debug, PartialEq, Eq, DeriveEntityModel)] #[sea_orm(table_name = "space_join_rules")] pub struct Model { #[sea_orm(primary_key, auto_increment = false)] pub id: Uuid, #[sea_orm(unique_key = "org_role_trigger_matcher")] pub organization_id: Uuid, #[sea_orm(unique_key = "org_role_trigger_matcher")] pub role_id: Uuid, #[sea_orm( unique_key = "org_role_trigger_matcher", column_type = "String(StringLen::N(32))" )] pub trigger: String, #[sea_orm( unique_key = "org_role_trigger_matcher", column_type = "String(StringLen::N(255))" )] pub matcher: String, #[sea_orm(default_value = true)] pub enabled: bool, #[sea_orm(default_expr = "Expr::current_timestamp()")] pub created_at: DateTimeUtc, #[sea_orm(default_expr = "Expr::current_timestamp()")] pub updated_at: DateTimeUtc, #[sea_orm(belongs_to, from = "organization_id", to = "id", on_delete = "Cascade")] pub organization: BelongsTo, } #[async_trait::async_trait] impl ActiveModelBehavior for ActiveModel { async fn before_save(mut self, _db: &C, insert: bool) -> Result where C: ConnectionTrait, { if insert && self.id.is_not_set() { self.id = Set(Uuid::now_v7()); } self.updated_at = Set(chrono::Utc::now()); Ok(self) } }