52 lines
2.0 KiB
Python
Executable File
52 lines
2.0 KiB
Python
Executable File
import enum
|
|
from sqlalchemy import Column, Integer, String, Boolean, Enum, DateTime, ForeignKey
|
|
from sqlalchemy.orm import relationship
|
|
from sqlalchemy.sql import func
|
|
from app.db.base import Base
|
|
|
|
class OrgType(str, enum.Enum):
|
|
INDIVIDUAL = "individual"
|
|
SERVICE = "service"
|
|
FLEET_OWNER = "fleet_owner"
|
|
CLUB = "club"
|
|
|
|
class Organization(Base):
|
|
__tablename__ = "organizations"
|
|
__table_args__ = {"schema": "data"}
|
|
|
|
id = Column(Integer, primary_key=True, index=True)
|
|
name = Column(String, nullable=False)
|
|
# A stabilitás miatt VARCHAR-ként kezeljük a DB-ben
|
|
org_type = Column(String(50), default="individual")
|
|
|
|
# A flotta technikai tulajdonosa (User)
|
|
owner_id = Column(Integer, ForeignKey("data.users.id"), nullable=True)
|
|
|
|
# Üzleti szabályok
|
|
is_active = Column(Boolean, default=True)
|
|
is_transferable = Column(Boolean, default=True)
|
|
|
|
# Verifikáció
|
|
is_verified = Column(Boolean, default=False)
|
|
verification_expires_at = Column(DateTime(timezone=True), nullable=True)
|
|
|
|
created_at = Column(DateTime(timezone=True), server_default=func.now())
|
|
updated_at = Column(DateTime(timezone=True), onupdate=func.now())
|
|
|
|
# Kapcsolatok (Asset-re hivatkozunk a Vehicle helyett)
|
|
assets = relationship("Asset", back_populates="organization", cascade="all, delete-orphan")
|
|
members = relationship("OrganizationMember", back_populates="organization")
|
|
owner = relationship("User", back_populates="owned_organizations")
|
|
|
|
class OrganizationMember(Base):
|
|
__tablename__ = "organization_members"
|
|
__table_args__ = {"schema": "data"}
|
|
id = Column(Integer, primary_key=True, index=True)
|
|
organization_id = Column(Integer, ForeignKey("data.organizations.id"), nullable=False)
|
|
user_id = Column(Integer, ForeignKey("data.users.id"), nullable=False)
|
|
role = Column(String, default="driver")
|
|
|
|
organization = relationship("Organization", back_populates="members")
|
|
|
|
# --- EZT A SORT TEDD KÍVÜLRE, A MARGÓRA ---
|
|
Organization.vehicles = Organization.assets |