added Docker setup & moved database into instance folder
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
from __future__ import annotations
|
||||
import os
|
||||
from flask import Flask, render_template
|
||||
from datetime import datetime
|
||||
|
||||
@@ -26,6 +27,12 @@ def create_app() -> Flask:
|
||||
return str(value)
|
||||
app.jinja_env.filters["fmt_ts"] = fmt_ts
|
||||
|
||||
# ensure the instance folder exists
|
||||
try:
|
||||
os.makedirs(app.instance_path)
|
||||
except OSError:
|
||||
pass
|
||||
|
||||
# Blueprints registrieren
|
||||
app.register_blueprint(structures_bp)
|
||||
app.register_blueprint(cookbook_bp)
|
||||
|
||||
3
webapp/app.py
Normal file
3
webapp/app.py
Normal file
@@ -0,0 +1,3 @@
|
||||
from . import create_app
|
||||
|
||||
app = create_app()
|
||||
@@ -1,59 +0,0 @@
|
||||
import os, json
|
||||
from tinydb import TinyDB
|
||||
from tinydb.storages import Storage
|
||||
|
||||
# Paths
|
||||
OLD_FILE = "orders.json"
|
||||
ARCHIVE_FILE = "orders_old.json"
|
||||
NEW_FILE = "orders_new.json" # final TinyDB JSON file
|
||||
TABLE_NAME = "orders"
|
||||
|
||||
|
||||
class PrettyJSONStorage(Storage):
|
||||
"""Custom TinyDB storage that pretty-prints JSON."""
|
||||
def __init__(self, path):
|
||||
self.path = path
|
||||
|
||||
def read(self):
|
||||
try:
|
||||
with open(self.path, "r", encoding="utf-8") as f:
|
||||
return json.load(f)
|
||||
except FileNotFoundError:
|
||||
return None
|
||||
|
||||
def write(self, data):
|
||||
with open(self.path, "w", encoding="utf-8") as f:
|
||||
json.dump(data, f, ensure_ascii=False, indent=2)
|
||||
|
||||
|
||||
def migrate():
|
||||
if not os.path.isfile(OLD_FILE):
|
||||
print("No old JSON file found. Nothing to migrate.")
|
||||
return
|
||||
|
||||
# Load old orders
|
||||
with open(OLD_FILE, "r", encoding="utf-8") as f:
|
||||
orders = json.load(f) or []
|
||||
|
||||
if not orders:
|
||||
print("No orders found in the old JSON.")
|
||||
return
|
||||
|
||||
print(orders)
|
||||
|
||||
# Open TinyDB and insert into table
|
||||
db = TinyDB(NEW_FILE, storage=PrettyJSONStorage)
|
||||
orders_table = db.table(TABLE_NAME)
|
||||
for order in orders:
|
||||
orders_table.insert(order)
|
||||
|
||||
# Rename old file to archive
|
||||
os.rename(OLD_FILE, ARCHIVE_FILE)
|
||||
os.rename(NEW_FILE, OLD_FILE)
|
||||
print(f"Migrated {len(orders)} orders into table '{TABLE_NAME}'.")
|
||||
print(f"Old JSON file renamed to '{ARCHIVE_FILE}'.")
|
||||
print(f"New TinyDB JSON file is '{OLD_FILE}'.")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
migrate()
|
||||
File diff suppressed because it is too large
Load Diff
11
webapp/eve_structure.ini
Normal file
11
webapp/eve_structure.ini
Normal file
@@ -0,0 +1,11 @@
|
||||
[uwsgi]
|
||||
chdir=/
|
||||
module = webapp.app
|
||||
callable = app
|
||||
socket = :5000
|
||||
processes = 4
|
||||
threads = 2
|
||||
master = true
|
||||
chmod-socket = 660
|
||||
vacuum = true
|
||||
die-on-term = true
|
||||
@@ -33,7 +33,7 @@ def get_db() -> TinyDB:
|
||||
Stored in `g` to avoid reopening the file multiple times.
|
||||
"""
|
||||
if "orders_db" not in g:
|
||||
db_path = os.path.join(current_app.root_path, "data", FILE_NAME)
|
||||
db_path = os.path.join(current_app.instance_path, FILE_NAME)
|
||||
if PRODUCTION == "dev":
|
||||
g.orders_db = TinyDB(db_path, storage=PrettyJSONStorage )
|
||||
else:
|
||||
|
||||
Reference in New Issue
Block a user