Fix for DB initialization.
This commit is contained in:
@@ -145,11 +145,11 @@ The application provides various endpoints for different user roles:
|
|||||||
|
|
||||||
## File Structure
|
## File Structure
|
||||||
|
|
||||||
- `app.py`: Main Flask application
|
- `app.py`: Main Flask application with integrated migration system
|
||||||
- `models.py`: Database models and relationships
|
- `models.py`: Database models and relationships
|
||||||
- `templates/`: HTML templates for all pages
|
- `templates/`: HTML templates for all pages
|
||||||
- `static/`: CSS and JavaScript files
|
- `static/`: CSS and JavaScript files
|
||||||
- `migrate_*.py`: Database migration scripts
|
- `migrate_*.py`: Legacy migration scripts (no longer needed)
|
||||||
|
|
||||||
## Contributing
|
## Contributing
|
||||||
|
|
||||||
|
|||||||
16
app.py
16
app.py
@@ -56,8 +56,9 @@ def run_migrations():
|
|||||||
# Check if database exists
|
# Check if database exists
|
||||||
if not os.path.exists(db_path):
|
if not os.path.exists(db_path):
|
||||||
print("Database doesn't exist. Creating new database.")
|
print("Database doesn't exist. Creating new database.")
|
||||||
db.create_all()
|
with app.app_context():
|
||||||
init_system_settings()
|
db.create_all()
|
||||||
|
init_system_settings()
|
||||||
return
|
return
|
||||||
|
|
||||||
print("Running database migrations...")
|
print("Running database migrations...")
|
||||||
@@ -67,6 +68,17 @@ def run_migrations():
|
|||||||
cursor = conn.cursor()
|
cursor = conn.cursor()
|
||||||
|
|
||||||
try:
|
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
|
# Migrate time_entry table
|
||||||
cursor.execute("PRAGMA table_info(time_entry)")
|
cursor.execute("PRAGMA table_info(time_entry)")
|
||||||
time_entry_columns = [column[1] for column in cursor.fetchall()]
|
time_entry_columns = [column[1] for column in cursor.fetchall()]
|
||||||
|
|||||||
Reference in New Issue
Block a user