1
0
mirror of https://gitlab.com/MoonTestUse1/AdministrationItDepartmens.git synced 2025-08-14 00:25:46 +02:00

Fix init tables

This commit is contained in:
MoonTestUse1
2025-01-06 22:56:27 +06:00
parent ed2a1185b7
commit 28a20247d5
5 changed files with 41 additions and 7 deletions

22
backend/app/db/init_db.py Normal file
View File

@@ -0,0 +1,22 @@
"""Database initialization script"""
from sqlalchemy.orm import Session
from app.core.config import settings
from app.models.employee import Employee
from app.utils.auth import get_password_hash
def init_db(db: Session) -> None:
"""Initialize database with default data"""
# Создаем администратора по умолчанию
admin = db.query(Employee).filter(Employee.email == settings.ADMIN_USERNAME).first()
if not admin:
admin = Employee(
email=settings.ADMIN_USERNAME,
full_name="System Administrator",
hashed_password=get_password_hash(settings.ADMIN_PASSWORD),
is_active=True,
is_admin=True,
department="Administration"
)
db.add(admin)
db.commit()
db.refresh(admin)