From 974c8c586e1182d502a2c30ba8b622c0b4033937 Mon Sep 17 00:00:00 2001 From: Tolmachev Igor Date: Sat, 27 Sep 2025 00:03:28 +0300 Subject: Add invite tokens models --- Cargo.toml | 1 + entity/src/invite_tokens.rs | 32 ++++++++++++++++++++++++++++++++ entity/src/lib.rs | 1 + entity/src/prelude.rs | 1 + entity/src/queues.rs | 8 ++++++++ migration/src/m0_init_tables.rs | 27 +++++++++++++++++++++++++++ 6 files changed, 70 insertions(+) create mode 100644 entity/src/invite_tokens.rs diff --git a/Cargo.toml b/Cargo.toml index 4c8f11f..3a07517 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -27,3 +27,4 @@ tracing-subscriber = "0.3.19" utoipa = { version = "5.4.0", features = ["axum_extras", "chrono", "preserve_order", "preserve_path_order"] } utoipa-axum = "0.2.0" utoipa-scalar = { version = "0.3.0", features = ["axum"] } +uuid = { version = "1.18.1", features = ["v4", "serde"] } diff --git a/entity/src/invite_tokens.rs b/entity/src/invite_tokens.rs new file mode 100644 index 0000000..f239567 --- /dev/null +++ b/entity/src/invite_tokens.rs @@ -0,0 +1,32 @@ +//! `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 = "invite_tokens")] +pub struct Model { + #[sea_orm(primary_key)] + pub id: i64, + pub token: Uuid, + 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, +} + +impl Related for Entity { + fn to() -> RelationDef { + Relation::Queues.def() + } +} + +impl ActiveModelBehavior for ActiveModel {} diff --git a/entity/src/lib.rs b/entity/src/lib.rs index 1ca05d6..389846a 100644 --- a/entity/src/lib.rs +++ b/entity/src/lib.rs @@ -3,6 +3,7 @@ pub mod prelude; pub mod access_to_queue; +pub mod invite_tokens; pub mod queue_elements; pub mod queues; pub mod sea_orm_active_enums; diff --git a/entity/src/prelude.rs b/entity/src/prelude.rs index 60f72f9..c4f6a2c 100644 --- a/entity/src/prelude.rs +++ b/entity/src/prelude.rs @@ -1,6 +1,7 @@ //! `SeaORM` Entity, @generated by sea-orm-codegen 1.1.14 pub use super::access_to_queue::Entity as AccessToQueue; +pub use super::invite_tokens::Entity as InviteTokens; 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/queues.rs b/entity/src/queues.rs index 34b358a..c6116df 100644 --- a/entity/src/queues.rs +++ b/entity/src/queues.rs @@ -15,6 +15,8 @@ pub struct Model { pub enum Relation { #[sea_orm(has_many = "super::access_to_queue::Entity")] AccessToQueue, + #[sea_orm(has_many = "super::invite_tokens::Entity")] + InviteTokens, #[sea_orm(has_many = "super::queue_elements::Entity")] QueueElements, #[sea_orm( @@ -33,6 +35,12 @@ impl Related for Entity { } } +impl Related for Entity { + fn to() -> RelationDef { + Relation::InviteTokens.def() + } +} + impl Related for Entity { fn to() -> RelationDef { Relation::QueueElements.def() diff --git a/migration/src/m0_init_tables.rs b/migration/src/m0_init_tables.rs index 5bde7cc..ddbc0fb 100644 --- a/migration/src/m0_init_tables.rs +++ b/migration/src/m0_init_tables.rs @@ -23,6 +23,14 @@ enum Queues { Name, } +#[derive(DeriveIden)] +enum InviteTokens { + Table, + Id, + Token, + QueueId, +} + #[derive(DeriveIden)] enum AccessToQueue { Table, @@ -94,6 +102,25 @@ impl MigrationTrait for Migration { ) .await?; + manager + .create_table( + Table::create() + .table(InviteTokens::Table) + .if_not_exists() + .col(pk_auto(InviteTokens::Id).big_integer()) + .col(uuid(InviteTokens::Token)) + .col(big_integer(InviteTokens::QueueId)) + .foreign_key( + ForeignKey::create() + .from(InviteTokens::Table, InviteTokens::QueueId) + .to(Queues::Table, Queues::Id) + .on_delete(ForeignKeyAction::Cascade) + .on_update(ForeignKeyAction::Cascade), + ) + .to_owned(), + ) + .await?; + manager .create_table( Table::create() -- cgit v1.3