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

Fix database

This commit is contained in:
MoonTestUse1
2025-01-07 05:26:33 +06:00
parent d9e276ad6b
commit bdf4ae9d70
29 changed files with 727 additions and 531 deletions

View File

@@ -1,21 +1,22 @@
"""Database initialization script"""
"""Database initialization"""
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
from ..models.employee import Employee
from ..utils.auth import get_password_hash
def init_db(db: Session) -> None:
"""Initialize database with default data"""
# Создаем тестового сотрудника
test_employee = db.query(Employee).filter(Employee.last_name == "User").first()
if not test_employee:
test_employee = Employee(
first_name="Test",
# Проверяем, есть ли уже админ в базе
admin = db.query(Employee).filter(Employee.is_admin == True).first()
if not admin:
# Создаем админа по умолчанию
admin = Employee(
first_name="Admin",
last_name="User",
department="IT",
office="101",
hashed_password=get_password_hash("testpass123")
office="102",
hashed_password=get_password_hash("adminpass123"),
is_admin=True
)
db.add(test_employee)
db.add(admin)
db.commit()
db.refresh(test_employee)
db.refresh(admin)