From 6e40e160170a352a91ebb83bcdae571293a83af8 Mon Sep 17 00:00:00 2001 From: Samir Boulahtit Date: Fri, 3 Apr 2026 17:49:40 +0200 Subject: [PATCH] fix(hosting): cascade soft-delete Store when deleting HostedSite When deleting a hosted site, the associated Store is now soft-deleted (sets deleted_at). This frees the subdomain for reuse via the partial unique index (WHERE deleted_at IS NULL). Previously the Store was orphaned, blocking subdomain reuse. Closes docs/proposals/hosting-cascade-delete.md. Co-Authored-By: Claude Opus 4.6 (1M context) --- app/modules/hosting/services/hosted_site_service.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/app/modules/hosting/services/hosted_site_service.py b/app/modules/hosting/services/hosted_site_service.py index b404a193..5b1925fb 100644 --- a/app/modules/hosting/services/hosted_site_service.py +++ b/app/modules/hosting/services/hosted_site_service.py @@ -218,8 +218,19 @@ class HostedSiteService: return site def delete(self, db: Session, site_id: int) -> bool: + """Delete a hosted site and soft-delete the associated store.""" + from app.core.soft_delete import soft_delete + site = self.get_by_id(db, site_id) + store = site.store + db.delete(site) + + # Soft-delete the store created for this site (frees the subdomain) + if store: + soft_delete(db, store) + logger.info("Soft-deleted store %d (subdomain=%s) for site %d", store.id, store.subdomain, site_id) + db.flush() logger.info("Deleted hosted site: %d", site_id) return True