STABLE: Final schema sync, optimized gitignore
This commit is contained in:
@@ -1,91 +1,129 @@
|
||||
# /opt/docker/dev/service_finder/backend/app/diagnose_system.py
|
||||
import asyncio
|
||||
import os
|
||||
from sqlalchemy import text, select
|
||||
from sqlalchemy.ext.asyncio import create_async_engine, AsyncSession
|
||||
from sqlalchemy.orm import sessionmaker
|
||||
import sys
|
||||
import logging
|
||||
from sqlalchemy import text, select, func
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
|
||||
# Importáljuk a rendszermodulokat az ellenőrzéshez
|
||||
# MB2.0 Importok
|
||||
try:
|
||||
from app.core.config import settings
|
||||
from app.core.i18n import t
|
||||
from app.models import SystemParameter
|
||||
from app.database import AsyncSessionLocal, engine
|
||||
from app.services.translation_service import translation_service
|
||||
from app.models.system import SystemParameter
|
||||
from app.models.identity import User
|
||||
from app.models.organization import Organization
|
||||
from app.models.asset import AssetCatalog
|
||||
from app.models.vehicle_definitions import VehicleModelDefinition
|
||||
except ImportError as e:
|
||||
print(f"❌ Import hiba: {e}")
|
||||
print("Ellenőrizd, hogy a PYTHONPATH be van-e állítva!")
|
||||
exit(1)
|
||||
print(f"❌ Kritikus import hiba: {e}")
|
||||
print("Győződj meg róla, hogy a PYTHONPATH tartalmazza a /backend mappát!")
|
||||
sys.exit(1)
|
||||
|
||||
# Naplózás kikapcsolása a tiszta diagnosztikai kimenetért
|
||||
logging.getLogger('sqlalchemy.engine').setLevel(logging.WARNING)
|
||||
|
||||
async def diagnose():
|
||||
print("\n" + "="*40)
|
||||
print("🔍 SZERVIZ KERESŐ - RENDSZER DIAGNOSZTIKA")
|
||||
print("="*40 + "\n")
|
||||
print("\n" + "═"*50)
|
||||
print("🛰️ SENTINEL SYSTEM DIAGNOSTICS - MB2.0 (2026)")
|
||||
print("═"*50 + "\n")
|
||||
|
||||
engine = create_async_engine(settings.DATABASE_URL)
|
||||
async_session = sessionmaker(engine, class_=AsyncSession, expire_on_commit=False)
|
||||
|
||||
async with async_session() as session:
|
||||
# --- 1. SÉMA ELLENŐRZÉSE ---
|
||||
print("1️⃣ Adatbázis séma ellenőrzése...")
|
||||
async with AsyncSessionLocal() as session:
|
||||
# --- 1. CSATLAKOZÁS ÉS ADATBÁZIS PING ---
|
||||
print("1️⃣ Kapcsolódási teszt...")
|
||||
try:
|
||||
# Organizations tábla oszlopai
|
||||
org_res = await session.execute(text(
|
||||
"SELECT column_name FROM information_schema.columns "
|
||||
"WHERE table_schema = 'data' AND table_name = 'organizations';"
|
||||
))
|
||||
org_cols = [row[0] for row in org_res.fetchall()]
|
||||
|
||||
# Users tábla oszlopai
|
||||
user_res = await session.execute(text(
|
||||
"SELECT column_name FROM information_schema.columns "
|
||||
"WHERE table_schema = 'data' AND table_name = 'users';"
|
||||
))
|
||||
user_cols = [row[0] for row in user_res.fetchall()]
|
||||
|
||||
checks = [
|
||||
("organizations.language", "language" in org_cols),
|
||||
("organizations.default_currency", "default_currency" in org_cols),
|
||||
("users.preferred_language", "preferred_language" in user_cols),
|
||||
("system_parameters tábla létezik", True) # Ha idáig eljut, a SystemParameter import sikerült
|
||||
]
|
||||
|
||||
for label, success in checks:
|
||||
status = "✅ OK" if success else "❌ HIÁNYZIK"
|
||||
print(f" [{status}] {label}")
|
||||
|
||||
await session.execute(text("SELECT 1"))
|
||||
print(" [✅ OK] PostgreSQL aszinkron kapcsolat aktív.")
|
||||
except Exception as e:
|
||||
print(f" ❌ Hiba a séma lekérdezésekor: {e}")
|
||||
print(f" [❌ HIBA] Nem sikerült kapcsolódni az adatbázishoz: {e}")
|
||||
return
|
||||
|
||||
# --- 2. ADATOK ELLENŐRZÉSE ---
|
||||
print("\n2️⃣ System Parameters (Alapadatok) ellenőrzése...")
|
||||
# --- 2. SÉMA INTEGRITÁS (MB2.0 Specifikus) ---
|
||||
print("\n2️⃣ Séma integritás ellenőrzése (Master Data)...")
|
||||
tables_to_check = [
|
||||
("identity.users", ["preferred_language", "scope_id", "is_active"]),
|
||||
("data.organizations", ["org_type", "folder_slug", "is_active"]),
|
||||
("data.assets", ["owner_org_id", "catalog_id", "vin"]),
|
||||
("data.asset_catalog", ["make", "model", "factory_data"]),
|
||||
("data.vehicle_model_definitions", ["status", "raw_search_context"])
|
||||
]
|
||||
|
||||
for table, columns in tables_to_check:
|
||||
try:
|
||||
schema, table_name = table.split('.')
|
||||
query = text(f"""
|
||||
SELECT column_name FROM information_schema.columns
|
||||
WHERE table_schema = '{schema}' AND table_name = '{table_name}';
|
||||
""")
|
||||
res = await session.execute(query)
|
||||
existing_cols = [row[0] for row in res.fetchall()]
|
||||
|
||||
if not existing_cols:
|
||||
print(f" [❌ HIBA] A tábla nem létezik: {table}")
|
||||
continue
|
||||
|
||||
missing = [c for c in columns if c not in existing_cols]
|
||||
if not missing:
|
||||
print(f" [✅ OK] {table} (Minden mező a helyén)")
|
||||
else:
|
||||
print(f" [⚠️ HIÁNY] {table} - Hiányzó mezők: {', '.join(missing)}")
|
||||
except Exception as e:
|
||||
print(f" [❌ HIBA] Hiba a(z) {table} ellenőrzésekor: {e}")
|
||||
|
||||
# --- 3. RENDSZER PARAMÉTEREK ---
|
||||
print("\n3️⃣ System Parameters (Sentinel Config) ellenőrzése...")
|
||||
try:
|
||||
result = await session.execute(select(SystemParameter))
|
||||
params = result.scalars().all()
|
||||
res = await session.execute(select(SystemParameter))
|
||||
params = res.scalars().all()
|
||||
if params:
|
||||
print(f" ✅ Talált paraméterek: {len(params)} db")
|
||||
for p in params:
|
||||
print(f" - {p.key}: {p.value[:2]}... (+{len(p.value)-2} elem)")
|
||||
print(f" [✅ OK] Talált paraméterek: {len(params)} db")
|
||||
critical_keys = ["SECURITY_MAX_RECORDS_PER_HOUR", "VEHICLE_LIMIT"]
|
||||
existing_keys = [p.key for p in params]
|
||||
for ck in critical_keys:
|
||||
status = "✔️" if ck in existing_keys else "❌"
|
||||
print(f" {status} {ck}")
|
||||
else:
|
||||
print(" ⚠️ Figyelem: A system_parameters tábla üres!")
|
||||
print(" [⚠️ FIGYELEM] A system_parameters tábla üres! Futtasd a seedert.")
|
||||
except Exception as e:
|
||||
print(f" ❌ Hiba az adatok lekérésekor: {e}")
|
||||
print(f" [❌ HIBA] SystemParameter lekérdezési hiba: {e}")
|
||||
|
||||
# --- 3. NYELVI MOTOR ELLENŐRZÉSE ---
|
||||
print("\n3️⃣ Nyelvi motor (i18n) és hu.json ellenőrzése...")
|
||||
# --- 4. i18n ÉS CACHE MOTOR ---
|
||||
print("\n4️⃣ Nyelvi motor és i18n Cache ellenőrzése...")
|
||||
try:
|
||||
test_save = t("COMMON.SAVE")
|
||||
test_email = t("email.reg_greeting", first_name="Admin")
|
||||
# Cache betöltése manuálisan a diagnosztikához
|
||||
await translation_service.load_cache(session)
|
||||
|
||||
if test_save != "COMMON.SAVE":
|
||||
print(f" ✅ Fordítás sikeres: COMMON.SAVE -> '{test_save}'")
|
||||
print(f" ✅ Paraméteres fordítás: '{test_email}'")
|
||||
test_key = "COMMON.SAVE"
|
||||
test_val = translation_service.get_text(test_key, "hu")
|
||||
|
||||
if test_val != f"[{test_key}]":
|
||||
print(f" [✅ OK] Fordítás sikeres (HU): {test_key} -> '{test_val}'")
|
||||
else:
|
||||
print(" ❌ A fordítás NEM működik (csak a kulcsot adta vissza).")
|
||||
print(f" Ellenőrizd a /app/app/locales/hu.json elérhetőségét!")
|
||||
print(f" [❌ HIBA] A fordítás nem működik. Nincs betöltött adat az adatbázisban.")
|
||||
except Exception as e:
|
||||
print(f" ❌ Hiba a nyelvi motor futtatásakor: {e}")
|
||||
print(f" [❌ HIBA] Nyelvi motor hiba: {e}")
|
||||
|
||||
print("\n" + "="*40)
|
||||
print("✅ DIAGNOSZTIKA KÉSZ")
|
||||
print("="*40 + "\n")
|
||||
# --- 5. ROBOT ELŐKÉSZÜLETEK (MDM) ---
|
||||
print("\n5️⃣ Robot Pipeline (MDM Staging) állapot...")
|
||||
try:
|
||||
res_hunter = await session.execute(
|
||||
select(func.count(VehicleModelDefinition.id)).where(VehicleModelDefinition.status == 'unverified')
|
||||
)
|
||||
unverified_count = res_hunter.scalar()
|
||||
|
||||
res_gold = await session.execute(
|
||||
select(func.count(AssetCatalog.id))
|
||||
)
|
||||
gold_count = res_gold.scalar()
|
||||
|
||||
print(f" [📊 ADAT] Staging rekordok (Hunter): {unverified_count} db")
|
||||
print(f" [📊 ADAT] Arany rekordok (Catalog): {gold_count} db")
|
||||
except Exception as e:
|
||||
print(f" [❌ HIBA] Robot-statisztika hiba: {e}")
|
||||
|
||||
print("\n" + "═"*50)
|
||||
print("🏁 DIAGNOSZTIKA BEFEJEZŐDÖTT")
|
||||
print("═"*50 + "\n")
|
||||
|
||||
if __name__ == "__main__":
|
||||
asyncio.run(diagnose())
|
||||
Reference in New Issue
Block a user