Updated alerts.py to work with PostgreSQL