From dc33fa8416ce6b447494c6efdf46518da37ac1cc Mon Sep 17 00:00:00 2001 From: Tolmachev Igor Date: Tue, 26 Aug 2025 21:13:53 +0900 Subject: Add database migration and entities --- entity/src/queues.rs | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 entity/src/queues.rs (limited to 'entity/src/queues.rs') diff --git a/entity/src/queues.rs b/entity/src/queues.rs new file mode 100644 index 0000000..34b358a --- /dev/null +++ b/entity/src/queues.rs @@ -0,0 +1,51 @@ +//! `SeaORM` Entity, @generated by sea-orm-codegen 1.1.14 + +use sea_orm::entity::prelude::*; + +#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)] +#[sea_orm(table_name = "queues")] +pub struct Model { + #[sea_orm(primary_key)] + pub id: i64, + pub owner_id: i64, + pub name: String, +} + +#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] +pub enum Relation { + #[sea_orm(has_many = "super::access_to_queue::Entity")] + AccessToQueue, + #[sea_orm(has_many = "super::queue_elements::Entity")] + QueueElements, + #[sea_orm( + belongs_to = "super::users::Entity", + from = "Column::OwnerId", + to = "super::users::Column::Id", + on_update = "Cascade", + on_delete = "Cascade" + )] + Users, +} + +impl Related for Entity { + fn to() -> RelationDef { + Relation::AccessToQueue.def() + } +} + +impl Related for Entity { + fn to() -> RelationDef { + Relation::QueueElements.def() + } +} + +impl Related for Entity { + fn to() -> RelationDef { + super::access_to_queue::Relation::Users.def() + } + fn via() -> Option { + Some(super::access_to_queue::Relation::Queues.def().rev()) + } +} + +impl ActiveModelBehavior for ActiveModel {} -- cgit v1.2.3