Product_Maker_id = Column(Uuid, primary_key=True, server_default=func.uuid_generate_v4())
business_name = Column(Text, nullable=False)
business_registration_path = Column(Text, nullable=False)
year_incorporated = Column(Text, nullable=False)
founder_ceo = Column(Text, nullable=False)
website = Column(Text, nullable=False)
category = Column(Text, nullable=False)
# Office Address composite columns
office_address = composite(Address,
Column('office_street', String(255)),
Column('office_city', String(255)),
Column('office_state', String(255)),
Column('office_postal_code', String(20)),
Column('office_country', String(255)))
# Warehouse Address composite columns
warehouse_address = composite(Address,
Column('warehouse_street', String(255)),
Column('warehouse_city', String(255)),
Column('warehouse_state', String(255)),
Column('warehouse_postal_code', String(20)),
Column('warehouse_country', String(255)))
# Telephone composite columns
telephone = composite(Telephone,
Column('tel_country_code', String(10)),
Column('tel_area_code', String(10)),
Column('tel_number', String(50)))
# For arrays of composite types, we need separate tables with relationships
# These will be handled as separate tables below
validation_status = Column(Boolean, nullable=False)
last_validation_date = Column(Date, nullable=False)
created_at = Column(TIMESTAMP, nullable=False)
created_by = Column(Text, nullable=False)
updated_at = Column(TIMESTAMP, nullable=False)
TSI_User_Info_id = Column(Uuid, ForeignKey('TSI_User_Info.TSI_User_Info_id'))
tsi_user_info = relationship("TSIUserInfo", back_populates="product_makers")
awards = relationship("ProductMakerAward", back_populates="product_maker", cascade="all, delete-orphan")
contact_persons = relationship("ProductMakerContactPerson", back_populates="product_maker", cascade="all, delete-orphan")
programs = relationship("ProductMakerProgram", back_populates="product_maker", cascade="all, delete-orphan")
from sqlalchemy import (
Text,
String,
Boolean,
Date,
TIMESTAMP,
Uuid,
ForeignKey,
func,
)
from sqlalchemy.orm import (
DeclarativeBase,
Mapped,
mapped_column,
composite,
relationship,
)
from typing import List
from uuid import UUID
from .address import Address # your Address composite class
from .telephone import Telephone # your Telephone composite class
class Base(DeclarativeBase):
pass
class ProductMaker(Base):
__tablename__ = 'Product_Maker'
# --- Primary Key UUID ---
Product_Maker_id: Mapped[UUID] = mapped_column(
Uuid,
primary_key=True,
server_default=func.uuid_generate_v4()
)
# --- Business Info ---
business_name: Mapped[str] = mapped_column(Text)
business_registration_path: Mapped[str] = mapped_column(Text)
year_incorporated: Mapped[str] = mapped_column(Text)
founder_ceo: Mapped[str] = mapped_column(Text)
website: Mapped[str] = mapped_column(Text)
category: Mapped[str] = mapped_column(Text)
# --- Composite: Office Address ---
office_address: Mapped[Address] = composite(
Address,
mapped_column('office_street', String(255)),
mapped_column('office_city', String(255)),
mapped_column('office_state', String(255)),
mapped_column('office_postal_code', String(20)),
mapped_column('office_country', String(255)),
)
# --- Composite: Warehouse Address ---
warehouse_address: Mapped[Address] = composite(
Address,
mapped_column('warehouse_street', String(255)),
mapped_column('warehouse_city', String(255)),
mapped_column('warehouse_state', String(255)),
mapped_column('warehouse_postal_code', String(20)),
mapped_column('warehouse_country', String(255)),
)
# --- Composite: Telephone ---
telephone: Mapped[Telephone] = composite(
Telephone,
mapped_column('tel_country_code', String(10)),
mapped_column('tel_area_code', String(10)),
mapped_column('tel_number', String(50)),
)
# --- Validation & Audit ---
validation_status: Mapped[bool] = mapped_column(Boolean)
last_validation_date: Mapped[Date] = mapped_column(Date)
created_at: Mapped[Date] = mapped_column(TIMESTAMP)
created_by: Mapped[str] = mapped_column(Text)
updated_at: Mapped[Date] = mapped_column(TIMESTAMP)
# --- ForeignKey & Relationships ---
TSI_User_Info_id: Mapped[UUID] = mapped_column(
Uuid,
ForeignKey('TSI_User_Info.TSI_User_Info_id')
)
tsi_user_info: Mapped["TSIUserInfo"] = relationship(
"TSIUserInfo",
back_populates="product_makers"
)
awards: Mapped[List["ProductMakerAward"]] = relationship(
"ProductMakerAward",
back_populates="product_maker",
cascade="all, delete-orphan"
)
contact_persons: Mapped[List["ProductMakerContactPerson"]] = relationship(
"ProductMakerContactPerson",
back_populates="product_maker",
cascade="all, delete-orphan"
)
programs: Mapped[List["ProductMakerProgram"]] = relationship(
"ProductMakerProgram",
back_populates="product_maker",
cascade="all, delete-orphan"
)