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