251dd703ed
Migration 035: tenants table with 'Schaeffler' default seed. Migration 036: tenant_id FK on all tables, RLS policies, backfill. New domains/tenants/ with CRUD router (admin only). All domain models extended with tenant_id FK. core/database.py: get_db_for_tenant with RLS context setter. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
88 lines
5.2 KiB
Python
88 lines
5.2 KiB
Python
import uuid
|
|
from datetime import datetime
|
|
from sqlalchemy import String, DateTime, Boolean, Text, Integer, Float, ForeignKey
|
|
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
|
from sqlalchemy.dialects.postgresql import UUID, JSONB
|
|
from app.database import Base
|
|
|
|
VALID_RENDER_BACKENDS = {"celery"}
|
|
|
|
|
|
class OutputType(Base):
|
|
__tablename__ = "output_types"
|
|
|
|
id: Mapped[uuid.UUID] = mapped_column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
|
name: Mapped[str] = mapped_column(String(200), unique=True, nullable=False)
|
|
description: Mapped[str | None] = mapped_column(Text, nullable=True)
|
|
renderer: Mapped[str] = mapped_column(String(50), nullable=False, default="threejs")
|
|
render_settings: Mapped[dict] = mapped_column(JSONB, nullable=False, default=dict)
|
|
output_format: Mapped[str] = mapped_column(String(20), nullable=False, default="png")
|
|
sort_order: Mapped[int] = mapped_column(Integer, nullable=False, default=0)
|
|
compatible_categories: Mapped[list] = mapped_column(JSONB, default=list, server_default="[]")
|
|
render_backend: Mapped[str] = mapped_column(String(20), nullable=False, default="auto", server_default="auto")
|
|
is_animation: Mapped[bool] = mapped_column(Boolean, nullable=False, default=False, server_default="false")
|
|
transparent_bg: Mapped[bool] = mapped_column(Boolean, nullable=False, default=False, server_default="false")
|
|
cycles_device: Mapped[str | None] = mapped_column(String(10), nullable=True, default=None)
|
|
pricing_tier_id: Mapped[int | None] = mapped_column(
|
|
Integer, ForeignKey("pricing_tiers.id", ondelete="SET NULL"), nullable=True, index=True
|
|
)
|
|
is_active: Mapped[bool] = mapped_column(Boolean, nullable=False, default=True)
|
|
tenant_id: Mapped[uuid.UUID | None] = mapped_column(
|
|
UUID(as_uuid=True), ForeignKey("tenants.id"), nullable=True, index=True
|
|
)
|
|
created_at: Mapped[datetime] = mapped_column(DateTime, default=datetime.utcnow, nullable=False)
|
|
updated_at: Mapped[datetime] = mapped_column(
|
|
DateTime, default=datetime.utcnow, onupdate=datetime.utcnow, nullable=False
|
|
)
|
|
|
|
order_lines: Mapped[list["OrderLine"]] = relationship("OrderLine", back_populates="output_type")
|
|
pricing_tier: Mapped["PricingTier | None"] = relationship("PricingTier", back_populates="output_types")
|
|
|
|
|
|
class RenderTemplate(Base):
|
|
__tablename__ = "render_templates"
|
|
|
|
id: Mapped[uuid.UUID] = mapped_column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
|
name: Mapped[str] = mapped_column(String(300), nullable=False)
|
|
category_key: Mapped[str | None] = mapped_column(String(100), nullable=True)
|
|
output_type_id: Mapped[uuid.UUID | None] = mapped_column(
|
|
UUID(as_uuid=True), ForeignKey("output_types.id", ondelete="SET NULL"), nullable=True
|
|
)
|
|
blend_file_path: Mapped[str] = mapped_column(Text, nullable=False)
|
|
original_filename: Mapped[str] = mapped_column(String(500), nullable=False)
|
|
target_collection: Mapped[str] = mapped_column(String(200), nullable=False, default="Product", server_default="Product")
|
|
material_replace_enabled: Mapped[bool] = mapped_column(Boolean, nullable=False, default=False, server_default="false")
|
|
lighting_only: Mapped[bool] = mapped_column(Boolean, nullable=False, default=False, server_default="false")
|
|
shadow_catcher_enabled: Mapped[bool] = mapped_column(Boolean, nullable=False, default=False, server_default="false")
|
|
camera_orbit: Mapped[bool] = mapped_column(Boolean, nullable=False, default=True, server_default="true")
|
|
is_active: Mapped[bool] = mapped_column(Boolean, nullable=False, default=True, server_default="true")
|
|
tenant_id: Mapped[uuid.UUID | None] = mapped_column(
|
|
UUID(as_uuid=True), ForeignKey("tenants.id"), nullable=True, index=True
|
|
)
|
|
created_at: Mapped[datetime] = mapped_column(DateTime, nullable=False, server_default="now()")
|
|
updated_at: Mapped[datetime] = mapped_column(DateTime, nullable=False, server_default="now()", onupdate=datetime.utcnow)
|
|
|
|
output_type = relationship("OutputType", lazy="joined")
|
|
|
|
|
|
class ProductRenderPosition(Base):
|
|
__tablename__ = "product_render_positions"
|
|
|
|
id: Mapped[uuid.UUID] = mapped_column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
|
product_id: Mapped[uuid.UUID] = mapped_column(
|
|
UUID(as_uuid=True), ForeignKey("products.id", ondelete="CASCADE"), nullable=False, index=True
|
|
)
|
|
name: Mapped[str] = mapped_column(String(200), nullable=False)
|
|
rotation_x: Mapped[float] = mapped_column(Float, nullable=False, default=0.0)
|
|
rotation_y: Mapped[float] = mapped_column(Float, nullable=False, default=0.0)
|
|
rotation_z: Mapped[float] = mapped_column(Float, nullable=False, default=0.0)
|
|
is_default: Mapped[bool] = mapped_column(Boolean, nullable=False, default=False)
|
|
sort_order: Mapped[int] = mapped_column(Integer, nullable=False, default=0)
|
|
created_at: Mapped[datetime] = mapped_column(DateTime, default=datetime.utcnow, nullable=False)
|
|
updated_at: Mapped[datetime] = mapped_column(
|
|
DateTime, default=datetime.utcnow, onupdate=datetime.utcnow, nullable=False
|
|
)
|
|
|
|
product: Mapped["Product"] = relationship("Product", back_populates="render_positions")
|
|
order_lines: Mapped[list["OrderLine"]] = relationship("OrderLine", back_populates="render_position")
|