- 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
92 lines
4.1 KiB
Python
Executable File
92 lines
4.1 KiB
Python
Executable File
import uuid
|
|
from datetime import datetime
|
|
from typing import Optional, TYPE_CHECKING
|
|
from sqlalchemy import ForeignKey, String, Integer, DateTime, func, Boolean
|
|
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
|
from sqlalchemy.dialects.postgresql import UUID as PG_UUID
|
|
from app.db.base_class import Base
|
|
|
|
# Típusvizsgálathoz a körkörös import elkerülése érdekében
|
|
if TYPE_CHECKING:
|
|
from app.models.identity import User
|
|
|
|
# Közös beállítás az összes táblához ebben a fájlban
|
|
SCHEMA_ARGS = {"schema": "data"}
|
|
|
|
class PointRule(Base):
|
|
__tablename__ = "point_rules"
|
|
__table_args__ = SCHEMA_ARGS
|
|
id: Mapped[int] = mapped_column(Integer, primary_key=True, index=True)
|
|
action_key: Mapped[str] = mapped_column(String, unique=True, index=True)
|
|
points: Mapped[int] = mapped_column(Integer, default=0)
|
|
description: Mapped[Optional[str]] = mapped_column(String)
|
|
is_active: Mapped[bool] = mapped_column(Boolean, default=True)
|
|
|
|
class LevelConfig(Base):
|
|
__tablename__ = "level_configs"
|
|
__table_args__ = SCHEMA_ARGS
|
|
id: Mapped[int] = mapped_column(Integer, primary_key=True, index=True)
|
|
level_number: Mapped[int] = mapped_column(Integer, unique=True)
|
|
min_points: Mapped[int] = mapped_column(Integer)
|
|
rank_name: Mapped[str] = mapped_column(String)
|
|
|
|
class RegionalSetting(Base):
|
|
__tablename__ = "regional_settings"
|
|
__table_args__ = SCHEMA_ARGS
|
|
id: Mapped[int] = mapped_column(Integer, primary_key=True, index=True)
|
|
country_code: Mapped[str] = mapped_column(String, unique=True)
|
|
currency: Mapped[str] = mapped_column(String, default="HUF")
|
|
is_active: Mapped[bool] = mapped_column(Boolean, default=True)
|
|
|
|
class PointsLedger(Base):
|
|
__tablename__ = "points_ledger"
|
|
__table_args__ = SCHEMA_ARGS
|
|
id: Mapped[int] = mapped_column(Integer, primary_key=True, index=True)
|
|
user_id: Mapped[int] = mapped_column(Integer, ForeignKey("data.users.id"))
|
|
points: Mapped[int] = mapped_column(Integer)
|
|
reason: Mapped[str] = mapped_column(String)
|
|
created_at: Mapped[datetime] = mapped_column(DateTime, default=func.now())
|
|
|
|
# Kapcsolat a felhasználóhoz
|
|
user: Mapped["User"] = relationship("User")
|
|
|
|
class UserStats(Base):
|
|
__tablename__ = "user_stats"
|
|
__table_args__ = SCHEMA_ARGS
|
|
# user_id a PK, mert 1:1 kapcsolat a User-rel
|
|
user_id: Mapped[int] = mapped_column(Integer, ForeignKey("data.users.id"), primary_key=True)
|
|
total_xp: Mapped[int] = mapped_column(Integer, default=0)
|
|
social_points: Mapped[int] = mapped_column(Integer, default=0)
|
|
current_level: Mapped[int] = mapped_column(Integer, default=1)
|
|
updated_at: Mapped[datetime] = mapped_column(DateTime, default=func.now(), onupdate=func.now())
|
|
|
|
# EZ A JAVÍTÁS: A visszamutató kapcsolat definiálása
|
|
user: Mapped["User"] = relationship("User", back_populates="stats")
|
|
|
|
class Badge(Base):
|
|
__tablename__ = "badges"
|
|
__table_args__ = SCHEMA_ARGS
|
|
id: Mapped[int] = mapped_column(Integer, primary_key=True, index=True)
|
|
name: Mapped[str] = mapped_column(String, unique=True)
|
|
description: Mapped[str] = mapped_column(String)
|
|
icon_url: Mapped[Optional[str]] = mapped_column(String)
|
|
|
|
class UserBadge(Base):
|
|
__tablename__ = "user_badges"
|
|
__table_args__ = SCHEMA_ARGS
|
|
id: Mapped[int] = mapped_column(Integer, primary_key=True, index=True)
|
|
user_id: Mapped[int] = mapped_column(Integer, ForeignKey("data.users.id"))
|
|
badge_id: Mapped[int] = mapped_column(Integer, ForeignKey("data.badges.id"))
|
|
earned_at: Mapped[datetime] = mapped_column(DateTime, default=func.now())
|
|
|
|
user: Mapped["User"] = relationship("User")
|
|
|
|
class Rating(Base): # <--- Az új értékelési modell
|
|
__tablename__ = "ratings"
|
|
__table_args__ = SCHEMA_ARGS
|
|
id: Mapped[uuid.UUID] = mapped_column(PG_UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
|
author_id: Mapped[int] = mapped_column(Integer, ForeignKey("data.users.id"))
|
|
target_type: Mapped[str] = mapped_column(String(20))
|
|
target_id: Mapped[uuid.UUID] = mapped_column(PG_UUID(as_uuid=True))
|
|
score: Mapped[int] = mapped_column(Integer)
|
|
comment: Mapped[Optional[str]] = mapped_column(String) |