-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add users_hoops migration, model and schema
- Loading branch information
Showing
10 changed files
with
136 additions
and
44 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
use sea_orm_migration::prelude::*; | ||
use crate::m20240503_190902_hoops::*; | ||
|
||
#[derive(DeriveMigrationName)] | ||
pub struct Migration; | ||
|
||
#[async_trait::async_trait] | ||
impl MigrationTrait for Migration { | ||
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> { | ||
|
||
manager | ||
.create_table( | ||
Table::create() | ||
.table(UsersHoops::Table) | ||
.if_not_exists() | ||
.col( | ||
ColumnDef::new(UsersHoops::Id) | ||
.integer() | ||
.not_null() | ||
.auto_increment() | ||
.primary_key(), | ||
) | ||
.col(ColumnDef::new(UsersHoops::UserId).integer().not_null()) | ||
.col(ColumnDef::new(UsersHoops::HoopId).integer().not_null()) | ||
.col(ColumnDef::new(UsersHoops::IsInvited).boolean().not_null()) | ||
.col(ColumnDef::new(UsersHoops::JoinedAt).big_integer().not_null()) | ||
.col(ColumnDef::new(UsersHoops::LeftAt).big_integer().not_null()) | ||
.to_owned(), | ||
) | ||
.await; | ||
|
||
manager.create_foreign_key( | ||
sea_query::ForeignKey::create() | ||
.name("FK_hoop_id") | ||
// HoopId from users_hoops table is a fk to the hoops table | ||
.from(UsersHoops::Table, UsersHoops::HoopId) | ||
.to(Hoops::Table, Hoops::Id) | ||
.on_delete(ForeignKeyAction::Cascade) | ||
.on_update(ForeignKeyAction::Cascade) | ||
.to_owned() | ||
).await; | ||
|
||
Ok(()) | ||
|
||
} | ||
|
||
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> { | ||
manager | ||
.drop_table(Table::drop().table(UsersHoops::Table).to_owned()) | ||
.await; | ||
|
||
Ok(()) | ||
|
||
} | ||
} | ||
|
||
#[derive(DeriveIden)] | ||
enum UsersHoops { | ||
Table, | ||
Id, | ||
UserId, | ||
HoopId, | ||
IsInvited, | ||
JoinedAt, | ||
LeftAt, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,5 +2,6 @@ | |
|
||
pub mod prelude; | ||
|
||
pub mod hoops; | ||
pub mod users_hoops; | ||
pub mod notifs; | ||
pub mod hoops; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.15 | ||
|
||
pub use super::hoops::Entity as Hoops; | ||
pub use super::users_hoops::Entity as UsersHoops; | ||
pub use super::notifs::Entity as Notifs; | ||
pub use super::hoops::Entity as Hoops; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.15 | ||
|
||
use sea_orm::entity::prelude::*; | ||
use serde::{Deserialize, Serialize}; | ||
|
||
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Serialize, Deserialize)] | ||
#[sea_orm(table_name = "users_hoops")] | ||
pub struct Model { | ||
#[sea_orm(primary_key)] | ||
#[serde(skip_deserializing)] | ||
pub id: i32, | ||
pub user_id: i32, | ||
pub hoop_id: i32, | ||
pub is_invited: bool, | ||
pub joined_at: i64, | ||
pub left_at: i64, | ||
} | ||
|
||
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] | ||
pub enum Relation { | ||
#[sea_orm( | ||
belongs_to = "super::hoops::Entity", | ||
from = "Column::HoopId", | ||
to = "super::hoops::Column::Id", | ||
on_update = "Cascade", | ||
on_delete = "Cascade" | ||
)] | ||
Hoops, | ||
} | ||
|
||
impl Related<super::hoops::Entity> for Entity { | ||
fn to() -> RelationDef { | ||
Relation::Hoops.def() | ||
} | ||
} | ||
|
||
impl ActiveModelBehavior for ActiveModel {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters