STABLE: Final schema sync, optimized gitignore

This commit is contained in:
Kincses
2026-02-26 08:19:25 +01:00
parent 893f39fa15
commit 505543330a
203 changed files with 11590 additions and 9542 deletions

View File

@@ -1,37 +1,82 @@
# /opt/docker/dev/service_finder/backend/app/final_admin_fix.py
import asyncio
from sqlalchemy import text
from app.db.session import SessionLocal, engine
from app.models.user import User, UserRole
import uuid
from sqlalchemy import text, select
from app.database import AsyncSessionLocal
from app.models.identity import User, Person, UserRole
from app.core.security import get_password_hash
async def run_fix():
async with SessionLocal() as db:
# 1. Ellenőrizzük az oszlopokat (biztonsági játék)
res = await db.execute(text("SELECT column_name FROM information_schema.columns WHERE table_schema = \u0027data\u0027 AND table_name = \u0027users\u0027"))
print("\n" + ""*50)
print("🛠️ ADMIN RENDSZERJAVÍTÁS ÉS INICIALIZÁLÁS (MB2.0)")
print(""*50)
async with AsyncSessionLocal() as db:
# 1. LOGIKA: Séma ellenőrzése az 'identity' névtérben
# Az MB2.0-ban a felhasználók már nem a 'data', hanem az 'identity' sémában vannak.
check_query = text("""
SELECT column_name FROM information_schema.columns
WHERE table_schema = 'identity' AND table_name = 'users'
""")
res = await db.execute(check_query)
cols = [r[0] for r in res.fetchall()]
print(f"INFO: Meglévő oszlopok: {cols}")
if "hashed_password" not in cols:
print("❌ HIBA: A hashed_password oszlop még mindig hiányzik! A migráció nem volt sikeres.")
if not cols:
print("❌ HIBA: Az 'identity.users' tábla nem található. Futtasd az Alembic migrációt!")
return
# 2. Admin létrehozása
res = await db.execute(text("SELECT id FROM data.users WHERE email = :e"), {"e": "admin@profibot.hu"})
if res.fetchone():
print("⚠ Az admin@profibot.hu már létezik.")
if "hashed_password" not in cols:
print("❌ HIBA: A 'hashed_password' oszlop hiányzik. Az adatbázis sémája elavult.")
return
# 2. LOGIKA: Admin keresése
admin_email = "admin@profibot.hu"
stmt = select(User).where(User.email == admin_email)
existing_res = await db.execute(stmt)
existing_admin = existing_res.scalar_one_or_none()
if existing_admin:
print(f"⚠️ Információ: A(z) {admin_email} felhasználó már létezik.")
# Opcionális: Jelszó kényszerített frissítése, ha elfelejtetted
# existing_admin.hashed_password = get_password_hash("Admin123!")
# await db.commit()
else:
admin = User(
email="admin@profibot.hu",
hashed_password=get_password_hash("Admin123!"),
first_name="Admin",
last_name="Profibot",
role=UserRole.ADMIN,
is_superuser=True,
is_active=True
)
db.add(admin)
await db.commit()
print("✅ SIKER: Admin felhasználó létrehozva!")
try:
# 3. LOGIKA: Person és User létrehozása (MB2.0 Standard)
# Előbb létrehozzuk a fizikai személyt
new_person = Person(
id_uuid=uuid.uuid4(),
first_name="Rendszer",
last_name="Adminisztrátor",
is_active=True
)
db.add(new_person)
await db.flush() # ID lekérése a mentés előtt
# Létrehozzuk a felhasználói fiókot az Admin role-al
new_admin = User(
email=admin_email,
hashed_password=get_password_hash("Admin123!"),
person_id=new_person.id,
role=UserRole.superadmin, # MB2.0 enum érték
is_active=True,
is_deleted=False,
preferred_language="hu"
)
db.add(new_admin)
await db.commit()
print(f"✅ SIKER: Superadmin létrehozva!")
print(f" 📧 Email: {admin_email}")
print(f" 🔑 Jelszó: Admin123!")
except Exception as e:
print(f"❌ HIBA a mentés során: {e}")
await db.rollback()
print("\n" + ""*50)
print("🏁 JAVÍTÁSI FOLYAMAT BEFEJEZŐDÖTT")
print(""*50 + "\n")
if __name__ == "__main__":
asyncio.run(run_fix())
asyncio.run(run_fix())