Fix for DB initialization.
This commit is contained in:
@@ -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
12
app.py
@@ -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()]
|
||||
|
||||
Reference in New Issue
Block a user