modified: app.py

modified:   db.py
	modified:   routes/journal_routes.py
	modified:   static/css/style.css
	modified:   static/js/main.js
	modified:   templates/base.html
	modified:   templates/day.html
	modified:   templates/future.html
	modified:   templates/index.html
	new file:   templates/monat.html
	modified:   templates/week.html
This commit is contained in:
SimolZimol
2026-08-02 21:12:17 +02:00
parent 9ab350ac02
commit 428dccc5b0
11 changed files with 632 additions and 106 deletions

26
db.py
View File

@@ -44,6 +44,8 @@ CREATE TABLE IF NOT EXISTS notes (
status ENUM('open', 'done', 'moved') NOT NULL DEFAULT 'open',
moved_to_date DATE NULL,
moved_to_future TINYINT(1) NOT NULL DEFAULT 0,
moved_from_date DATE NULL,
refs JSON NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
CONSTRAINT fk_notes_user FOREIGN KEY (user_id)
@@ -55,6 +57,7 @@ CREATE TABLE IF NOT EXISTS future_log (
user_id INT NOT NULL,
month_date DATE NOT NULL,
note_text TEXT NOT NULL,
refs JSON NULL,
status ENUM('open', 'done') NOT NULL DEFAULT 'open',
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
CONSTRAINT fk_future_user FOREIGN KEY (user_id)
@@ -63,6 +66,26 @@ CREATE TABLE IF NOT EXISTS future_log (
"""
# Spalten, die für bereits bestehende Datenbanken nachgezogen werden müssen
MIGRATIONS = [
("notes", "moved_from_date", "DATE NULL"),
("notes", "refs", "JSON NULL"),
("future_log", "refs", "JSON NULL"),
]
def _ensure_column(conn, table: str, column: str, definition: str) -> None:
"""Fügt eine Spalte hinzu, falls sie noch nicht existiert (Migration)."""
with conn.cursor() as cur:
cur.execute(
"SELECT COUNT(*) AS c FROM information_schema.COLUMNS "
"WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = %s AND COLUMN_NAME = %s",
(table, column),
)
if cur.fetchone()["c"] == 0:
cur.execute(f"ALTER TABLE {table} ADD COLUMN {column} {definition}")
def init_db():
"""Erstellt das Schema, falls es noch nicht existiert."""
conn = get_connection()
@@ -72,5 +95,8 @@ def init_db():
stmt = statement.strip()
if stmt:
cur.execute(stmt)
# Migrationen für bestehende Datenbanken
for table, column, definition in MIGRATIONS:
_ensure_column(conn, table, column, definition)
finally:
conn.close()