38 lines
1.5 KiB
Python
Executable File
38 lines
1.5 KiB
Python
Executable File
import asyncio
|
|
from sqlalchemy import text
|
|
from app.db.session import SessionLocal, engine
|
|
from app.models.user import User, 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"))
|
|
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.")
|
|
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.")
|
|
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!")
|
|
|
|
if __name__ == "__main__":
|
|
asyncio.run(run_fix())
|