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,41 @@
"""Script to add a new employee to the database"""
import sys
from pathlib import Path
# Add the parent directory to sys.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 add_employee():
db = SessionLocal()
try:
# Create employee data
employee = EmployeeCreate(
first_name="", # Имя не указано в требованиях
last_name="Лесников",
department="general", # Общий отдел
office="101",
password="1111"
)
# Check if employee already exists
existing_employee = employees.get_employee_by_lastname(db, employee.last_name)
if existing_employee:
print(f"Сотрудник {employee.last_name} уже существует")
return
# Create new employee
db_employee = employees.create_employee(db, employee)
print(f"Создан сотрудник: {db_employee.last_name} (ID: {db_employee.id})")
except Exception as e:
print(f"Ошибка при создании сотрудника: {e}")
raise e
finally:
db.close()
if __name__ == "__main__":
add_employee()

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()

View File

@@ -7,6 +7,9 @@ RUN apt-get update && apt-get install -y \
gcc \ gcc \
&& rm -rf /var/lib/apt/lists/* && rm -rf /var/lib/apt/lists/*
# Create logs directory
RUN mkdir -p /app/logs
# Copy requirements first to leverage Docker cache # Copy requirements first to leverage Docker cache
COPY backend/requirements.txt . COPY backend/requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt RUN pip install --no-cache-dir -r requirements.txt
@@ -14,7 +17,14 @@ RUN pip install --no-cache-dir -r requirements.txt
# Copy application code # Copy application code
COPY backend/ . COPY backend/ .
# Make entrypoint script executable
COPY docker/backend/entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh
# Create volume for logs
VOLUME ["/app/logs"]
# Expose the port the app runs on # Expose the port the app runs on
EXPOSE 8000 EXPOSE 8000
CMD ["python", "run.py"] ENTRYPOINT ["/entrypoint.sh"]

View File

@@ -0,0 +1,8 @@
#!/bin/sh
set -e
# Run database initialization
python /app/scripts/init_db.py
# Start the main application
exec python /app/run.py