feat user - company m-to-m relationship

users
Miroito 2 years ago
parent 30de1a9b53
commit 68e77ea0fa

823
server/Cargo.lock generated

File diff suppressed because it is too large Load Diff

@ -18,7 +18,7 @@ axum = { version = "0.6", features = ["headers", "macros"] }
hyper = { version = "0.14", features = ["full"] }
tower = "0.4"
tower-cookies = "0.9"
sea-orm = { version = "0.11", features = [
sea-orm = { version = "0.12", features = [
"runtime-tokio-rustls",
"macros",
"sqlx-mysql",

File diff suppressed because it is too large Load Diff

@ -12,5 +12,5 @@ path = "src/lib.rs"
async-std = { version = "^1", features = ["attributes", "tokio1"] }
[dependencies.sea-orm-migration]
version = "0.11.0"
version = "0.12.0"
features = ["sqlx-mysql", "runtime-tokio-rustls"]

@ -6,6 +6,7 @@ mod m20230112_160440_create_transaction_table;
mod m20230119_112539_create_transactions_in_process_table;
mod m20230303_132528_transactions_created_at;
mod m20230604_113236_user_table;
mod m20231126_093416_create_user_company_table;
pub struct Migrator;
@ -18,6 +19,7 @@ impl MigratorTrait for Migrator {
Box::new(m20230119_112539_create_transactions_in_process_table::Migration),
Box::new(m20230303_132528_transactions_created_at::Migration),
Box::new(m20230604_113236_user_table::Migration),
Box::new(m20231126_093416_create_user_company_table::Migration),
]
}
}

@ -34,7 +34,7 @@ impl MigrationTrait for Migration {
}
#[derive(Iden)]
enum User {
pub enum User {
Table,
Id,
Email,

@ -0,0 +1,56 @@
use crate::m20230112_115856_create_company_table as company;
use crate::m20230604_113236_user_table as user;
use sea_orm_migration::prelude::*;
#[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(UserCompany::Table)
.if_not_exists()
.col(ColumnDef::new(UserCompany::UserId).integer().not_null())
.col(ColumnDef::new(UserCompany::CompanyId).integer().not_null())
.primary_key(
Index::create()
.col(UserCompany::CompanyId)
.col(UserCompany::UserId),
)
.foreign_key(
ForeignKey::create()
.name("FK_user")
.from(UserCompany::Table, UserCompany::CompanyId)
.to(user::User::Table, user::User::Id)
.on_update(ForeignKeyAction::Cascade)
.on_delete(ForeignKeyAction::Cascade),
)
.foreign_key(
ForeignKey::create()
.name("FK_company")
.from(UserCompany::Table, UserCompany::CompanyId)
.to(company::Company::Table, company::Company::Id)
.on_update(ForeignKeyAction::Cascade)
.on_delete(ForeignKeyAction::Cascade),
)
.to_owned(),
)
.await
}
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
manager
.drop_table(Table::drop().table(UserCompany::Table).to_owned())
.await
}
}
#[derive(Iden)]
enum UserCompany {
Table,
UserId,
CompanyId,
}

@ -1,4 +1,4 @@
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.11.0
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.6
use sea_orm::entity::prelude::*;
use serde::{Deserialize, Serialize};
@ -18,6 +18,8 @@ pub struct Model {
pub enum Relation {
#[sea_orm(has_many = "super::transaction::Entity")]
Transaction,
#[sea_orm(has_many = "super::user_company::Entity")]
UserCompany,
}
impl Related<super::transaction::Entity> for Entity {
@ -26,4 +28,19 @@ impl Related<super::transaction::Entity> for Entity {
}
}
impl Related<super::user_company::Entity> for Entity {
fn to() -> RelationDef {
Relation::UserCompany.def()
}
}
impl Related<super::user::Entity> for Entity {
fn to() -> RelationDef {
super::user_company::Relation::User.def()
}
fn via() -> Option<RelationDef> {
Some(super::user_company::Relation::Company.def().rev())
}
}
impl ActiveModelBehavior for ActiveModel {}

@ -1,4 +1,4 @@
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.11.0
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.6
use sea_orm::entity::prelude::*;
use serde::{Deserialize, Serialize};

@ -1,4 +1,4 @@
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.11.0
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.6
pub mod prelude;
@ -6,3 +6,4 @@ pub mod company;
pub mod in_process_transaction;
pub mod transaction;
pub mod user;
pub mod user_company;

@ -1,6 +1,7 @@
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.11.0
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.6
pub use super::company::Entity as Company;
pub use super::in_process_transaction::Entity as InProcessTransaction;
pub use super::transaction::Entity as Transaction;
pub use super::user::Entity as User;
pub use super::user_company::Entity as UserCompany;

@ -1,4 +1,4 @@
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.11.0
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.6
use sea_orm::entity::prelude::*;
use serde::{Deserialize, Serialize};

@ -1,4 +1,4 @@
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.11.0
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.6
use sea_orm::entity::prelude::*;
use serde::{Deserialize, Serialize};
@ -16,6 +16,24 @@ pub struct Model {
}
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {}
pub enum Relation {
#[sea_orm(has_many = "super::user_company::Entity")]
UserCompany,
}
impl Related<super::user_company::Entity> for Entity {
fn to() -> RelationDef {
Relation::UserCompany.def()
}
}
impl Related<super::company::Entity> for Entity {
fn to() -> RelationDef {
super::user_company::Relation::Company.def()
}
fn via() -> Option<RelationDef> {
Some(super::user_company::Relation::User.def().rev())
}
}
impl ActiveModelBehavior for ActiveModel {}

@ -0,0 +1,47 @@
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.6
use sea_orm::entity::prelude::*;
use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Serialize, Deserialize)]
#[sea_orm(table_name = "user_company")]
pub struct Model {
#[sea_orm(primary_key, auto_increment = false)]
pub user_id: i32,
#[sea_orm(primary_key, auto_increment = false)]
pub company_id: i32,
}
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {
#[sea_orm(
belongs_to = "super::company::Entity",
from = "Column::CompanyId",
to = "super::company::Column::Id",
on_update = "Cascade",
on_delete = "Cascade"
)]
Company,
#[sea_orm(
belongs_to = "super::user::Entity",
from = "Column::CompanyId",
to = "super::user::Column::Id",
on_update = "Cascade",
on_delete = "Cascade"
)]
User,
}
impl Related<super::company::Entity> for Entity {
fn to() -> RelationDef {
Relation::Company.def()
}
}
impl Related<super::user::Entity> for Entity {
fn to() -> RelationDef {
Relation::User.def()
}
}
impl ActiveModelBehavior for ActiveModel {}
Loading…
Cancel
Save