generated from Templates/Docker_Image
fix: add back DB init endpoints, ref NOISSUE
This commit is contained in:
@@ -20,17 +20,23 @@ def create_dashboard():
|
|||||||
return
|
return
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# Fetch current project
|
# Wrap database queries to handle missing tables gracefully
|
||||||
current_project = db_session.query(ProjectHistory).order_by(ProjectHistory.created_at.desc()).first()
|
try:
|
||||||
|
# Fetch current project
|
||||||
|
current_project = db_session.query(ProjectHistory).order_by(ProjectHistory.created_at.desc()).first()
|
||||||
|
|
||||||
# Fetch recent audit trail entries
|
# Fetch recent audit trail entries
|
||||||
recent_audits = db_session.query(AuditTrail).order_by(AuditTrail.created_at.desc()).limit(10).all()
|
recent_audits = db_session.query(AuditTrail).order_by(AuditTrail.created_at.desc()).limit(10).all()
|
||||||
|
|
||||||
# Fetch recent project history entries
|
# Fetch recent project history entries
|
||||||
recent_projects = db_session.query(ProjectHistory).order_by(ProjectHistory.created_at.desc()).limit(5).all()
|
recent_projects = db_session.query(ProjectHistory).order_by(ProjectHistory.created_at.desc()).limit(5).all()
|
||||||
|
|
||||||
# Fetch recent system logs
|
# Fetch recent system logs
|
||||||
recent_logs = db_session.query(SystemLog).order_by(SystemLog.created_at.desc()).limit(5).all()
|
recent_logs = db_session.query(SystemLog).order_by(SystemLog.created_at.desc()).limit(5).all()
|
||||||
|
except Exception as e:
|
||||||
|
# Handle missing tables or other database errors
|
||||||
|
ui.label(f'Database error: {str(e)}. Please run POST /init-db or ensure the database is initialized.')
|
||||||
|
return
|
||||||
|
|
||||||
# Create main card
|
# Create main card
|
||||||
with ui.card().col().classes('w-full max-w-6xl mx-auto').props('elevated').style('max-width: 1200px; margin: 0 auto;') as main_card:
|
with ui.card().col().classes('w-full max-w-6xl mx-auto').props('elevated').style('max-width: 1200px; margin: 0 auto;') as main_card:
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ The NiceGUI frontend provides:
|
|||||||
|
|
||||||
import frontend
|
import frontend
|
||||||
from fastapi import FastAPI
|
from fastapi import FastAPI
|
||||||
|
from database import init_db
|
||||||
|
|
||||||
app = FastAPI()
|
app = FastAPI()
|
||||||
|
|
||||||
@@ -23,6 +24,13 @@ def read_root():
|
|||||||
return {'Hello': 'World'}
|
return {'Hello': 'World'}
|
||||||
|
|
||||||
|
|
||||||
|
@app.post('/init-db')
|
||||||
|
def initialize_database():
|
||||||
|
"""Initialize database tables (POST endpoint for NiceGUI to call before dashboard)."""
|
||||||
|
init_db()
|
||||||
|
return {'message': 'Database initialized successfully'}
|
||||||
|
|
||||||
|
|
||||||
frontend.init(app)
|
frontend.init(app)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|||||||
Reference in New Issue
Block a user