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

Починка админки2

This commit is contained in:
MoonTestUse1
2024-12-31 02:53:38 +06:00
parent 25a872beaf
commit a3b9a995f8
4 changed files with 97 additions and 1 deletions

View File

@@ -0,0 +1,37 @@
"""Database initialization script that runs on container startup"""
import sys
from pathlib import Path
sys.path.append(str(Path(__file__).resolve().parents[1]))
from app.database import SessionLocal
from app.crud import employees
from app.models.employee import EmployeeCreate
def init_db():
db = SessionLocal()
try:
# Create default employee
employee = EmployeeCreate(
first_name="Сотрудник",
last_name="Лесников",
department="general",
office="101",
password="1111"
)
existing = employees.get_employee_by_lastname(db, employee.last_name)
if not existing:
employees.create_employee(db, employee)
print("Default employee created successfully")
else:
print("Default employee already exists")
except Exception as e:
print(f"Error initializing database: {e}")
raise
finally:
db.close()
if __name__ == "__main__":
init_db()