Files
orion/app/modules/tenancy/models/store_domain.py
Samir Boulahtit c3d26e9aa4 refactor(migrations): squash 75 migrations into 12 per-module initial migrations
The old migration chain was broken (downgrade path through vendor->merchant
rename made rollbacks impossible). This squashes everything into fresh
per-module migrations with zero schema drift, verified by autogenerate.

Changes:
- Replace 75 accumulated migrations with 12 per-module initial migrations
  (core, billing, catalog, marketplace, cms, customers, orders, inventory,
  cart, messaging, loyalty, dev_tools) in a linear chain
- Fix make db-reset to use SQL DROP SCHEMA instead of alembic downgrade base
- Enable migration autodiscovery for all modules (migrations_path in definitions)
- Rewrite alembic/env.py to import all 75 model tables across 13 modules
- Fix AdminNotification import (was incorrectly from tenancy, now from messaging)
- Update squash_migrations.py to handle all module migration directories

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-08 11:51:37 +01:00

100 lines
2.7 KiB
Python

# app/modules/tenancy/models/store_domain.py
"""
Store Domain Model - Maps custom domains to stores
"""
from sqlalchemy import (
Boolean,
Column,
DateTime,
ForeignKey,
Index,
Integer,
String,
UniqueConstraint,
)
from sqlalchemy.orm import relationship
from app.core.database import Base
from models.database.base import TimestampMixin
class StoreDomain(Base, TimestampMixin):
"""
Maps custom domains to stores for multi-domain routing.
Examples:
- customdomain1.com -> Store 1
- shop.mybusiness.com -> Store 2
- www.customdomain1.com -> Store 1 (www is stripped)
"""
__tablename__ = "store_domains"
id = Column(Integer, primary_key=True, index=True)
store_id = Column(
Integer, ForeignKey("stores.id", ondelete="CASCADE"), nullable=False
)
# Domain configuration
domain = Column(String(255), nullable=False, unique=True, index=True)
is_primary = Column(Boolean, default=False, nullable=False)
is_active = Column(Boolean, default=True, nullable=False)
# SSL/TLS status (for monitoring)
ssl_status = Column(
String(50), default="pending"
) # pending, active, expired, error
ssl_verified_at = Column(DateTime(timezone=True), nullable=True)
# DNS verification (to confirm domain ownership)
verification_token = Column(String(100), unique=True, nullable=True)
is_verified = Column(Boolean, default=False, nullable=False)
verified_at = Column(DateTime(timezone=True), nullable=True)
# Relationships
store = relationship("Store", back_populates="domains")
# Constraints
__table_args__ = (
UniqueConstraint("store_id", "domain", name="uq_store_domain"),
Index("idx_domain_active", "domain", "is_active"),
Index("idx_store_domain_primary", "store_id", "is_primary"),
)
def __repr__(self):
return f"<StoreDomain(domain='{self.domain}', store_id={self.store_id})>"
@property
def full_url(self):
"""Return full URL with https"""
return f"https://{self.domain}"
@classmethod
def normalize_domain(cls, domain: str) -> str:
"""
Normalize domain for consistent storage.
Examples:
- https://example.com -> example.com
- www.example.com -> example.com
- EXAMPLE.COM -> example.com
"""
# Remove protocol
domain = domain.replace("https://", "").replace("http://", "") # noqa: SEC-034
# Remove trailing slash
domain = domain.rstrip("/")
# Remove www prefix (optional - depends on your preference)
# if domain.startswith("www."):
# domain = domain[4:]
# Convert to lowercase
domain = domain.lower()
return domain
__all__ = ["StoreDomain"]