feat: add unique constraints for custom subdomain and domain per platform
Some checks failed
CI / ruff (push) Successful in 10s
CI / validate (push) Has been cancelled
CI / dependency-scanning (push) Has been cancelled
CI / docs (push) Has been cancelled
CI / deploy (push) Has been cancelled
CI / pytest (push) Has been cancelled

Add UNIQUE(custom_subdomain, platform_id) on store_platforms to prevent
two stores from claiming the same subdomain on the same platform.
Add UNIQUE(store_id, platform_id) on store_domains to enforce one custom
domain per store per platform.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-02-26 12:05:17 +01:00
parent d480b59df4
commit e7f8e61717
3 changed files with 41 additions and 0 deletions

View File

@@ -68,6 +68,8 @@ class StoreDomain(Base, TimestampMixin):
# Constraints
__table_args__ = (
UniqueConstraint("store_id", "domain", name="uq_store_domain"),
# A store can have at most one custom domain per platform
UniqueConstraint("store_id", "platform_id", name="uq_store_domain_platform"),
Index("idx_domain_active", "domain", "is_active"),
Index("idx_store_domain_primary", "store_id", "is_primary"),
Index("idx_store_domain_platform", "platform_id"),

View File

@@ -152,6 +152,12 @@ class StorePlatform(Base, TimestampMixin):
"platform_id",
name="uq_store_platform",
),
# Same custom_subdomain cannot be claimed twice on the same platform
UniqueConstraint(
"custom_subdomain",
"platform_id",
name="uq_custom_subdomain_platform",
),
# Performance indexes
Index(
"idx_store_platform_active",