diff options
| author | Tolmachev Igor <me@igorek.dev> | 2025-08-26 21:13:53 +0900 |
|---|---|---|
| committer | Tolmachev Igor <me@igorek.dev> | 2025-08-26 21:13:53 +0900 |
| commit | dc33fa8416ce6b447494c6efdf46518da37ac1cc (patch) | |
| tree | 6bf069f70c953f14b3a7e84ed4a7bbcde3de7012 /entity/src | |
| parent | 9cb5689c87978c4e05e87f631ebf92a626d583b0 (diff) | |
| download | queue_server-dc33fa8416ce6b447494c6efdf46518da37ac1cc.tar.gz queue_server-dc33fa8416ce6b447494c6efdf46518da37ac1cc.zip | |
Add database migration and entities
Diffstat (limited to 'entity/src')
| -rw-r--r-- | entity/src/access_to_queue.rs | 46 | ||||
| -rw-r--r-- | entity/src/lib.rs | 9 | ||||
| -rw-r--r-- | entity/src/prelude.rs | 6 | ||||
| -rw-r--r-- | entity/src/queue_elements.rs | 50 | ||||
| -rw-r--r-- | entity/src/queues.rs | 51 | ||||
| -rw-r--r-- | entity/src/sea_orm_active_enums.rs | 16 | ||||
| -rw-r--r-- | entity/src/users.rs | 49 |
7 files changed, 227 insertions, 0 deletions
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 @@ | |||
| 1 | //! `SeaORM` Entity, @generated by sea-orm-codegen 1.1.14 | ||
| 2 | |||
| 3 | use sea_orm::entity::prelude::*; | ||
| 4 | |||
| 5 | #[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)] | ||
| 6 | #[sea_orm(table_name = "access_to_queue")] | ||
| 7 | pub struct Model { | ||
| 8 | #[sea_orm(primary_key, auto_increment = false)] | ||
| 9 | pub user_id: i64, | ||
| 10 | #[sea_orm(primary_key, auto_increment = false)] | ||
| 11 | pub queue_id: i64, | ||
| 12 | } | ||
| 13 | |||
| 14 | #[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] | ||
| 15 | pub enum Relation { | ||
| 16 | #[sea_orm( | ||
| 17 | belongs_to = "super::queues::Entity", | ||
| 18 | from = "Column::QueueId", | ||
| 19 | to = "super::queues::Column::Id", | ||
| 20 | on_update = "Cascade", | ||
| 21 | on_delete = "Cascade" | ||
| 22 | )] | ||
| 23 | Queues, | ||
| 24 | #[sea_orm( | ||
| 25 | belongs_to = "super::users::Entity", | ||
| 26 | from = "Column::UserId", | ||
| 27 | to = "super::users::Column::Id", | ||
| 28 | on_update = "Cascade", | ||
| 29 | on_delete = "Cascade" | ||
| 30 | )] | ||
| 31 | Users, | ||
| 32 | } | ||
| 33 | |||
| 34 | impl Related<super::queues::Entity> for Entity { | ||
| 35 | fn to() -> RelationDef { | ||
| 36 | Relation::Queues.def() | ||
| 37 | } | ||
| 38 | } | ||
| 39 | |||
| 40 | impl Related<super::users::Entity> for Entity { | ||
| 41 | fn to() -> RelationDef { | ||
| 42 | Relation::Users.def() | ||
| 43 | } | ||
| 44 | } | ||
| 45 | |||
| 46 | 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 @@ | |||
| 1 | //! `SeaORM` Entity, @generated by sea-orm-codegen 1.1.14 | ||
| 2 | |||
| 3 | pub mod prelude; | ||
| 4 | |||
| 5 | pub mod access_to_queue; | ||
| 6 | pub mod queue_elements; | ||
| 7 | pub mod queues; | ||
| 8 | pub mod sea_orm_active_enums; | ||
| 9 | 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 @@ | |||
| 1 | //! `SeaORM` Entity, @generated by sea-orm-codegen 1.1.14 | ||
| 2 | |||
| 3 | pub use super::access_to_queue::Entity as AccessToQueue; | ||
| 4 | pub use super::queue_elements::Entity as QueueElements; | ||
| 5 | pub use super::queues::Entity as Queues; | ||
| 6 | 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 @@ | |||
| 1 | //! `SeaORM` Entity, @generated by sea-orm-codegen 1.1.14 | ||
| 2 | |||
| 3 | use super::sea_orm_active_enums::QueueElementStatusEnum; | ||
| 4 | use sea_orm::entity::prelude::*; | ||
| 5 | |||
| 6 | #[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)] | ||
| 7 | #[sea_orm(table_name = "queue_elements")] | ||
| 8 | pub struct Model { | ||
| 9 | #[sea_orm(primary_key)] | ||
| 10 | pub id: i64, | ||
| 11 | pub queue_id: i64, | ||
| 12 | pub user_id: i64, | ||
| 13 | #[sea_orm(unique)] | ||
| 14 | pub position: i64, | ||
| 15 | pub status: QueueElementStatusEnum, | ||
| 16 | } | ||
| 17 | |||
| 18 | #[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] | ||
| 19 | pub enum Relation { | ||
| 20 | #[sea_orm( | ||
| 21 | belongs_to = "super::queues::Entity", | ||
| 22 | from = "Column::QueueId", | ||
| 23 | to = "super::queues::Column::Id", | ||
| 24 | on_update = "Cascade", | ||
| 25 | on_delete = "Cascade" | ||
| 26 | )] | ||
| 27 | Queues, | ||
| 28 | #[sea_orm( | ||
| 29 | belongs_to = "super::users::Entity", | ||
| 30 | from = "Column::UserId", | ||
| 31 | to = "super::users::Column::Id", | ||
| 32 | on_update = "Cascade", | ||
| 33 | on_delete = "Cascade" | ||
| 34 | )] | ||
| 35 | Users, | ||
| 36 | } | ||
| 37 | |||
| 38 | impl Related<super::queues::Entity> for Entity { | ||
| 39 | fn to() -> RelationDef { | ||
| 40 | Relation::Queues.def() | ||
| 41 | } | ||
| 42 | } | ||
| 43 | |||
| 44 | impl Related<super::users::Entity> for Entity { | ||
| 45 | fn to() -> RelationDef { | ||
| 46 | Relation::Users.def() | ||
| 47 | } | ||
| 48 | } | ||
| 49 | |||
| 50 | 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 @@ | |||
| 1 | //! `SeaORM` Entity, @generated by sea-orm-codegen 1.1.14 | ||
| 2 | |||
| 3 | use sea_orm::entity::prelude::*; | ||
| 4 | |||
| 5 | #[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)] | ||
| 6 | #[sea_orm(table_name = "queues")] | ||
| 7 | pub struct Model { | ||
| 8 | #[sea_orm(primary_key)] | ||
| 9 | pub id: i64, | ||
| 10 | pub owner_id: i64, | ||
| 11 | pub name: String, | ||
| 12 | } | ||
| 13 | |||
| 14 | #[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] | ||
| 15 | pub enum Relation { | ||
| 16 | #[sea_orm(has_many = "super::access_to_queue::Entity")] | ||
| 17 | AccessToQueue, | ||
| 18 | #[sea_orm(has_many = "super::queue_elements::Entity")] | ||
| 19 | QueueElements, | ||
| 20 | #[sea_orm( | ||
| 21 | belongs_to = "super::users::Entity", | ||
| 22 | from = "Column::OwnerId", | ||
| 23 | to = "super::users::Column::Id", | ||
| 24 | on_update = "Cascade", | ||
| 25 | on_delete = "Cascade" | ||
| 26 | )] | ||
| 27 | Users, | ||
| 28 | } | ||
| 29 | |||
| 30 | impl Related<super::access_to_queue::Entity> for Entity { | ||
| 31 | fn to() -> RelationDef { | ||
| 32 | Relation::AccessToQueue.def() | ||
| 33 | } | ||
| 34 | } | ||
| 35 | |||
| 36 | impl Related<super::queue_elements::Entity> for Entity { | ||
| 37 | fn to() -> RelationDef { | ||
| 38 | Relation::QueueElements.def() | ||
| 39 | } | ||
| 40 | } | ||
| 41 | |||
| 42 | impl Related<super::users::Entity> for Entity { | ||
| 43 | fn to() -> RelationDef { | ||
| 44 | super::access_to_queue::Relation::Users.def() | ||
| 45 | } | ||
| 46 | fn via() -> Option<RelationDef> { | ||
| 47 | Some(super::access_to_queue::Relation::Queues.def().rev()) | ||
| 48 | } | ||
| 49 | } | ||
| 50 | |||
| 51 | 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 @@ | |||
| 1 | //! `SeaORM` Entity, @generated by sea-orm-codegen 1.1.14 | ||
| 2 | |||
| 3 | use sea_orm::entity::prelude::*; | ||
| 4 | |||
| 5 | #[derive(Debug, Clone, PartialEq, Eq, EnumIter, DeriveActiveEnum)] | ||
| 6 | #[sea_orm( | ||
| 7 | rs_type = "String", | ||
| 8 | db_type = "Enum", | ||
| 9 | enum_name = "queue_element_status_enum" | ||
| 10 | )] | ||
| 11 | pub enum QueueElementStatusEnum { | ||
| 12 | #[sea_orm(string_value = "passed")] | ||
| 13 | Passed, | ||
| 14 | #[sea_orm(string_value = "waiting")] | ||
| 15 | Waiting, | ||
| 16 | } | ||
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 @@ | |||
| 1 | //! `SeaORM` Entity, @generated by sea-orm-codegen 1.1.14 | ||
| 2 | |||
| 3 | use sea_orm::entity::prelude::*; | ||
| 4 | |||
| 5 | #[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)] | ||
| 6 | #[sea_orm(table_name = "users")] | ||
| 7 | pub struct Model { | ||
| 8 | #[sea_orm(primary_key)] | ||
| 9 | pub id: i64, | ||
| 10 | #[sea_orm(unique)] | ||
| 11 | pub login: String, | ||
| 12 | pub password: String, | ||
| 13 | pub password_issue_date: DateTime, | ||
| 14 | pub first_name: String, | ||
| 15 | pub last_name: String, | ||
| 16 | } | ||
| 17 | |||
| 18 | #[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] | ||
| 19 | pub enum Relation { | ||
| 20 | #[sea_orm(has_many = "super::access_to_queue::Entity")] | ||
| 21 | AccessToQueue, | ||
| 22 | #[sea_orm(has_many = "super::queue_elements::Entity")] | ||
| 23 | QueueElements, | ||
| 24 | #[sea_orm(has_many = "super::queues::Entity")] | ||
| 25 | Queues, | ||
| 26 | } | ||
| 27 | |||
| 28 | impl Related<super::access_to_queue::Entity> for Entity { | ||
| 29 | fn to() -> RelationDef { | ||
| 30 | Relation::AccessToQueue.def() | ||
| 31 | } | ||
| 32 | } | ||
| 33 | |||
| 34 | impl Related<super::queue_elements::Entity> for Entity { | ||
| 35 | fn to() -> RelationDef { | ||
| 36 | Relation::QueueElements.def() | ||
| 37 | } | ||
| 38 | } | ||
| 39 | |||
| 40 | impl Related<super::queues::Entity> for Entity { | ||
| 41 | fn to() -> RelationDef { | ||
| 42 | super::access_to_queue::Relation::Queues.def() | ||
| 43 | } | ||
| 44 | fn via() -> Option<RelationDef> { | ||
| 45 | Some(super::access_to_queue::Relation::Users.def().rev()) | ||
| 46 | } | ||
| 47 | } | ||
| 48 | |||
| 49 | impl ActiveModelBehavior for ActiveModel {} | ||
