From 16a10112a8cfece4709953e0e581ceb07e950b88 Mon Sep 17 00:00:00 2001 From: alemi Date: Sat, 22 Jun 2024 05:17:03 +0200 Subject: [PATCH] fix: cascade obj/activity deletions in addressing otherwise its impossible to delete objects because foreign key relation is violated! --- upub/core/src/model/addressing.rs | 6 +++--- upub/core/src/traits/normalize.rs | 2 +- .../src/m20240524_000004_create_addressing_deliveries.rs | 4 ++++ 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/upub/core/src/model/addressing.rs b/upub/core/src/model/addressing.rs index 810bf7cb..dac6e0de 100644 --- a/upub/core/src/model/addressing.rs +++ b/upub/core/src/model/addressing.rs @@ -19,7 +19,7 @@ pub enum Relation { from = "Column::Activity", to = "super::activity::Column::Internal", on_update = "Cascade", - on_delete = "NoAction" + on_delete = "Cascade" )] Activities, #[sea_orm( @@ -27,7 +27,7 @@ pub enum Relation { from = "Column::Actor", to = "super::actor::Column::Internal", on_update = "Cascade", - on_delete = "NoAction" + on_delete = "Cascade" )] Actors, #[sea_orm( @@ -43,7 +43,7 @@ pub enum Relation { from = "Column::Object", to = "super::object::Column::Internal", on_update = "Cascade", - on_delete = "NoAction" + on_delete = "Cascade" )] Objects, } diff --git a/upub/core/src/traits/normalize.rs b/upub/core/src/traits/normalize.rs index ac346ce9..c30b540d 100644 --- a/upub/core/src/traits/normalize.rs +++ b/upub/core/src/traits/normalize.rs @@ -1,4 +1,4 @@ -use apb::{field::OptionalString, Link, Collection, Document, Endpoints, Node, Object, PublicKey}; +use apb::{field::OptionalString, Collection, Document, Endpoints, Node, Object, PublicKey}; use sea_orm::{sea_query::Expr, ActiveModelTrait, ActiveValue::{Unchanged, NotSet, Set}, ColumnTrait, ConnectionTrait, DbErr, EntityTrait, IntoActiveModel, QueryFilter}; use super::Addresser; diff --git a/upub/migrations/src/m20240524_000004_create_addressing_deliveries.rs b/upub/migrations/src/m20240524_000004_create_addressing_deliveries.rs index e44b7f65..d1801915 100644 --- a/upub/migrations/src/m20240524_000004_create_addressing_deliveries.rs +++ b/upub/migrations/src/m20240524_000004_create_addressing_deliveries.rs @@ -50,6 +50,7 @@ impl MigrationTrait for Migration { .from(Addressing::Table, Addressing::Actor) .to(Actors::Table, Actors::Internal) .on_update(ForeignKeyAction::Cascade) + .on_delete(ForeignKeyAction::Cascade) ) .col(ColumnDef::new(Addressing::Instance).big_integer().null()) .foreign_key( @@ -58,6 +59,7 @@ impl MigrationTrait for Migration { .from(Addressing::Table, Addressing::Instance) .to(Instances::Table, Instances::Internal) .on_update(ForeignKeyAction::Cascade) + .on_update(ForeignKeyAction::NoAction) ) .col(ColumnDef::new(Addressing::Activity).big_integer().null()) .foreign_key( @@ -66,6 +68,7 @@ impl MigrationTrait for Migration { .from(Addressing::Table, Addressing::Activity) .to(Activities::Table, Activities::Internal) .on_update(ForeignKeyAction::Cascade) + .on_delete(ForeignKeyAction::Cascade) ) .col(ColumnDef::new(Addressing::Object).big_integer().null()) .foreign_key( @@ -74,6 +77,7 @@ impl MigrationTrait for Migration { .from(Addressing::Table, Addressing::Object) .to(Objects::Table, Objects::Internal) .on_update(ForeignKeyAction::Cascade) + .on_delete(ForeignKeyAction::Cascade) ) .col(ColumnDef::new(Addressing::Published).timestamp_with_time_zone().not_null().default(Expr::current_timestamp())) .to_owned()