Fix: ki_health_reports ALTER TABLE user_id Migration, INSERT try/catch, Bericht immer zurückgeben (SW by-v807)

This commit is contained in:
rene 2026-05-09 21:31:05 +02:00
parent 0b06669635
commit 891e11df65
6 changed files with 24 additions and 16 deletions

View file

@ -1236,11 +1236,16 @@ def _migrate(conn_factory):
CREATE TABLE IF NOT EXISTS ki_health_reports (
id INTEGER PRIMARY KEY AUTOINCREMENT,
dog_id INTEGER NOT NULL REFERENCES dogs(id) ON DELETE CASCADE,
user_id INTEGER NOT NULL REFERENCES users(id) ON DELETE CASCADE,
user_id INTEGER REFERENCES users(id) ON DELETE CASCADE,
bericht TEXT NOT NULL,
erstellt_at TEXT NOT NULL DEFAULT (datetime('now'))
)
""")
# user_id nachträglich ergänzen falls Tabelle ohne diese Spalte erstellt wurde
try:
conn.execute("ALTER TABLE ki_health_reports ADD COLUMN user_id INTEGER REFERENCES users(id) ON DELETE CASCADE")
except Exception:
pass # Spalte existiert bereits
conn.execute("""
CREATE INDEX IF NOT EXISTS idx_ki_health_reports_dog
ON ki_health_reports(dog_id, erstellt_at DESC)