Upstream Changes - 2 (#2149)

* Upstream Changes - 2

* revert
This commit is contained in:
Billy Chan 2024-03-13 16:51:17 +08:00 committed by GitHub
parent b866236704
commit 950a3bc201
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
9 changed files with 21 additions and 37 deletions

View File

@ -17,7 +17,7 @@ pub enum Relation {
from = "Column::BakeryId", from = "Column::BakeryId",
to = "super::bakery::Column::Id", to = "super::bakery::Column::Id",
on_update = "Cascade", on_update = "Cascade",
on_delete = "Cascade" on_delete = "SetNull"
)] )]
Bakery, Bakery,
} }

View File

@ -21,7 +21,7 @@ pub enum Relation {
from = "Column::BakeryId", from = "Column::BakeryId",
to = "super::bakery::Column::Id", to = "super::bakery::Column::Id",
on_update = "Cascade", on_update = "Cascade",
on_delete = "Cascade" on_delete = "SetNull"
)] )]
Bakery, Bakery,
#[sea_orm(has_many = "super::lineitem::Entity")] #[sea_orm(has_many = "super::lineitem::Entity")]

View File

@ -22,9 +22,7 @@ pub enum Relation {
#[sea_orm( #[sea_orm(
belongs_to = "super::baker::Entity", belongs_to = "super::baker::Entity",
from = "Column::BakerId", from = "Column::BakerId",
to = "super::baker::Column::Id", to = "super::baker::Column::Id"
on_update = "Cascade",
on_delete = "Cascade"
)] )]
Baker, Baker,
} }

View File

@ -25,9 +25,7 @@ pub enum Relation {
#[sea_orm( #[sea_orm(
belongs_to = "super::cake::Entity", belongs_to = "super::cake::Entity",
from = "Column::CakeId", from = "Column::CakeId",
to = "super::cake::Column::Id", to = "super::cake::Column::Id"
on_update = "Cascade",
on_delete = "Cascade"
)] )]
Cake, Cake,
} }

View File

@ -17,9 +17,7 @@ pub enum Relation {
#[sea_orm( #[sea_orm(
belongs_to = "super::bakery::Entity", belongs_to = "super::bakery::Entity",
from = "Column::BakeryId", from = "Column::BakeryId",
to = "super::bakery::Column::Id", to = "super::bakery::Column::Id"
on_update = "Cascade",
on_delete = "Cascade"
)] )]
Bakery, Bakery,
#[sea_orm( #[sea_orm(

View File

@ -58,7 +58,7 @@ pub async fn create_baker_table(db: &DbConn) -> Result<ExecResult, DbErr> {
.name("fk-baker-bakery_id") .name("fk-baker-bakery_id")
.from(baker::Entity, baker::Column::BakeryId) .from(baker::Entity, baker::Column::BakeryId)
.to(bakery::Entity, bakery::Column::Id) .to(bakery::Entity, bakery::Column::Id)
.on_delete(ForeignKeyAction::Cascade) .on_delete(ForeignKeyAction::SetNull)
.on_update(ForeignKeyAction::Cascade), .on_update(ForeignKeyAction::Cascade),
) )
.to_owned(); .to_owned();
@ -113,9 +113,7 @@ pub async fn create_order_table(db: &DbConn) -> Result<ExecResult, DbErr> {
ForeignKey::create() ForeignKey::create()
.name("fk-order-bakery_id") .name("fk-order-bakery_id")
.from(order::Entity, order::Column::BakeryId) .from(order::Entity, order::Column::BakeryId)
.to(bakery::Entity, bakery::Column::Id) .to(bakery::Entity, bakery::Column::Id),
.on_delete(ForeignKeyAction::Cascade)
.on_update(ForeignKeyAction::Cascade),
) )
.foreign_key( .foreign_key(
ForeignKey::create() ForeignKey::create()
@ -172,9 +170,7 @@ pub async fn create_lineitem_table(db: &DbConn) -> Result<ExecResult, DbErr> {
ForeignKey::create() ForeignKey::create()
.name("fk-lineitem-cake_id") .name("fk-lineitem-cake_id")
.from(lineitem::Entity, lineitem::Column::CakeId) .from(lineitem::Entity, lineitem::Column::CakeId)
.to(cake::Entity, cake::Column::Id) .to(cake::Entity, cake::Column::Id),
.on_delete(ForeignKeyAction::Cascade)
.on_update(ForeignKeyAction::Cascade),
) )
.to_owned(); .to_owned();
@ -212,9 +208,7 @@ pub async fn create_cakes_bakers_table(db: &DbConn) -> Result<ExecResult, DbErr>
ForeignKey::create() ForeignKey::create()
.name("fk-cakes_bakers-baker_id") .name("fk-cakes_bakers-baker_id")
.from(cakes_bakers::Entity, cakes_bakers::Column::BakerId) .from(cakes_bakers::Entity, cakes_bakers::Column::BakerId)
.to(baker::Entity, baker::Column::Id) .to(baker::Entity, baker::Column::Id),
.on_delete(ForeignKeyAction::Cascade)
.on_update(ForeignKeyAction::Cascade),
) )
.to_owned(); .to_owned();
@ -243,7 +237,7 @@ pub async fn create_cake_table(db: &DbConn) -> Result<ExecResult, DbErr> {
.name("fk-cake-bakery_id") .name("fk-cake-bakery_id")
.from(cake::Entity, cake::Column::BakeryId) .from(cake::Entity, cake::Column::BakeryId)
.to(bakery::Entity, bakery::Column::Id) .to(bakery::Entity, bakery::Column::Id)
.on_delete(ForeignKeyAction::Cascade) .on_delete(ForeignKeyAction::SetNull)
.on_update(ForeignKeyAction::Cascade), .on_update(ForeignKeyAction::Cascade),
) )
.col( .col(

View File

@ -45,7 +45,9 @@ pub async fn create_tables(db: &DatabaseConnection) -> Result<(), DbErr> {
create_edit_log_table(db).await?; create_edit_log_table(db).await?;
create_teas_table(db).await?; create_teas_table(db).await?;
create_binary_table(db).await?; create_binary_table(db).await?;
if matches!(db_backend, DbBackend::Postgres) {
create_bits_table(db).await?; create_bits_table(db).await?;
}
create_dyn_table_name_lazy_static_table(db).await?; create_dyn_table_name_lazy_static_table(db).await?;
create_value_type_table(db).await?; create_value_type_table(db).await?;

View File

@ -3,11 +3,9 @@ pub mod common;
pub use chrono::offset::Utc; pub use chrono::offset::Utc;
pub use common::{bakery_chain::*, setup::*, TestContext}; pub use common::{bakery_chain::*, setup::*, TestContext};
pub use rust_decimal::prelude::*; pub use rust_decimal::prelude::*;
pub use sea_orm::{entity::*, query::*, DatabaseConnection, FromQueryResult};
pub use uuid::Uuid; pub use uuid::Uuid;
#[cfg(any(feature = "sqlx-mysql", feature = "sqlx-postgres"))]
use sea_orm::{entity::*, query::*, DatabaseConnection, FromQueryResult};
// Run the test locally: // Run the test locally:
// DATABASE_URL="mysql://root:@localhost" cargo test --features sqlx-mysql,runtime-async-std --test sequential_op_tests // DATABASE_URL="mysql://root:@localhost" cargo test --features sqlx-mysql,runtime-async-std --test sequential_op_tests
#[sea_orm_macros::test] #[sea_orm_macros::test]
@ -29,7 +27,6 @@ pub async fn test_multiple_operations() {
ctx.delete().await; ctx.delete().await;
} }
#[cfg(any(feature = "sqlx-mysql", feature = "sqlx-postgres"))]
async fn seed_data(db: &DatabaseConnection) { async fn seed_data(db: &DatabaseConnection) {
let bakery = bakery::ActiveModel { let bakery = bakery::ActiveModel {
name: Set("SeaSide Bakery".to_owned()), name: Set("SeaSide Bakery".to_owned()),
@ -131,7 +128,6 @@ async fn seed_data(db: &DatabaseConnection) {
.expect("could not insert order"); .expect("could not insert order");
} }
#[cfg(any(feature = "sqlx-mysql", feature = "sqlx-postgres"))]
async fn find_baker_least_sales(db: &DatabaseConnection) -> Option<baker::Model> { async fn find_baker_least_sales(db: &DatabaseConnection) -> Option<baker::Model> {
#[cfg(any(feature = "sqlx-postgres"))] #[cfg(any(feature = "sqlx-postgres"))]
type Type = i64; type Type = i64;
@ -194,7 +190,6 @@ async fn find_baker_least_sales(db: &DatabaseConnection) -> Option<baker::Model>
.unwrap() .unwrap()
} }
#[cfg(any(feature = "sqlx-mysql", feature = "sqlx-postgres"))]
async fn create_cake(db: &DatabaseConnection, baker: baker::Model) -> Option<cake::Model> { async fn create_cake(db: &DatabaseConnection, baker: baker::Model) -> Option<cake::Model> {
let new_cake = cake::ActiveModel { let new_cake = cake::ActiveModel {
name: Set("New Cake".to_owned()), name: Set("New Cake".to_owned()),
@ -230,7 +225,6 @@ async fn create_cake(db: &DatabaseConnection, baker: baker::Model) -> Option<cak
.unwrap() .unwrap()
} }
#[cfg(any(feature = "sqlx-mysql", feature = "sqlx-postgres"))]
async fn create_order(db: &DatabaseConnection, cake: cake::Model) { async fn create_order(db: &DatabaseConnection, cake: cake::Model) {
let another_customer = customer::ActiveModel { let another_customer = customer::ActiveModel {
name: Set("John".to_owned()), name: Set("John".to_owned()),
@ -264,7 +258,6 @@ async fn create_order(db: &DatabaseConnection, cake: cake::Model) {
.expect("could not insert order"); .expect("could not insert order");
} }
#[cfg(any(feature = "sqlx-mysql", feature = "sqlx-postgres"))]
pub async fn test_delete_bakery(db: &DatabaseConnection) { pub async fn test_delete_bakery(db: &DatabaseConnection) {
let initial_bakeries = Bakery::find().all(db).await.unwrap().len(); let initial_bakeries = Bakery::find().all(db).await.unwrap().len();

View File

@ -28,9 +28,10 @@ pub async fn test_error(db: &DatabaseConnection) {
// if compiling without sqlx, this assignment will complain, // if compiling without sqlx, this assignment will complain,
// but the whole test is useless in that case anyway. // but the whole test is useless in that case anyway.
#[allow(unused_variables)] #[allow(unused_variables, clippy::match_single_binding)]
let error: DbErr = cake let error: DbErr = match db.get_database_backend() {
.into_active_model() _ => cake.into_active_model(),
}
.insert(db) .insert(db)
.await .await
.expect_err("inserting should fail due to duplicate primary key"); .expect_err("inserting should fail due to duplicate primary key");