From 30933ed2d548554d1468e35d607c1579299bbaaa Mon Sep 17 00:00:00 2001 From: "Manuel Weiser (aider)" Date: Mon, 2 Sep 2024 09:35:10 +0200 Subject: [PATCH] fix: update database path to use instance folder for SQLite files --- game_collection/app.py | 6 +++++- game_collection/database.py | 5 ++++- 2 files changed, 9 insertions(+), 2 deletions(-) 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