versione prima dle menu della clincia
This commit is contained in:
24
backend/app/db/init_db.py
Normal file
24
backend/app/db/init_db.py
Normal file
@@ -0,0 +1,24 @@
|
||||
import hashlib
|
||||
|
||||
from sqlalchemy import select
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from app.db.base import Base
|
||||
from app.db.session import SessionLocal, engine
|
||||
from app.models import TestUser
|
||||
|
||||
|
||||
def init_db() -> None:
|
||||
Base.metadata.create_all(bind=engine)
|
||||
seed_test_data()
|
||||
|
||||
|
||||
def seed_test_data() -> None:
|
||||
with SessionLocal() as db:
|
||||
existing_user = db.scalar(select(TestUser).where(TestUser.username == "admin_test"))
|
||||
if existing_user:
|
||||
return
|
||||
|
||||
password_hash = hashlib.sha256("change_me_123".encode("utf-8")).hexdigest()
|
||||
db.add(TestUser(username="admin_test", password_hash=password_hash))
|
||||
db.commit()
|
||||
Reference in New Issue
Block a user