05/15 Update: implement iPad notification function 2

This commit is contained in:
Nguyen Ngo
2026-05-15 15:15:10 -04:00
parent b761f6577e
commit b69a52e5f5
5 changed files with 162 additions and 13 deletions
@@ -0,0 +1,53 @@
"""phase17 — add event_type column to notifications table
Background
----------
The `notifications` table has no `event_type` column, but the mobile API
endpoint GET /api/v1/notifications references `n.event_type`, causing an
AttributeError (500) on every poll — silently breaking iPad notifications.
This migration adds `event_type VARCHAR(50) NULL` so the column is stored
at creation time and returned correctly to the mobile poller.
The `notify()` utility is updated separately to pass event_type when creating
Notification records.
Uses INFORMATION_SCHEMA existence check — safe to re-run (CLAUDE.md rules 16, 17).
Revision ID: phase17_notification_event_type
Revises: phase16_notifications_columns
"""
revision = 'phase17_notification_event_type'
down_revision = 'phase16_notifications_columns'
branch_labels = None
depends_on = None
from alembic import op
import sqlalchemy as sa
def _column_exists(bind, table, column):
result = bind.execute(sa.text(
"SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS "
"WHERE TABLE_SCHEMA = DATABASE() "
"AND TABLE_NAME = :t AND COLUMN_NAME = :c"
), {'t': table, 'c': column})
return result.scalar() > 0
def upgrade():
bind = op.get_bind()
if not _column_exists(bind, 'notifications', 'event_type'):
op.execute(sa.text(
"ALTER TABLE notifications "
"ADD COLUMN event_type VARCHAR(50) NULL"
))
def downgrade():
bind = op.get_bind()
if _column_exists(bind, 'notifications', 'event_type'):
op.execute(sa.text(
"ALTER TABLE notifications DROP COLUMN event_type"
))