- Split mother's name in KYC (last/first) - Added mileage_unit and fuel_type to Assets - Expanded AssetCost for international VAT and original currency - Fixed SQLAlchemy IndexError in asset catalog lookup - Added exchange_rate and ratings tables to models
88 lines
3.7 KiB
Python
88 lines
3.7 KiB
Python
import uuid
|
|
import enum
|
|
from sqlalchemy import Column, Integer, String, Boolean, DateTime, ForeignKey, JSON, Numeric, text, Enum, BigInteger
|
|
from sqlalchemy.orm import relationship
|
|
from sqlalchemy.dialects.postgresql import UUID as PG_UUID
|
|
from sqlalchemy.sql import func
|
|
from app.db.base_class import Base
|
|
|
|
class UserRole(str, enum.Enum):
|
|
admin = "admin"
|
|
user = "user"
|
|
service = "service"
|
|
fleet_manager = "fleet_manager"
|
|
driver = "driver"
|
|
|
|
class Person(Base):
|
|
__tablename__ = "persons"
|
|
__table_args__ = {"schema": "data"}
|
|
|
|
id = Column(BigInteger, primary_key=True, index=True)
|
|
id_uuid = Column(PG_UUID(as_uuid=True), default=uuid.uuid4, unique=True, nullable=False)
|
|
address_id = Column(PG_UUID(as_uuid=True), ForeignKey("data.addresses.id"), nullable=True)
|
|
|
|
last_name = Column(String, nullable=False)
|
|
first_name = Column(String, nullable=False)
|
|
mothers_last_name = Column(String, nullable=True)
|
|
mothers_first_name = Column(String, nullable=True)
|
|
birth_place = Column(String, nullable=True)
|
|
birth_date = Column(DateTime, nullable=True)
|
|
phone = Column(String, nullable=True)
|
|
|
|
identity_docs = Column(JSON, server_default=text("'{}'::jsonb"))
|
|
medical_emergency = Column(JSON, server_default=text("'{}'::jsonb"))
|
|
ice_contact = Column(JSON, server_default=text("'{}'::jsonb"))
|
|
|
|
is_active = Column(Boolean, default=False, nullable=False)
|
|
created_at = Column(DateTime(timezone=True), server_default=func.now())
|
|
updated_at = Column(DateTime(timezone=True), onupdate=func.now())
|
|
|
|
users = relationship("User", back_populates="person")
|
|
|
|
class User(Base):
|
|
__tablename__ = "users"
|
|
__table_args__ = {"schema": "data"}
|
|
|
|
id = Column(Integer, primary_key=True, index=True)
|
|
email = Column(String, unique=True, index=True, nullable=False)
|
|
hashed_password = Column(String, nullable=True)
|
|
role = Column(Enum(UserRole), default=UserRole.user)
|
|
is_active = Column(Boolean, default=False)
|
|
region_code = Column(String, default="HU")
|
|
is_deleted = Column(Boolean, default=False)
|
|
person_id = Column(BigInteger, ForeignKey("data.persons.id"), nullable=True)
|
|
|
|
person = relationship("Person", back_populates="users")
|
|
wallet = relationship("Wallet", back_populates="user", uselist=False)
|
|
|
|
# Itt a trükk: csak a string hivatkozás marad, így nincs import hiba,
|
|
# de a SQLAlchemy tudni fogja, hogy a UserStats-ra gondolunk.
|
|
stats = relationship("UserStats", back_populates="user", uselist=False)
|
|
|
|
owned_organizations = relationship("Organization", back_populates="owner", lazy="select")
|
|
created_at = Column(DateTime(timezone=True), server_default=func.now())
|
|
|
|
class Wallet(Base):
|
|
"""Kétoszlopos pénztárca: Coin (Szerviz) és Kredit (Prémium)."""
|
|
__tablename__ = "wallets"
|
|
__table_args__ = {"schema": "data"}
|
|
|
|
id = Column(Integer, primary_key=True, index=True)
|
|
user_id = Column(Integer, ForeignKey("data.users.id"), unique=True)
|
|
coin_balance = Column(Numeric(18, 2), default=0.00)
|
|
credit_balance = Column(Numeric(18, 2), default=0.00)
|
|
currency = Column(String(3), default="HUF")
|
|
|
|
user = relationship("User", back_populates="wallet")
|
|
|
|
class VerificationToken(Base):
|
|
__tablename__ = "verification_tokens"
|
|
__table_args__ = {"schema": "data"}
|
|
|
|
id = Column(Integer, primary_key=True, index=True)
|
|
token = Column(PG_UUID(as_uuid=True), default=uuid.uuid4, unique=True, nullable=False)
|
|
user_id = Column(Integer, ForeignKey("data.users.id", ondelete="CASCADE"), nullable=False)
|
|
token_type = Column(String(20), nullable=False)
|
|
created_at = Column(DateTime(timezone=True), server_default=func.now())
|
|
expires_at = Column(DateTime(timezone=True), nullable=False)
|
|
is_used = Column(Boolean, default=False) |