- Allow-list copy with once-per-key non-production dropped-key log - Winter-named Has* hook interfaces; WithSoftDeleteCascade names the tx
49 lines
1.5 KiB
Go
49 lines
1.5 KiB
Go
package lagoon
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
// HasBeforeValidate is the Winter beforeValidate hook. GORM does not
|
|
// dispatch this name; later validation wiring type-asserts it.
|
|
type HasBeforeValidate interface {
|
|
BeforeValidate(tx *gorm.DB) error
|
|
}
|
|
|
|
// HasBeforeCreate matches GORM's native BeforeCreate hook so a model
|
|
// needs no adapter. GORM dispatches it by method name.
|
|
type HasBeforeCreate interface {
|
|
BeforeCreate(tx *gorm.DB) error
|
|
}
|
|
|
|
// HasBeforeSave matches GORM's native BeforeSave hook so a model
|
|
// needs no adapter. GORM dispatches it by method name.
|
|
type HasBeforeSave interface {
|
|
BeforeSave(tx *gorm.DB) error
|
|
}
|
|
|
|
// HasBeforeDelete matches GORM's native BeforeDelete hook so a model
|
|
// needs no adapter. GORM dispatches it by method name.
|
|
type HasBeforeDelete interface {
|
|
BeforeDelete(tx *gorm.DB) error
|
|
}
|
|
|
|
// HasAfterDelete matches GORM's native AfterDelete hook so a model
|
|
// needs no adapter. GORM dispatches it by method name.
|
|
type HasAfterDelete interface {
|
|
AfterDelete(tx *gorm.DB) error
|
|
}
|
|
|
|
// WithSoftDeleteCascade names the "Collection cascades to Album" pattern
|
|
// (DATA-03). Callers invoke it from their own BeforeDelete method: GORM
|
|
// already runs BeforeDelete inside the parent Delete transaction, so this
|
|
// does not open a new transaction. A cascade error aborts the parent delete.
|
|
func WithSoftDeleteCascade(tx *gorm.DB, cascade func(tx *gorm.DB) error) error {
|
|
if tx == nil {
|
|
return fmt.Errorf("lagoon: soft-delete cascade tx is nil")
|
|
}
|
|
return cascade(tx)
|
|
}
|