diff options
| author | Tolmachev Igor <me@igorek.dev> | 2025-09-27 13:48:50 +0300 |
|---|---|---|
| committer | Tolmachev Igor <me@igorek.dev> | 2025-09-27 13:48:50 +0300 |
| commit | 413708f2baa3987b4b8c7c727eeee8cfd8d59f73 (patch) | |
| tree | b108339ad2b2c78b9b01c8c413ab54ab1e673168 | |
| parent | 974c8c586e1182d502a2c30ba8b622c0b4033937 (diff) | |
| download | queue_server-413708f2baa3987b4b8c7c727eeee8cfd8d59f73.tar.gz queue_server-413708f2baa3987b4b8c7c727eeee8cfd8d59f73.zip | |
Fix invite tokens models
| -rw-r--r-- | entity/src/access_to_queue.rs | 15 | ||||
| -rw-r--r-- | entity/src/invite_tokens.rs | 10 | ||||
| -rw-r--r-- | entity/src/queues.rs | 5 | ||||
| -rw-r--r-- | entity/src/users.rs | 5 | ||||
| -rw-r--r-- | migration/src/m0_init_tables.rs | 17 |
5 files changed, 44 insertions, 8 deletions
diff --git a/entity/src/access_to_queue.rs b/entity/src/access_to_queue.rs index 9de03d5..5244ed0 100644 --- a/entity/src/access_to_queue.rs +++ b/entity/src/access_to_queue.rs | |||
| @@ -9,11 +9,20 @@ pub struct Model { | |||
| 9 | pub user_id: i64, | 9 | pub user_id: i64, |
| 10 | #[sea_orm(primary_key, auto_increment = false)] | 10 | #[sea_orm(primary_key, auto_increment = false)] |
| 11 | pub queue_id: i64, | 11 | pub queue_id: i64, |
| 12 | pub invite_token_id: i64, | ||
| 12 | } | 13 | } |
| 13 | 14 | ||
| 14 | #[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] | 15 | #[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] |
| 15 | pub enum Relation { | 16 | pub enum Relation { |
| 16 | #[sea_orm( | 17 | #[sea_orm( |
| 18 | belongs_to = "super::invite_tokens::Entity", | ||
| 19 | from = "Column::InviteTokenId", | ||
| 20 | to = "super::invite_tokens::Column::Id", | ||
| 21 | on_update = "Cascade", | ||
| 22 | on_delete = "Cascade" | ||
| 23 | )] | ||
| 24 | InviteTokens, | ||
| 25 | #[sea_orm( | ||
| 17 | belongs_to = "super::queues::Entity", | 26 | belongs_to = "super::queues::Entity", |
| 18 | from = "Column::QueueId", | 27 | from = "Column::QueueId", |
| 19 | to = "super::queues::Column::Id", | 28 | to = "super::queues::Column::Id", |
| @@ -31,6 +40,12 @@ pub enum Relation { | |||
| 31 | Users, | 40 | Users, |
| 32 | } | 41 | } |
| 33 | 42 | ||
| 43 | impl Related<super::invite_tokens::Entity> for Entity { | ||
| 44 | fn to() -> RelationDef { | ||
| 45 | Relation::InviteTokens.def() | ||
| 46 | } | ||
| 47 | } | ||
| 48 | |||
| 34 | impl Related<super::queues::Entity> for Entity { | 49 | impl Related<super::queues::Entity> for Entity { |
| 35 | fn to() -> RelationDef { | 50 | fn to() -> RelationDef { |
| 36 | Relation::Queues.def() | 51 | Relation::Queues.def() |
diff --git a/entity/src/invite_tokens.rs b/entity/src/invite_tokens.rs index f239567..c0b59f7 100644 --- a/entity/src/invite_tokens.rs +++ b/entity/src/invite_tokens.rs | |||
| @@ -9,10 +9,14 @@ pub struct Model { | |||
| 9 | pub id: i64, | 9 | pub id: i64, |
| 10 | pub token: Uuid, | 10 | pub token: Uuid, |
| 11 | pub queue_id: i64, | 11 | pub queue_id: i64, |
| 12 | pub name: String, | ||
| 13 | pub is_revoked: bool, | ||
| 12 | } | 14 | } |
| 13 | 15 | ||
| 14 | #[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] | 16 | #[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] |
| 15 | pub enum Relation { | 17 | pub enum Relation { |
| 18 | #[sea_orm(has_many = "super::access_to_queue::Entity")] | ||
| 19 | AccessToQueue, | ||
| 16 | #[sea_orm( | 20 | #[sea_orm( |
| 17 | belongs_to = "super::queues::Entity", | 21 | belongs_to = "super::queues::Entity", |
| 18 | from = "Column::QueueId", | 22 | from = "Column::QueueId", |
| @@ -23,6 +27,12 @@ pub enum Relation { | |||
| 23 | Queues, | 27 | Queues, |
| 24 | } | 28 | } |
| 25 | 29 | ||
| 30 | impl Related<super::access_to_queue::Entity> for Entity { | ||
| 31 | fn to() -> RelationDef { | ||
| 32 | Relation::AccessToQueue.def() | ||
| 33 | } | ||
| 34 | } | ||
| 35 | |||
| 26 | impl Related<super::queues::Entity> for Entity { | 36 | impl Related<super::queues::Entity> for Entity { |
| 27 | fn to() -> RelationDef { | 37 | fn to() -> RelationDef { |
| 28 | Relation::Queues.def() | 38 | Relation::Queues.def() |
diff --git a/entity/src/queues.rs b/entity/src/queues.rs index c6116df..af2714c 100644 --- a/entity/src/queues.rs +++ b/entity/src/queues.rs | |||
| @@ -49,10 +49,7 @@ impl Related<super::queue_elements::Entity> for Entity { | |||
| 49 | 49 | ||
| 50 | impl Related<super::users::Entity> for Entity { | 50 | impl Related<super::users::Entity> for Entity { |
| 51 | fn to() -> RelationDef { | 51 | fn to() -> RelationDef { |
| 52 | super::access_to_queue::Relation::Users.def() | 52 | Relation::Users.def() |
| 53 | } | ||
| 54 | fn via() -> Option<RelationDef> { | ||
| 55 | Some(super::access_to_queue::Relation::Queues.def().rev()) | ||
| 56 | } | 53 | } |
| 57 | } | 54 | } |
| 58 | 55 | ||
diff --git a/entity/src/users.rs b/entity/src/users.rs index 6628c9e..4455f4a 100644 --- a/entity/src/users.rs +++ b/entity/src/users.rs | |||
| @@ -39,10 +39,7 @@ impl Related<super::queue_elements::Entity> for Entity { | |||
| 39 | 39 | ||
| 40 | impl Related<super::queues::Entity> for Entity { | 40 | impl Related<super::queues::Entity> for Entity { |
| 41 | fn to() -> RelationDef { | 41 | fn to() -> RelationDef { |
| 42 | super::access_to_queue::Relation::Queues.def() | 42 | Relation::Queues.def() |
| 43 | } | ||
| 44 | fn via() -> Option<RelationDef> { | ||
| 45 | Some(super::access_to_queue::Relation::Users.def().rev()) | ||
| 46 | } | 43 | } |
| 47 | } | 44 | } |
| 48 | 45 | ||
diff --git a/migration/src/m0_init_tables.rs b/migration/src/m0_init_tables.rs index ddbc0fb..5e9a621 100644 --- a/migration/src/m0_init_tables.rs +++ b/migration/src/m0_init_tables.rs | |||
| @@ -29,6 +29,8 @@ enum InviteTokens { | |||
| 29 | Id, | 29 | Id, |
| 30 | Token, | 30 | Token, |
| 31 | QueueId, | 31 | QueueId, |
| 32 | Name, | ||
| 33 | IsRevoked, | ||
| 32 | } | 34 | } |
| 33 | 35 | ||
| 34 | #[derive(DeriveIden)] | 36 | #[derive(DeriveIden)] |
| @@ -36,6 +38,7 @@ enum AccessToQueue { | |||
| 36 | Table, | 38 | Table, |
| 37 | UserId, | 39 | UserId, |
| 38 | QueueId, | 40 | QueueId, |
| 41 | InviteTokenId, | ||
| 39 | } | 42 | } |
| 40 | 43 | ||
| 41 | #[derive(DeriveIden)] | 44 | #[derive(DeriveIden)] |
| @@ -117,6 +120,8 @@ impl MigrationTrait for Migration { | |||
| 117 | .on_delete(ForeignKeyAction::Cascade) | 120 | .on_delete(ForeignKeyAction::Cascade) |
| 118 | .on_update(ForeignKeyAction::Cascade), | 121 | .on_update(ForeignKeyAction::Cascade), |
| 119 | ) | 122 | ) |
| 123 | .col(string(InviteTokens::Name)) | ||
| 124 | .col(boolean(InviteTokens::IsRevoked).default(false)) | ||
| 120 | .to_owned(), | 125 | .to_owned(), |
| 121 | ) | 126 | ) |
| 122 | .await?; | 127 | .await?; |
| @@ -142,6 +147,14 @@ impl MigrationTrait for Migration { | |||
| 142 | .on_delete(ForeignKeyAction::Cascade) | 147 | .on_delete(ForeignKeyAction::Cascade) |
| 143 | .on_update(ForeignKeyAction::Cascade), | 148 | .on_update(ForeignKeyAction::Cascade), |
| 144 | ) | 149 | ) |
| 150 | .col(big_integer(AccessToQueue::InviteTokenId)) | ||
| 151 | .foreign_key( | ||
| 152 | ForeignKey::create() | ||
| 153 | .from(AccessToQueue::Table, AccessToQueue::InviteTokenId) | ||
| 154 | .to(InviteTokens::Table, InviteTokens::Id) | ||
| 155 | .on_delete(ForeignKeyAction::Cascade) | ||
| 156 | .on_update(ForeignKeyAction::Cascade), | ||
| 157 | ) | ||
| 145 | .primary_key( | 158 | .primary_key( |
| 146 | Index::create() | 159 | Index::create() |
| 147 | .col(AccessToQueue::UserId) | 160 | .col(AccessToQueue::UserId) |
| @@ -209,6 +222,10 @@ impl MigrationTrait for Migration { | |||
| 209 | .await?; | 222 | .await?; |
| 210 | 223 | ||
| 211 | manager | 224 | manager |
| 225 | .drop_table(Table::drop().table(InviteTokens::Table).to_owned()) | ||
| 226 | .await?; | ||
| 227 | |||
| 228 | manager | ||
| 212 | .drop_table(Table::drop().table(AccessToQueue::Table).to_owned()) | 229 | .drop_table(Table::drop().table(AccessToQueue::Table).to_owned()) |
| 213 | .await?; | 230 | .await?; |
| 214 | 231 | ||
