diff --git a/game_collection/app.py b/game_collection/app.py index ec0b2a0..c2bbce6 100644 --- a/game_collection/app.py +++ b/game_collection/app.py @@ -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 diff --git a/game_collection/database.py b/game_collection/database.py index d408340..ed99213 100644 --- a/game_collection/database.py +++ b/game_collection/database.py @@ -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