add directory creation for SQLite database in create_app function; remove init container for SQLite
This commit is contained in:
parent
bdb61fe1b7
commit
7209d3fed0
2 changed files with 9 additions and 9 deletions
|
|
@ -26,6 +26,15 @@ def create_app():
|
|||
|
||||
# Initialize database tables
|
||||
with app.app_context():
|
||||
# Create data directory if it doesn't exist
|
||||
import os
|
||||
db_path = app.config.get('SQLALCHEMY_DATABASE_URI', '')
|
||||
if db_path.startswith('sqlite:///'):
|
||||
db_file_path = db_path.replace('sqlite:///', '')
|
||||
db_dir = os.path.dirname(db_file_path)
|
||||
if db_dir and not os.path.exists(db_dir):
|
||||
os.makedirs(db_dir, exist_ok=True)
|
||||
|
||||
db.create_all()
|
||||
|
||||
return app
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue