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) <noreply@anthropic.com>
This commit is contained in:
2026-04-03 17:49:40 +02:00
parent dd09bcaeec
commit 6e40e16017

View File

@@ -218,8 +218,19 @@ class HostedSiteService:
return site return site
def delete(self, db: Session, site_id: int) -> bool: 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) site = self.get_by_id(db, site_id)
store = site.store
db.delete(site) 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() db.flush()
logger.info("Deleted hosted site: %d", site_id) logger.info("Deleted hosted site: %d", site_id)
return True return True