fix(cloudflare): clean up pointing member when zone domain is deleted

This commit is contained in:
ryan
2026-08-29 18:32:02 +08:00
parent 81739f9cb4
commit bbd7f72c2d
9 changed files with 104 additions and 5 deletions
+3 -1
View File
@@ -91,7 +91,9 @@ func DeleteCFPointingGroup(ctx context.Context, id uint) error {
// CountCFPointingMembersByGroupID counts members in a group.
func CountCFPointingMembersByGroupID(ctx context.Context, groupID uint) (int64, error) {
var count int64
err := db.DB(ctx).Model(&model.CFPointingMember{}).Where("group_id = ?", groupID).Count(&count).Error
err := db.DB(ctx).Table("of_cf_pointing_members AS members").
Joins("JOIN of_zone_domains AS domains ON domains.id = members.zone_domain_id").
Where("members.group_id = ?", groupID).Count(&count).Error
return count, err
}
+10 -1
View File
@@ -97,7 +97,16 @@ func SaveZoneDomain(ctx context.Context, domain *model.ZoneDomain) error {
// DeleteZoneDomain deletes a zone domain record.
func DeleteZoneDomain(ctx context.Context, domain *model.ZoneDomain) error {
return db.DB(ctx).Delete(domain).Error
conn := db.DB(ctx)
if conn == nil {
return errors.New(errDatabaseNotInitialized)
}
return conn.Transaction(func(tx *gorm.DB) error {
if err := tx.Where("zone_domain_id = ?", domain.ID).Delete(&model.CFPointingMember{}).Error; err != nil {
return err
}
return tx.Delete(domain).Error
})
}
// ListZoneDomainsByRouteID returns the domains bound to a proxy route.