2 Commits
0.3.3 ... 0.3.4

Author SHA1 Message Date
c66b57f9cb release: version 0.3.4 🚀 2026-04-05 00:19:31 +02:00
ba30f84f49 fix: fix database init, refs NOISSUE 2026-04-05 00:19:29 +02:00
6 changed files with 97 additions and 14 deletions

View File

@@ -5,10 +5,21 @@ Changelog
(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)
------------------

View File

@@ -0,0 +1 @@
{"dark_mode":false}

View File

@@ -1 +1 @@
0.3.3
0.3.4

View File

@@ -46,7 +46,7 @@ def create_dashboard():
subtitle = ui.label('Real-time Dashboard & Audit Trail Display').style('font-size: 14px; opacity: 0.9; margin-top: 5px;')
# 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
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;')

View File

@@ -1,6 +1,6 @@
"""Database connection and session management."""
from sqlalchemy import create_engine, event
from sqlalchemy import create_engine, text
from sqlalchemy.orm import sessionmaker, Session
from config import settings
from models import Base
@@ -92,18 +92,86 @@ def get_db_session() -> Session:
return session
def init_db() -> None:
"""Initialize database tables."""
def init_db() -> dict:
"""Initialize database tables and database if needed."""
if settings.USE_SQLITE:
# SQLite - auto-creates file and tables
engine = get_engine()
try:
Base.metadata.create_all(bind=engine)
print("Database tables created successfully.")
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!)."""
if settings.USE_SQLITE:
engine = get_engine()
try:
Base.metadata.drop_all(bind=engine)
print("Database tables dropped successfully.")
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:

View File

@@ -27,8 +27,11 @@ def read_root():
@app.post('/init-db')
def initialize_database():
"""Initialize database tables (POST endpoint for NiceGUI to call before dashboard)."""
try:
init_db()
return {'message': 'Database initialized successfully'}
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)