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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user