homelab_automation/debug_alerts.py
Bruno Charest 817f8b4ee7
Some checks failed
Tests / Backend Tests (Python) (3.10) (push) Has been cancelled
Tests / Backend Tests (Python) (3.11) (push) Has been cancelled
Tests / Backend Tests (Python) (3.12) (push) Has been cancelled
Tests / Frontend Tests (JS) (push) Has been cancelled
Tests / Integration Tests (push) Has been cancelled
Tests / All Tests Passed (push) Has been cancelled
feat: Implement Homelab Automation API v2, introducing a new dashboard, comprehensive backend models, and API routes.
2026-03-06 09:31:08 -05:00

39 lines
1.4 KiB
Python

import os
import asyncio
from sqlalchemy import text
from dotenv import load_dotenv
load_dotenv()
from app.models.database import async_session_maker, engine
async def check():
async with async_session_maker() as session:
try:
print(f"DATABASE URL: {engine.url}")
# Check table existence and columns
print("Checking alerts table...")
res = await session.execute(text("DESCRIBE alerts"))
columns = res.fetchall()
for col in columns:
print(f"Column: {col}")
# Try a dry insertion
print("\nAttempting dry insertion...")
# Use columns found or assume standard ones
stmt = text("INSERT INTO alerts (category, title, level, message, source, created_at) VALUES ('test', 'Test', 'info', 'Test', 'script', NOW())")
res = await session.execute(stmt)
print(f"Insert success, rowcount: {res.rowcount}")
await session.commit()
print("Commit success")
except Exception as e:
print(f"\nERROR: {type(e).__name__}: {str(e)}")
if hasattr(e, 'orig'):
print(f"Original error: {e.orig}")
if __name__ == "__main__":
loop = asyncio.get_event_loop()
loop.run_until_complete(check())
# Don't close explicitly, or wait a bit