mirror of
https://gitlab.com/MoonTestUse1/AdministrationItDepartmens.git
synced 2025-08-14 00:25:46 +02:00
Fix database
This commit is contained in:
@@ -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)
|
Reference in New Issue
Block a user