parent
b866236704
commit
950a3bc201
@ -17,7 +17,7 @@ pub enum Relation {
|
||||
from = "Column::BakeryId",
|
||||
to = "super::bakery::Column::Id",
|
||||
on_update = "Cascade",
|
||||
on_delete = "Cascade"
|
||||
on_delete = "SetNull"
|
||||
)]
|
||||
Bakery,
|
||||
}
|
||||
|
@ -21,7 +21,7 @@ pub enum Relation {
|
||||
from = "Column::BakeryId",
|
||||
to = "super::bakery::Column::Id",
|
||||
on_update = "Cascade",
|
||||
on_delete = "Cascade"
|
||||
on_delete = "SetNull"
|
||||
)]
|
||||
Bakery,
|
||||
#[sea_orm(has_many = "super::lineitem::Entity")]
|
||||
|
@ -22,9 +22,7 @@ pub enum Relation {
|
||||
#[sea_orm(
|
||||
belongs_to = "super::baker::Entity",
|
||||
from = "Column::BakerId",
|
||||
to = "super::baker::Column::Id",
|
||||
on_update = "Cascade",
|
||||
on_delete = "Cascade"
|
||||
to = "super::baker::Column::Id"
|
||||
)]
|
||||
Baker,
|
||||
}
|
||||
|
@ -25,9 +25,7 @@ pub enum Relation {
|
||||
#[sea_orm(
|
||||
belongs_to = "super::cake::Entity",
|
||||
from = "Column::CakeId",
|
||||
to = "super::cake::Column::Id",
|
||||
on_update = "Cascade",
|
||||
on_delete = "Cascade"
|
||||
to = "super::cake::Column::Id"
|
||||
)]
|
||||
Cake,
|
||||
}
|
||||
|
@ -17,9 +17,7 @@ pub enum Relation {
|
||||
#[sea_orm(
|
||||
belongs_to = "super::bakery::Entity",
|
||||
from = "Column::BakeryId",
|
||||
to = "super::bakery::Column::Id",
|
||||
on_update = "Cascade",
|
||||
on_delete = "Cascade"
|
||||
to = "super::bakery::Column::Id"
|
||||
)]
|
||||
Bakery,
|
||||
#[sea_orm(
|
||||
|
@ -58,7 +58,7 @@ pub async fn create_baker_table(db: &DbConn) -> Result<ExecResult, DbErr> {
|
||||
.name("fk-baker-bakery_id")
|
||||
.from(baker::Entity, baker::Column::BakeryId)
|
||||
.to(bakery::Entity, bakery::Column::Id)
|
||||
.on_delete(ForeignKeyAction::Cascade)
|
||||
.on_delete(ForeignKeyAction::SetNull)
|
||||
.on_update(ForeignKeyAction::Cascade),
|
||||
)
|
||||
.to_owned();
|
||||
@ -113,9 +113,7 @@ pub async fn create_order_table(db: &DbConn) -> Result<ExecResult, DbErr> {
|
||||
ForeignKey::create()
|
||||
.name("fk-order-bakery_id")
|
||||
.from(order::Entity, order::Column::BakeryId)
|
||||
.to(bakery::Entity, bakery::Column::Id)
|
||||
.on_delete(ForeignKeyAction::Cascade)
|
||||
.on_update(ForeignKeyAction::Cascade),
|
||||
.to(bakery::Entity, bakery::Column::Id),
|
||||
)
|
||||
.foreign_key(
|
||||
ForeignKey::create()
|
||||
@ -172,9 +170,7 @@ pub async fn create_lineitem_table(db: &DbConn) -> Result<ExecResult, DbErr> {
|
||||
ForeignKey::create()
|
||||
.name("fk-lineitem-cake_id")
|
||||
.from(lineitem::Entity, lineitem::Column::CakeId)
|
||||
.to(cake::Entity, cake::Column::Id)
|
||||
.on_delete(ForeignKeyAction::Cascade)
|
||||
.on_update(ForeignKeyAction::Cascade),
|
||||
.to(cake::Entity, cake::Column::Id),
|
||||
)
|
||||
.to_owned();
|
||||
|
||||
@ -212,9 +208,7 @@ pub async fn create_cakes_bakers_table(db: &DbConn) -> Result<ExecResult, DbErr>
|
||||
ForeignKey::create()
|
||||
.name("fk-cakes_bakers-baker_id")
|
||||
.from(cakes_bakers::Entity, cakes_bakers::Column::BakerId)
|
||||
.to(baker::Entity, baker::Column::Id)
|
||||
.on_delete(ForeignKeyAction::Cascade)
|
||||
.on_update(ForeignKeyAction::Cascade),
|
||||
.to(baker::Entity, baker::Column::Id),
|
||||
)
|
||||
.to_owned();
|
||||
|
||||
@ -243,7 +237,7 @@ pub async fn create_cake_table(db: &DbConn) -> Result<ExecResult, DbErr> {
|
||||
.name("fk-cake-bakery_id")
|
||||
.from(cake::Entity, cake::Column::BakeryId)
|
||||
.to(bakery::Entity, bakery::Column::Id)
|
||||
.on_delete(ForeignKeyAction::Cascade)
|
||||
.on_delete(ForeignKeyAction::SetNull)
|
||||
.on_update(ForeignKeyAction::Cascade),
|
||||
)
|
||||
.col(
|
||||
|
@ -45,7 +45,9 @@ pub async fn create_tables(db: &DatabaseConnection) -> Result<(), DbErr> {
|
||||
create_edit_log_table(db).await?;
|
||||
create_teas_table(db).await?;
|
||||
create_binary_table(db).await?;
|
||||
create_bits_table(db).await?;
|
||||
if matches!(db_backend, DbBackend::Postgres) {
|
||||
create_bits_table(db).await?;
|
||||
}
|
||||
create_dyn_table_name_lazy_static_table(db).await?;
|
||||
create_value_type_table(db).await?;
|
||||
|
||||
|
@ -3,11 +3,9 @@ pub mod common;
|
||||
pub use chrono::offset::Utc;
|
||||
pub use common::{bakery_chain::*, setup::*, TestContext};
|
||||
pub use rust_decimal::prelude::*;
|
||||
pub use sea_orm::{entity::*, query::*, DatabaseConnection, FromQueryResult};
|
||||
pub use uuid::Uuid;
|
||||
|
||||
#[cfg(any(feature = "sqlx-mysql", feature = "sqlx-postgres"))]
|
||||
use sea_orm::{entity::*, query::*, DatabaseConnection, FromQueryResult};
|
||||
|
||||
// Run the test locally:
|
||||
// DATABASE_URL="mysql://root:@localhost" cargo test --features sqlx-mysql,runtime-async-std --test sequential_op_tests
|
||||
#[sea_orm_macros::test]
|
||||
@ -29,7 +27,6 @@ pub async fn test_multiple_operations() {
|
||||
ctx.delete().await;
|
||||
}
|
||||
|
||||
#[cfg(any(feature = "sqlx-mysql", feature = "sqlx-postgres"))]
|
||||
async fn seed_data(db: &DatabaseConnection) {
|
||||
let bakery = bakery::ActiveModel {
|
||||
name: Set("SeaSide Bakery".to_owned()),
|
||||
@ -131,7 +128,6 @@ async fn seed_data(db: &DatabaseConnection) {
|
||||
.expect("could not insert order");
|
||||
}
|
||||
|
||||
#[cfg(any(feature = "sqlx-mysql", feature = "sqlx-postgres"))]
|
||||
async fn find_baker_least_sales(db: &DatabaseConnection) -> Option<baker::Model> {
|
||||
#[cfg(any(feature = "sqlx-postgres"))]
|
||||
type Type = i64;
|
||||
@ -194,7 +190,6 @@ async fn find_baker_least_sales(db: &DatabaseConnection) -> Option<baker::Model>
|
||||
.unwrap()
|
||||
}
|
||||
|
||||
#[cfg(any(feature = "sqlx-mysql", feature = "sqlx-postgres"))]
|
||||
async fn create_cake(db: &DatabaseConnection, baker: baker::Model) -> Option<cake::Model> {
|
||||
let new_cake = cake::ActiveModel {
|
||||
name: Set("New Cake".to_owned()),
|
||||
@ -230,7 +225,6 @@ async fn create_cake(db: &DatabaseConnection, baker: baker::Model) -> Option<cak
|
||||
.unwrap()
|
||||
}
|
||||
|
||||
#[cfg(any(feature = "sqlx-mysql", feature = "sqlx-postgres"))]
|
||||
async fn create_order(db: &DatabaseConnection, cake: cake::Model) {
|
||||
let another_customer = customer::ActiveModel {
|
||||
name: Set("John".to_owned()),
|
||||
@ -264,7 +258,6 @@ async fn create_order(db: &DatabaseConnection, cake: cake::Model) {
|
||||
.expect("could not insert order");
|
||||
}
|
||||
|
||||
#[cfg(any(feature = "sqlx-mysql", feature = "sqlx-postgres"))]
|
||||
pub async fn test_delete_bakery(db: &DatabaseConnection) {
|
||||
let initial_bakeries = Bakery::find().all(db).await.unwrap().len();
|
||||
|
||||
|
@ -28,12 +28,13 @@ pub async fn test_error(db: &DatabaseConnection) {
|
||||
|
||||
// if compiling without sqlx, this assignment will complain,
|
||||
// but the whole test is useless in that case anyway.
|
||||
#[allow(unused_variables)]
|
||||
let error: DbErr = cake
|
||||
.into_active_model()
|
||||
.insert(db)
|
||||
.await
|
||||
.expect_err("inserting should fail due to duplicate primary key");
|
||||
#[allow(unused_variables, clippy::match_single_binding)]
|
||||
let error: DbErr = match db.get_database_backend() {
|
||||
_ => cake.into_active_model(),
|
||||
}
|
||||
.insert(db)
|
||||
.await
|
||||
.expect_err("inserting should fail due to duplicate primary key");
|
||||
|
||||
assert!(matches!(
|
||||
error.sql_err(),
|
||||
|
Loading…
x
Reference in New Issue
Block a user