Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| c66b57f9cb | |||
| ba30f84f49 | |||
| 81935daaf5 | |||
| d2260ac797 | |||
| ca6f39a3e8 | |||
| 5eb5bd426a |
33
HISTORY.md
33
HISTORY.md
@@ -5,10 +5,43 @@ Changelog
|
|||||||
(unreleased)
|
(unreleased)
|
||||||
------------
|
------------
|
||||||
|
|
||||||
|
Fix
|
||||||
|
~~~
|
||||||
|
- Fix database init, refs NOISSUE. [Simon Diesenreiter]
|
||||||
|
|
||||||
|
|
||||||
|
0.3.3 (2026-04-04)
|
||||||
|
------------------
|
||||||
|
|
||||||
|
Fix
|
||||||
|
~~~
|
||||||
|
- Fix runtime errors, refs NOISSUE. [Simon Diesenreiter]
|
||||||
|
|
||||||
|
Other
|
||||||
|
~~~~~
|
||||||
|
|
||||||
|
|
||||||
|
0.3.2 (2026-04-04)
|
||||||
|
------------------
|
||||||
|
|
||||||
|
Fix
|
||||||
|
~~~
|
||||||
|
- Add back DB init endpoints, ref NOISSUE. [Simon Diesenreiter]
|
||||||
|
|
||||||
|
Other
|
||||||
|
~~~~~
|
||||||
|
|
||||||
|
|
||||||
|
0.3.1 (2026-04-04)
|
||||||
|
------------------
|
||||||
|
|
||||||
Fix
|
Fix
|
||||||
~~~
|
~~~
|
||||||
- Fix broken Docker build, refs NOISSUE. [Simon Diesenreiter]
|
- Fix broken Docker build, refs NOISSUE. [Simon Diesenreiter]
|
||||||
|
|
||||||
|
Other
|
||||||
|
~~~~~
|
||||||
|
|
||||||
|
|
||||||
0.3.0 (2026-04-04)
|
0.3.0 (2026-04-04)
|
||||||
------------------
|
------------------
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
{"dark_mode":false}
|
||||||
@@ -1 +1 @@
|
|||||||
0.3.1
|
0.3.4
|
||||||
|
|||||||
@@ -20,27 +20,33 @@ 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
|
||||||
# Fetch recent audit trail entries
|
current_project = db_session.query(ProjectHistory).order_by(ProjectHistory.created_at.desc()).first()
|
||||||
recent_audits = db_session.query(AuditTrail).order_by(AuditTrail.created_at.desc()).limit(10).all()
|
|
||||||
|
# Fetch recent audit trail entries
|
||||||
# Fetch recent project history entries
|
recent_audits = db_session.query(AuditTrail).order_by(AuditTrail.created_at.desc()).limit(10).all()
|
||||||
recent_projects = db_session.query(ProjectHistory).order_by(ProjectHistory.created_at.desc()).limit(5).all()
|
|
||||||
|
# Fetch recent project history entries
|
||||||
# Fetch recent system logs
|
recent_projects = db_session.query(ProjectHistory).order_by(ProjectHistory.created_at.desc()).limit(5).all()
|
||||||
recent_logs = db_session.query(SystemLog).order_by(SystemLog.created_at.desc()).limit(5).all()
|
|
||||||
|
# Fetch recent system logs
|
||||||
|
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().classes('w-full max-w-6xl mx-auto').props('elevated').style('max-width: 1200px; margin: 0 auto;') as main_card:
|
||||||
# Header section
|
# Header section
|
||||||
with ui.row().classes('items-center gap-4 mb-6').style('padding: 20px; background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); border-radius: 12px; color: white;') as header_row:
|
with ui.row().classes('items-center gap-4 mb-6').style('padding: 20px; background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); border-radius: 12px; color: white;') as header_row:
|
||||||
title = ui.label('AI Software Factory').style('font-size: 28px; font-weight: bold; margin: 0;')
|
title = ui.label('AI Software Factory').style('font-size: 28px; font-weight: bold; margin: 0;')
|
||||||
subtitle = ui.label('Real-time Dashboard & Audit Trail Display').style('font-size: 14px; opacity: 0.9; margin-top: 5px;')
|
subtitle = ui.label('Real-time Dashboard & Audit Trail Display').style('font-size: 14px; opacity: 0.9; margin-top: 5px;')
|
||||||
|
|
||||||
# Stats grid
|
# Stats grid
|
||||||
with ui.grid(columns=4, cols=4).props('gutter=1').style('margin-top: 15px;') as stats_grid:
|
with ui.grid(columns=4).props('gutter=1').style('margin-top: 15px;') as stats_grid:
|
||||||
# Current Project
|
# Current Project
|
||||||
with ui.column().classes('text-center').style('background: rgba(255, 255, 255, 0.1); padding: 15px; border-radius: 8px;') as card1:
|
with ui.column().classes('text-center').style('background: rgba(255, 255, 255, 0.1); padding: 15px; border-radius: 8px;') as card1:
|
||||||
ui.label('Current Project').style('font-size: 12px; text-transform: uppercase; opacity: 0.8;')
|
ui.label('Current Project').style('font-size: 12px; text-transform: uppercase; opacity: 0.8;')
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
"""Database connection and session management."""
|
"""Database connection and session management."""
|
||||||
|
|
||||||
from sqlalchemy import create_engine, event
|
from sqlalchemy import create_engine, text
|
||||||
from sqlalchemy.orm import sessionmaker, Session
|
from sqlalchemy.orm import sessionmaker, Session
|
||||||
from config import settings
|
from config import settings
|
||||||
from models import Base
|
from models import Base
|
||||||
@@ -92,18 +92,86 @@ def get_db_session() -> Session:
|
|||||||
return session
|
return session
|
||||||
|
|
||||||
|
|
||||||
def init_db() -> None:
|
def init_db() -> dict:
|
||||||
"""Initialize database tables."""
|
"""Initialize database tables and database if needed."""
|
||||||
engine = get_engine()
|
if settings.USE_SQLITE:
|
||||||
Base.metadata.create_all(bind=engine)
|
# SQLite - auto-creates file and tables
|
||||||
print("Database tables created successfully.")
|
engine = get_engine()
|
||||||
|
try:
|
||||||
|
Base.metadata.create_all(bind=engine)
|
||||||
|
print("SQLite database tables created successfully.")
|
||||||
|
return {'status': 'success', 'message': 'SQLite database initialized.'}
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Error initializing SQLite database: {str(e)}")
|
||||||
|
return {'status': 'error', 'message': f'Error: {str(e)}'}
|
||||||
|
else:
|
||||||
|
# PostgreSQL
|
||||||
|
db_url = settings.POSTGRES_URL or settings.database_url
|
||||||
|
db_name = db_url.split('/')[-1] if '/' in db_url else 'ai_software_factory'
|
||||||
|
|
||||||
|
try:
|
||||||
|
# Create engine to check/create database
|
||||||
|
engine = create_engine(db_url)
|
||||||
|
|
||||||
|
# Try to create database if it doesn't exist
|
||||||
|
try:
|
||||||
|
with engine.connect() as conn:
|
||||||
|
# Check if database exists
|
||||||
|
result = conn.execute(text(f"SELECT 1 FROM {db_name} WHERE 1=0"))
|
||||||
|
# If no error, database exists
|
||||||
|
conn.commit()
|
||||||
|
print(f"PostgreSQL database '{db_name}' already exists.")
|
||||||
|
except Exception as e:
|
||||||
|
# Database doesn't exist or has different error - try to create it
|
||||||
|
error_msg = str(e).lower()
|
||||||
|
# Only create if it's a relation does not exist error or similar
|
||||||
|
if "does not exist" in error_msg or "database" in error_msg:
|
||||||
|
try:
|
||||||
|
conn = engine.connect()
|
||||||
|
conn.execute(text(f"CREATE DATABASE {db_name}"))
|
||||||
|
conn.commit()
|
||||||
|
print(f"PostgreSQL database '{db_name}' created.")
|
||||||
|
except Exception as db_error:
|
||||||
|
print(f"Could not create database: {str(db_error)}")
|
||||||
|
# Try to connect anyway - maybe using existing db name
|
||||||
|
engine = create_engine(db_url.replace(f'/{db_name}', '/postgres'))
|
||||||
|
with engine.connect() as conn:
|
||||||
|
# Just create tables in postgres database for now
|
||||||
|
print(f"Using existing 'postgres' database.")
|
||||||
|
|
||||||
|
# Create tables
|
||||||
|
Base.metadata.create_all(bind=engine)
|
||||||
|
print(f"PostgreSQL database '{db_name}' tables created successfully.")
|
||||||
|
return {'status': 'success', 'message': f'PostgreSQL database "{db_name}" initialized.'}
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Error initializing PostgreSQL database: {str(e)}")
|
||||||
|
return {'status': 'error', 'message': f'Error: {str(e)}'}
|
||||||
|
|
||||||
|
|
||||||
def drop_db() -> None:
|
def drop_db() -> dict:
|
||||||
"""Drop all database tables (use with caution!)."""
|
"""Drop all database tables (use with caution!)."""
|
||||||
engine = get_engine()
|
if settings.USE_SQLITE:
|
||||||
Base.metadata.drop_all(bind=engine)
|
engine = get_engine()
|
||||||
print("Database tables dropped successfully.")
|
try:
|
||||||
|
Base.metadata.drop_all(bind=engine)
|
||||||
|
print("SQLite database tables dropped successfully.")
|
||||||
|
return {'status': 'success', 'message': 'SQLite tables dropped.'}
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Error dropping SQLite tables: {str(e)}")
|
||||||
|
return {'status': 'error', 'message': str(e)}
|
||||||
|
else:
|
||||||
|
db_url = settings.POSTGRES_URL or settings.database_url
|
||||||
|
db_name = db_url.split('/')[-1] if '/' in db_url else 'ai_software_factory'
|
||||||
|
|
||||||
|
try:
|
||||||
|
engine = create_engine(db_url)
|
||||||
|
Base.metadata.drop_all(bind=engine)
|
||||||
|
print(f"PostgreSQL database '{db_name}' tables dropped successfully.")
|
||||||
|
return {'status': 'success', 'message': f'PostgreSQL "{db_name}" tables dropped.'}
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Error dropping PostgreSQL tables: {str(e)}")
|
||||||
|
return {'status': 'error', 'message': str(e)}
|
||||||
|
|
||||||
|
|
||||||
def create_migration_script() -> str:
|
def create_migration_script() -> str:
|
||||||
|
|||||||
@@ -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,16 @@ 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)."""
|
||||||
|
try:
|
||||||
|
init_db()
|
||||||
|
return {'message': 'Database tables created successfully', 'status': 'success'}
|
||||||
|
except Exception as e:
|
||||||
|
return {'message': f'Error initializing database: {str(e)}', 'status': 'error'}
|
||||||
|
|
||||||
|
|
||||||
frontend.init(app)
|
frontend.init(app)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|||||||
Reference in New Issue
Block a user