admin frontend elkezdése, járművek tisztázása, frontend fejleszts
This commit is contained in:
94
backend/app/scripts/seed_services.py
Normal file
94
backend/app/scripts/seed_services.py
Normal file
@@ -0,0 +1,94 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Service Finder - ServiceCatalog Seed Script
|
||||
=============================================
|
||||
Aszinkron seed szkript a system.service_catalog tábla feltöltéséhez.
|
||||
Törli a meglévő adatokat, majd beszúrja a 3 alap szolgáltatást.
|
||||
|
||||
Használat:
|
||||
docker compose exec sf_api python3 /app/backend/app/scripts/seed_services.py
|
||||
"""
|
||||
|
||||
import asyncio
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
# Projekt gyökér hozzáadása a Python path-hoz
|
||||
sys.path.insert(0, str(Path(__file__).parent.parent.parent))
|
||||
|
||||
from sqlalchemy import text
|
||||
from app.db.session import AsyncSessionLocal
|
||||
from app.models.core_logic import ServiceCatalog
|
||||
|
||||
|
||||
SERVICES = [
|
||||
{
|
||||
"service_code": "SRV_DATA_EXPORT",
|
||||
"name": "Adat Export",
|
||||
"description": "PDF és Excel adatexport funkciók",
|
||||
"credit_cost": 0,
|
||||
},
|
||||
{
|
||||
"service_code": "SRV_AI_UPLOAD",
|
||||
"name": "AI Számlafeldolgozás",
|
||||
"description": "Dokumentumok és számlák AI alapú beolvasása",
|
||||
"credit_cost": 50,
|
||||
},
|
||||
{
|
||||
"service_code": "SRV_DIGITAL_BOOK",
|
||||
"name": "Digitális Szervizkönyv",
|
||||
"description": "Idegen járművek szerviztörténetének lekérdezése",
|
||||
"credit_cost": 150,
|
||||
},
|
||||
]
|
||||
|
||||
|
||||
async def seed_services():
|
||||
print("=" * 70)
|
||||
print(" ServiceCatalog Seed Script")
|
||||
print("=" * 70)
|
||||
|
||||
async with AsyncSessionLocal() as db:
|
||||
# 1. Tábla tartalmának törlése
|
||||
print("\n🧹 Törlés: system.service_catalog összes rekordja...")
|
||||
await db.execute(text("DELETE FROM system.service_catalog"))
|
||||
await db.commit()
|
||||
print(" ✅ Törölve.")
|
||||
|
||||
# 2. Szolgáltatások beszúrása
|
||||
print("\n📦 Szolgáltatások beszúrása:")
|
||||
for svc in SERVICES:
|
||||
stmt = text("""
|
||||
INSERT INTO system.service_catalog (service_code, name, description, credit_cost, is_active)
|
||||
VALUES (:service_code, :name, :description, :credit_cost, TRUE)
|
||||
""")
|
||||
await db.execute(stmt, svc)
|
||||
print(f" ✅ {svc['service_code']:20s} | {svc['name']:25s} | {svc['credit_cost']:>4} kredit")
|
||||
|
||||
await db.commit()
|
||||
print("\n ✅ Minden rekord beszúrva.")
|
||||
|
||||
# 3. Lekérdezés - bizonyíték
|
||||
print("\n" + "=" * 70)
|
||||
print(" 📋 LEKÉRDEZÉS - system.service_catalog tartalma")
|
||||
print("=" * 70)
|
||||
result = await db.execute(
|
||||
text("SELECT id, service_code, name, description, credit_cost, is_active FROM system.service_catalog ORDER BY id")
|
||||
)
|
||||
rows = result.fetchall()
|
||||
|
||||
if not rows:
|
||||
print("\n❌ NINCSENEK REKORDOK a táblában!")
|
||||
else:
|
||||
print(f"\n{'ID':>4} | {'Kód':20s} | {'Név':25s} | {'Leírás':45s} | {'Ár':>5s} | {'Aktív':>5s}")
|
||||
print("-" * 110)
|
||||
for row in rows:
|
||||
print(f"{row.id:>4} | {row.service_code:20s} | {row.name:25s} | {(row.description or ''):45s} | {row.credit_cost:>5} | {'Igen' if row.is_active else 'Nem'}")
|
||||
|
||||
print("\n" + "=" * 70)
|
||||
print(f" Összesen: {len(rows)} rekord a system.service_catalog táblában.")
|
||||
print("=" * 70)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
asyncio.run(seed_services())
|
||||
Reference in New Issue
Block a user