fix: update database path to use instance folder for SQLite files
This commit is contained in:
		| @@ -2,12 +2,16 @@ from flask import Flask, request, jsonify | ||||
| from flask_sqlalchemy import SQLAlchemy | ||||
| from database import init_db | ||||
| from models import db, Game | ||||
| import os | ||||
|  | ||||
| app = Flask(__name__) | ||||
| app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///games.db' | ||||
| app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + os.path.join(app.instance_path, 'games.db') | ||||
| app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False | ||||
| db.init_app(app) | ||||
|  | ||||
| # Stelle sicher, dass der instance-Ordner existiert | ||||
| os.makedirs(app.instance_path, exist_ok=True) | ||||
|  | ||||
| with app.app_context(): | ||||
|     init_db()  # Ensure the database is initialized before any operations | ||||
|  | ||||
|   | ||||
| @@ -1,7 +1,10 @@ | ||||
| import sqlite3 | ||||
| import os | ||||
| from flask import current_app | ||||
|  | ||||
| def init_db(): | ||||
|     conn = sqlite3.connect('games.db') | ||||
|     db_path = os.path.join(current_app.instance_path, 'games.db') | ||||
|     conn = sqlite3.connect(db_path) | ||||
|     cursor = conn.cursor() | ||||
|      | ||||
|     # Tabelle für Spiele erstellen | ||||
|   | ||||
		Reference in New Issue
	
	Block a user