Fix for DB initialization.

This commit is contained in:
2025-07-01 15:03:03 +02:00
committed by Jens Luedicke
parent 6c27bdeea7
commit c9ee69712d
2 changed files with 16 additions and 4 deletions

View File

@@ -145,11 +145,11 @@ The application provides various endpoints for different user roles:
## File Structure
- `app.py`: Main Flask application
- `app.py`: Main Flask application with integrated migration system
- `models.py`: Database models and relationships
- `templates/`: HTML templates for all pages
- `static/`: CSS and JavaScript files
- `migrate_*.py`: Database migration scripts
- `migrate_*.py`: Legacy migration scripts (no longer needed)
## Contributing

12
app.py
View File

@@ -56,6 +56,7 @@ def run_migrations():
# Check if database exists
if not os.path.exists(db_path):
print("Database doesn't exist. Creating new database.")
with app.app_context():
db.create_all()
init_system_settings()
return
@@ -67,6 +68,17 @@ def run_migrations():
cursor = conn.cursor()
try:
# Check if time_entry table exists first
cursor.execute("SELECT name FROM sqlite_master WHERE type='table' AND name='time_entry'")
if not cursor.fetchone():
print("time_entry table doesn't exist. Creating all tables...")
with app.app_context():
db.create_all()
init_system_settings()
conn.commit()
conn.close()
return
# Migrate time_entry table
cursor.execute("PRAGMA table_info(time_entry)")
time_entry_columns = [column[1] for column in cursor.fetchall()]