Added an SQLite database that will host ping logs. DB file is automatically created and upgraded

This commit is contained in:
2025-09-01 10:05:39 +02:00
parent f685e2b705
commit 7ee6ed88c1
6 changed files with 210 additions and 1 deletions

23
app.py
View File

@@ -3,10 +3,31 @@ from flask import jsonify, Flask, render_template, send_file
from poll_services import start_async_loop
from mem import services
import threading
from flask_sqlalchemy import SQLAlchemy
from flask_migrate import Migrate, init, upgrade
from pathlib import Path
# Flask app to serve status
app = Flask(__name__)
app.config["SQLALCHEMY_DATABASE_URI"] = "sqlite:///app.db"
db = SQLAlchemy(app=app)
migration = Migrate(app=app, db=db)
# Init and upgrade
with app.app_context():
# Check if DB file or migrations folder is missing
if not (
Path("./instance/app.db").is_file() and Path("./migrations").is_dir()
):
init()
# Upgrade db if any new migrations exist
upgrade()
class logs(db.Model):
id = db.Column(db.Integer, primary_key=True)
dateCreated = db.Column(db.DateTime, nullable=False)
@app.route("/")