Problem: - Ruff removed 'from app.core.database import Base' from models/database/base.py - Import appeared "unused" (F401) but was actually a critical re-export - Caused ImportError: cannot import name 'Base' at runtime - Re-export pattern: import in one file to export from package Solution: 1. Added F401 ignore for models/database/base.py in pyproject.toml 2. Created scripts/verify_critical_imports.py verification script 3. Integrated verification into make check and CI pipeline 4. Updated documentation with explanation New Verification Script: - Checks all critical re-export imports exist - Detects import variations (parentheses, 'as' clauses) - Handles SQLAlchemy declarative_base alternatives - Runs as part of make check automatically Protected Files: - models/database/base.py - Re-exports Base for all models - models/__init__.py - Exports Base for Alembic - models/database/__init__.py - Exports Base from package - All __init__.py files (already protected) Makefile Changes: - make verify-imports - Run import verification - make check - Now includes verify-imports - make ci - Includes verify-imports in pipeline Documentation Updated: - Code quality guide explains re-export protection - Pre-commit workflow includes verification - Examples of why re-exports matter This prevents future issues where linters remove seemingly "unused" imports that are actually critical for application structure. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
78 lines
2.6 KiB
Python
78 lines
2.6 KiB
Python
from sqlalchemy import (
|
|
JSON,
|
|
Boolean,
|
|
Column,
|
|
DateTime,
|
|
ForeignKey,
|
|
Integer,
|
|
Numeric,
|
|
String,
|
|
)
|
|
from sqlalchemy.orm import relationship
|
|
|
|
from app.core.database import Base
|
|
|
|
from .base import TimestampMixin
|
|
|
|
|
|
class Customer(Base, TimestampMixin):
|
|
__tablename__ = "customers"
|
|
|
|
id = Column(Integer, primary_key=True, index=True)
|
|
vendor_id = Column(Integer, ForeignKey("vendors.id"), nullable=False)
|
|
email = Column(
|
|
String(255), nullable=False, index=True
|
|
) # Unique within vendor scope
|
|
hashed_password = Column(String(255), nullable=False)
|
|
first_name = Column(String(100))
|
|
last_name = Column(String(100))
|
|
phone = Column(String(50))
|
|
customer_number = Column(
|
|
String(100), nullable=False, index=True
|
|
) # Vendor-specific ID
|
|
preferences = Column(JSON, default=dict)
|
|
marketing_consent = Column(Boolean, default=False)
|
|
last_order_date = Column(DateTime)
|
|
total_orders = Column(Integer, default=0)
|
|
total_spent = Column(Numeric(10, 2), default=0)
|
|
is_active = Column(Boolean, default=True, nullable=False)
|
|
|
|
# Relationships
|
|
vendor = relationship("Vendor", back_populates="customers")
|
|
addresses = relationship("CustomerAddress", back_populates="customer")
|
|
orders = relationship("Order", back_populates="customer")
|
|
|
|
def __repr__(self):
|
|
return f"<Customer(id={self.id}, vendor_id={self.vendor_id}, email='{self.email}')>"
|
|
|
|
@property
|
|
def full_name(self):
|
|
if self.first_name and self.last_name:
|
|
return f"{self.first_name} {self.last_name}"
|
|
return self.email
|
|
|
|
|
|
class CustomerAddress(Base, TimestampMixin):
|
|
__tablename__ = "customer_addresses"
|
|
|
|
id = Column(Integer, primary_key=True, index=True)
|
|
vendor_id = Column(Integer, ForeignKey("vendors.id"), nullable=False)
|
|
customer_id = Column(Integer, ForeignKey("customers.id"), nullable=False)
|
|
address_type = Column(String(50), nullable=False) # 'billing', 'shipping'
|
|
first_name = Column(String(100), nullable=False)
|
|
last_name = Column(String(100), nullable=False)
|
|
company = Column(String(200))
|
|
address_line_1 = Column(String(255), nullable=False)
|
|
address_line_2 = Column(String(255))
|
|
city = Column(String(100), nullable=False)
|
|
postal_code = Column(String(20), nullable=False)
|
|
country = Column(String(100), nullable=False)
|
|
is_default = Column(Boolean, default=False)
|
|
|
|
# Relationships
|
|
vendor = relationship("Vendor")
|
|
customer = relationship("Customer", back_populates="addresses")
|
|
|
|
def __repr__(self):
|
|
return f"<CustomerAddress(id={self.id}, customer_id={self.customer_id}, type='{self.address_type}')>"
|