STABLE: KYC and Auth working, before Asset refactor
This commit is contained in:
@@ -5,15 +5,102 @@ from sqlalchemy.sql import func
|
||||
import uuid
|
||||
from app.db.base import Base
|
||||
|
||||
class VehicleBrand(Base):
|
||||
__tablename__ = "vehicle_brands"
|
||||
# 1. GLOBÁLIS KATALÓGUS (A rendszer agya)
|
||||
class VehicleCatalog(Base):
|
||||
__tablename__ = "vehicle_catalog"
|
||||
__table_args__ = {"schema": "data"}
|
||||
|
||||
id = Column(Integer, primary_key=True, index=True)
|
||||
name = Column(String(100), nullable=False, unique=True)
|
||||
slug = Column(String(100), unique=True)
|
||||
country_of_origin = Column(String(50))
|
||||
is_active = Column(Boolean, default=True)
|
||||
brand = Column(String(100), nullable=False)
|
||||
model = Column(String(100), nullable=False)
|
||||
generation = Column(String(100))
|
||||
year_from = Column(Integer)
|
||||
year_to = Column(Integer)
|
||||
category = Column(String(50)) # car, bike, boat, plane, truck
|
||||
engine_type = Column(String(50)) # petrol, diesel, electric, hybrid
|
||||
engine_power_kw = Column(Integer)
|
||||
|
||||
# DNS ADATOK: Minden technikai részlet (kerékméret, olajmennyiség, stb.)
|
||||
factory_specs = Column(JSON, default={})
|
||||
# SZERVIZTERV: Gyári előírások
|
||||
maintenance_plan = Column(JSON, default={})
|
||||
|
||||
created_at = Column(DateTime(timezone=True), server_default=func.now())
|
||||
updated_at = Column(DateTime(timezone=True), onupdate=func.now())
|
||||
|
||||
# 2. EGYEDI ESZKÖZ (Asset) - A felhasználó tulajdona
|
||||
class Asset(Base):
|
||||
__tablename__ = "assets"
|
||||
__table_args__ = {"schema": "data"}
|
||||
|
||||
id = Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
||||
uai = Column(String(100), unique=True, nullable=False) # VIN, HIN vagy Serial Number
|
||||
organization_id = Column(Integer, ForeignKey("data.organizations.id"))
|
||||
catalog_id = Column(Integer, ForeignKey("data.vehicle_catalog.id"), nullable=True)
|
||||
|
||||
asset_type = Column(String(20), nullable=False) # car, boat, plane
|
||||
name = Column(String(255)) # "Kincses E39"
|
||||
|
||||
# Dinamikus állapot
|
||||
current_plate_number = Column(String(20))
|
||||
current_country_code = Column(String(2))
|
||||
odometer_value = Column(Numeric(12, 2), default=0)
|
||||
operating_hours = Column(Numeric(12, 2), default=0)
|
||||
|
||||
# Egyedi DNS (Gyári config + utólagos módosítások)
|
||||
factory_config = Column(JSON, default={})
|
||||
aftermarket_mods = Column(JSON, default={})
|
||||
|
||||
status = Column(String(50), default="active")
|
||||
created_at = Column(DateTime(timezone=True), server_default=func.now())
|
||||
updated_at = Column(DateTime(timezone=True), onupdate=func.now())
|
||||
|
||||
# Kapcsolatok
|
||||
organization = relationship("Organization", back_populates="assets")
|
||||
catalog_entry = relationship("VehicleCatalog")
|
||||
events = relationship("AssetEvent", back_populates="asset", cascade="all, delete-orphan")
|
||||
ratings = relationship("AssetRating", back_populates="asset")
|
||||
|
||||
# 3. DIGITÁLIS SZERVIZKÖNYV / ESEMÉNYTÁR
|
||||
class AssetEvent(Base):
|
||||
__tablename__ = "asset_events"
|
||||
__table_args__ = {"schema": "data"}
|
||||
|
||||
id = Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
||||
asset_id = Column(UUID(as_uuid=True), ForeignKey("data.assets.id"))
|
||||
event_type = Column(String(50)) # SERVICE, REPAIR, INSPECTION, ACCIDENT, PLATE_CHANGE
|
||||
|
||||
odometer_at_event = Column(Numeric(12, 2))
|
||||
hours_at_event = Column(Numeric(12, 2))
|
||||
|
||||
description = Column(String)
|
||||
cost = Column(Numeric(12, 2))
|
||||
currency = Column(String(3), default="EUR")
|
||||
|
||||
is_verified = Column(Boolean, default=False)
|
||||
attachments = Column(JSON, default=[]) # Számlák, fotók linkjei
|
||||
|
||||
created_at = Column(DateTime(timezone=True), server_default=func.now())
|
||||
asset = relationship("Asset", back_populates="events")
|
||||
|
||||
# 4. EMOCIONÁLIS ÉRTÉKELÉS
|
||||
class AssetRating(Base):
|
||||
__tablename__ = "asset_ratings"
|
||||
__table_args__ = {"schema": "data"}
|
||||
|
||||
id = Column(Integer, primary_key=True)
|
||||
asset_id = Column(UUID(as_uuid=True), ForeignKey("data.assets.id"))
|
||||
user_id = Column(Integer, ForeignKey("data.users.id"))
|
||||
|
||||
comfort_score = Column(Integer) # 1-10
|
||||
experience_score = Column(Integer) # 1-10
|
||||
practicality_score = Column(Integer) # 1-10
|
||||
comment = Column(String)
|
||||
|
||||
created_at = Column(DateTime(timezone=True), server_default=func.now())
|
||||
asset = relationship("Asset", back_populates="ratings")
|
||||
|
||||
# 5. SZOLGÁLTATÓK (Szerelők, Partnerek)
|
||||
class ServiceProvider(Base):
|
||||
__tablename__ = "service_providers"
|
||||
__table_args__ = {"schema": "data"}
|
||||
@@ -21,67 +108,9 @@ class ServiceProvider(Base):
|
||||
name = Column(String(255), nullable=False)
|
||||
official_brand_partner = Column(Boolean, default=False)
|
||||
technical_rating_pct = Column(Integer, default=80)
|
||||
social_rating_pct = Column(Integer, default=80)
|
||||
location_city = Column(String(100))
|
||||
service_type = Column(String(50))
|
||||
search_tags = Column(String)
|
||||
latitude = Column(Numeric(10, 8))
|
||||
longitude = Column(Numeric(11, 8))
|
||||
is_active = Column(Boolean, default=True)
|
||||
records = relationship("ServiceRecord", back_populates="provider")
|
||||
|
||||
class EngineSpec(Base):
|
||||
__tablename__ = "engine_specs"
|
||||
__table_args__ = {"schema": "data"}
|
||||
id = Column(Integer, primary_key=True, index=True)
|
||||
engine_code = Column(String(50), unique=True)
|
||||
fuel_type = Column(String(20))
|
||||
power_kw = Column(Integer)
|
||||
default_service_interval_km = Column(Integer, default=15000)
|
||||
vehicles = relationship("Vehicle", back_populates="engine_spec")
|
||||
|
||||
class Vehicle(Base):
|
||||
__tablename__ = "vehicles"
|
||||
__table_args__ = {"schema": "data"}
|
||||
id = Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
||||
current_company_id = Column(Integer, ForeignKey("data.organizations.id"))
|
||||
brand_id = Column(Integer, ForeignKey("data.vehicle_brands.id"))
|
||||
model_name = Column(String(100))
|
||||
engine_spec_id = Column(Integer, ForeignKey("data.engine_specs.id"))
|
||||
identification_number = Column(String(50), unique=True)
|
||||
license_plate = Column(String(20))
|
||||
tracking_mode = Column(String(10), default="km")
|
||||
current_rating_pct = Column(Integer, default=100)
|
||||
total_real_usage = Column(Numeric(15, 2), default=0)
|
||||
created_at = Column(DateTime(timezone=True), server_default=func.now())
|
||||
|
||||
engine_spec = relationship("EngineSpec", back_populates="vehicles")
|
||||
service_records = relationship("ServiceRecord", back_populates="vehicle", cascade="all, delete-orphan")
|
||||
current_org = relationship("Organization", back_populates="vehicles")
|
||||
|
||||
class ServiceRecord(Base):
|
||||
__tablename__ = "service_records"
|
||||
__table_args__ = {"schema": "data"}
|
||||
id = Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
||||
vehicle_id = Column(UUID(as_uuid=True), ForeignKey("data.vehicles.id"))
|
||||
provider_id = Column(Integer, ForeignKey("data.service_providers.id"))
|
||||
service_date = Column(Date, nullable=False)
|
||||
usage_value = Column(Numeric(15, 2))
|
||||
repair_quality_pct = Column(Integer, default=100)
|
||||
|
||||
vehicle = relationship("Vehicle", back_populates="service_records")
|
||||
provider = relationship("ServiceProvider", back_populates="records")
|
||||
|
||||
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")
|
||||
|
||||
# --- KOMPATIBILITÁSI RÉTEG ---
|
||||
UserVehicle = Vehicle
|
||||
VehicleOwnership = Vehicle
|
||||
Vehicle = Asset
|
||||
ServiceRecord = AssetEvent
|
||||
Reference in New Issue
Block a user