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/access_to_queue.rs | 46 ++++++++++++++++++++++++++++++++++ entity/src/lib.rs | 9 +++++++ entity/src/prelude.rs | 6 +++++ entity/src/queue_elements.rs | 50 +++++++++++++++++++++++++++++++++++++ entity/src/queues.rs | 51 ++++++++++++++++++++++++++++++++++++++ entity/src/sea_orm_active_enums.rs | 16 ++++++++++++ entity/src/users.rs | 49 ++++++++++++++++++++++++++++++++++++ 7 files changed, 227 insertions(+) create mode 100644 entity/src/access_to_queue.rs create mode 100644 entity/src/lib.rs create mode 100644 entity/src/prelude.rs create mode 100644 entity/src/queue_elements.rs create mode 100644 entity/src/queues.rs create mode 100644 entity/src/sea_orm_active_enums.rs create mode 100644 entity/src/users.rs (limited to 'entity/src') diff --git a/entity/src/access_to_queue.rs b/entity/src/access_to_queue.rs new file mode 100644 index 0000000..9de03d5 --- /dev/null +++ b/entity/src/access_to_queue.rs @@ -0,0 +1,46 @@ +//! `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 = "access_to_queue")] +pub struct Model { + #[sea_orm(primary_key, auto_increment = false)] + pub user_id: i64, + #[sea_orm(primary_key, auto_increment = false)] + pub queue_id: i64, +} + +#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] +pub enum Relation { + #[sea_orm( + belongs_to = "super::queues::Entity", + from = "Column::QueueId", + to = "super::queues::Column::Id", + on_update = "Cascade", + on_delete = "Cascade" + )] + Queues, + #[sea_orm( + belongs_to = "super::users::Entity", + from = "Column::UserId", + to = "super::users::Column::Id", + on_update = "Cascade", + on_delete = "Cascade" + )] + Users, +} + +impl Related for Entity { + fn to() -> RelationDef { + Relation::Queues.def() + } +} + +impl Related for Entity { + fn to() -> RelationDef { + Relation::Users.def() + } +} + +impl ActiveModelBehavior for ActiveModel {} diff --git a/entity/src/lib.rs b/entity/src/lib.rs new file mode 100644 index 0000000..1ca05d6 --- /dev/null +++ b/entity/src/lib.rs @@ -0,0 +1,9 @@ +//! `SeaORM` Entity, @generated by sea-orm-codegen 1.1.14 + +pub mod prelude; + +pub mod access_to_queue; +pub mod queue_elements; +pub mod queues; +pub mod sea_orm_active_enums; +pub mod users; diff --git a/entity/src/prelude.rs b/entity/src/prelude.rs new file mode 100644 index 0000000..60f72f9 --- /dev/null +++ b/entity/src/prelude.rs @@ -0,0 +1,6 @@ +//! `SeaORM` Entity, @generated by sea-orm-codegen 1.1.14 + +pub use super::access_to_queue::Entity as AccessToQueue; +pub use super::queue_elements::Entity as QueueElements; +pub use super::queues::Entity as Queues; +pub use super::users::Entity as Users; diff --git a/entity/src/queue_elements.rs b/entity/src/queue_elements.rs new file mode 100644 index 0000000..7002da1 --- /dev/null +++ b/entity/src/queue_elements.rs @@ -0,0 +1,50 @@ +//! `SeaORM` Entity, @generated by sea-orm-codegen 1.1.14 + +use super::sea_orm_active_enums::QueueElementStatusEnum; +use sea_orm::entity::prelude::*; + +#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)] +#[sea_orm(table_name = "queue_elements")] +pub struct Model { + #[sea_orm(primary_key)] + pub id: i64, + pub queue_id: i64, + pub user_id: i64, + #[sea_orm(unique)] + pub position: i64, + pub status: QueueElementStatusEnum, +} + +#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] +pub enum Relation { + #[sea_orm( + belongs_to = "super::queues::Entity", + from = "Column::QueueId", + to = "super::queues::Column::Id", + on_update = "Cascade", + on_delete = "Cascade" + )] + Queues, + #[sea_orm( + belongs_to = "super::users::Entity", + from = "Column::UserId", + to = "super::users::Column::Id", + on_update = "Cascade", + on_delete = "Cascade" + )] + Users, +} + +impl Related for Entity { + fn to() -> RelationDef { + Relation::Queues.def() + } +} + +impl Related for Entity { + fn to() -> RelationDef { + Relation::Users.def() + } +} + +impl ActiveModelBehavior for ActiveModel {} 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 {} diff --git a/entity/src/sea_orm_active_enums.rs b/entity/src/sea_orm_active_enums.rs new file mode 100644 index 0000000..2252a9f --- /dev/null +++ b/entity/src/sea_orm_active_enums.rs @@ -0,0 +1,16 @@ +//! `SeaORM` Entity, @generated by sea-orm-codegen 1.1.14 + +use sea_orm::entity::prelude::*; + +#[derive(Debug, Clone, PartialEq, Eq, EnumIter, DeriveActiveEnum)] +#[sea_orm( + rs_type = "String", + db_type = "Enum", + enum_name = "queue_element_status_enum" +)] +pub enum QueueElementStatusEnum { + #[sea_orm(string_value = "passed")] + Passed, + #[sea_orm(string_value = "waiting")] + Waiting, +} diff --git a/entity/src/users.rs b/entity/src/users.rs new file mode 100644 index 0000000..b61d51b --- /dev/null +++ b/entity/src/users.rs @@ -0,0 +1,49 @@ +//! `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 = "users")] +pub struct Model { + #[sea_orm(primary_key)] + pub id: i64, + #[sea_orm(unique)] + pub login: String, + pub password: String, + pub password_issue_date: DateTime, + pub first_name: String, + pub last_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(has_many = "super::queues::Entity")] + Queues, +} + +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::Queues.def() + } + fn via() -> Option { + Some(super::access_to_queue::Relation::Users.def().rev()) + } +} + +impl ActiveModelBehavior for ActiveModel {} -- cgit v1.3