aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTolmachev Igor <me@igorek.dev>2025-09-27 00:03:28 +0300
committerTolmachev Igor <me@igorek.dev>2025-09-27 00:03:28 +0300
commit974c8c586e1182d502a2c30ba8b622c0b4033937 (patch)
tree7f7a7df8650d344b729edda836be0f47f3ce0d17
parentf4c9192b9cc2f08c38822ed477a48dd7599238d6 (diff)
downloadqueue_server-974c8c586e1182d502a2c30ba8b622c0b4033937.tar.gz
queue_server-974c8c586e1182d502a2c30ba8b622c0b4033937.zip
Add invite tokens models
-rw-r--r--Cargo.toml1
-rw-r--r--entity/src/invite_tokens.rs32
-rw-r--r--entity/src/lib.rs1
-rw-r--r--entity/src/prelude.rs1
-rw-r--r--entity/src/queues.rs8
-rw-r--r--migration/src/m0_init_tables.rs27
6 files changed, 70 insertions, 0 deletions
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"
27utoipa = { version = "5.4.0", features = ["axum_extras", "chrono", "preserve_order", "preserve_path_order"] } 27utoipa = { version = "5.4.0", features = ["axum_extras", "chrono", "preserve_order", "preserve_path_order"] }
28utoipa-axum = "0.2.0" 28utoipa-axum = "0.2.0"
29utoipa-scalar = { version = "0.3.0", features = ["axum"] } 29utoipa-scalar = { version = "0.3.0", features = ["axum"] }
30uuid = { 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 @@
1//! `SeaORM` Entity, @generated by sea-orm-codegen 1.1.14
2
3use sea_orm::entity::prelude::*;
4
5#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)]
6#[sea_orm(table_name = "invite_tokens")]
7pub struct Model {
8 #[sea_orm(primary_key)]
9 pub id: i64,
10 pub token: Uuid,
11 pub queue_id: i64,
12}
13
14#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
15pub 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}
25
26impl Related<super::queues::Entity> for Entity {
27 fn to() -> RelationDef {
28 Relation::Queues.def()
29 }
30}
31
32impl 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 @@
3pub mod prelude; 3pub mod prelude;
4 4
5pub mod access_to_queue; 5pub mod access_to_queue;
6pub mod invite_tokens;
6pub mod queue_elements; 7pub mod queue_elements;
7pub mod queues; 8pub mod queues;
8pub mod sea_orm_active_enums; 9pub 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 @@
1//! `SeaORM` Entity, @generated by sea-orm-codegen 1.1.14 1//! `SeaORM` Entity, @generated by sea-orm-codegen 1.1.14
2 2
3pub use super::access_to_queue::Entity as AccessToQueue; 3pub use super::access_to_queue::Entity as AccessToQueue;
4pub use super::invite_tokens::Entity as InviteTokens;
4pub use super::queue_elements::Entity as QueueElements; 5pub use super::queue_elements::Entity as QueueElements;
5pub use super::queues::Entity as Queues; 6pub use super::queues::Entity as Queues;
6pub use super::users::Entity as Users; 7pub 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 {
15pub enum Relation { 15pub enum Relation {
16 #[sea_orm(has_many = "super::access_to_queue::Entity")] 16 #[sea_orm(has_many = "super::access_to_queue::Entity")]
17 AccessToQueue, 17 AccessToQueue,
18 #[sea_orm(has_many = "super::invite_tokens::Entity")]
19 InviteTokens,
18 #[sea_orm(has_many = "super::queue_elements::Entity")] 20 #[sea_orm(has_many = "super::queue_elements::Entity")]
19 QueueElements, 21 QueueElements,
20 #[sea_orm( 22 #[sea_orm(
@@ -33,6 +35,12 @@ impl Related<super::access_to_queue::Entity> for Entity {
33 } 35 }
34} 36}
35 37
38impl Related<super::invite_tokens::Entity> for Entity {
39 fn to() -> RelationDef {
40 Relation::InviteTokens.def()
41 }
42}
43
36impl Related<super::queue_elements::Entity> for Entity { 44impl Related<super::queue_elements::Entity> for Entity {
37 fn to() -> RelationDef { 45 fn to() -> RelationDef {
38 Relation::QueueElements.def() 46 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
@@ -24,6 +24,14 @@ enum Queues {
24} 24}
25 25
26#[derive(DeriveIden)] 26#[derive(DeriveIden)]
27enum InviteTokens {
28 Table,
29 Id,
30 Token,
31 QueueId,
32}
33
34#[derive(DeriveIden)]
27enum AccessToQueue { 35enum AccessToQueue {
28 Table, 36 Table,
29 UserId, 37 UserId,
@@ -97,6 +105,25 @@ impl MigrationTrait for Migration {
97 manager 105 manager
98 .create_table( 106 .create_table(
99 Table::create() 107 Table::create()
108 .table(InviteTokens::Table)
109 .if_not_exists()
110 .col(pk_auto(InviteTokens::Id).big_integer())
111 .col(uuid(InviteTokens::Token))
112 .col(big_integer(InviteTokens::QueueId))
113 .foreign_key(
114 ForeignKey::create()
115 .from(InviteTokens::Table, InviteTokens::QueueId)
116 .to(Queues::Table, Queues::Id)
117 .on_delete(ForeignKeyAction::Cascade)
118 .on_update(ForeignKeyAction::Cascade),
119 )
120 .to_owned(),
121 )
122 .await?;
123
124 manager
125 .create_table(
126 Table::create()
100 .table(AccessToQueue::Table) 127 .table(AccessToQueue::Table)
101 .if_not_exists() 128 .if_not_exists()
102 .col(big_integer(AccessToQueue::UserId)) 129 .col(big_integer(AccessToQueue::UserId))