"Refactor database connection for improved data consistency (feat"
This commit is contained in:
Binary file not shown.
@@ -11,19 +11,33 @@ import importlib.util
|
||||
parent_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||
sys.path.insert(0, parent_dir)
|
||||
|
||||
from app import app, db_path
|
||||
# Direkt den Datenbankpfad berechnen, statt ihn aus app.py zu importieren
|
||||
def get_db_path():
|
||||
"""Berechnet den absoluten Pfad zur Datenbank"""
|
||||
basedir = os.path.abspath(os.path.dirname(os.path.dirname(__file__)))
|
||||
return os.path.join(basedir, 'database', 'systades.db')
|
||||
|
||||
# Import models direkt
|
||||
from models import db
|
||||
|
||||
def ensure_db_dir():
|
||||
"""Make sure the database directory exists."""
|
||||
db_path = get_db_path()
|
||||
os.makedirs(os.path.dirname(db_path), exist_ok=True)
|
||||
|
||||
def fix_database_schema():
|
||||
"""Fix the database schema by adding missing columns."""
|
||||
# Import Flask-App erst innerhalb der Funktion
|
||||
from flask import Flask
|
||||
from app import app
|
||||
|
||||
with app.app_context():
|
||||
# Ensure directory exists
|
||||
ensure_db_dir()
|
||||
|
||||
# Get database path
|
||||
db_path = get_db_path()
|
||||
|
||||
# Check if database exists, create tables if needed
|
||||
if not os.path.exists(db_path):
|
||||
print("Database doesn't exist. Creating all tables from scratch...")
|
||||
|
||||
Reference in New Issue
Block a user