Implements the full User Connections & Notification Centre feature: Phase 1 - Database: migrations 039-043 adding umbral_name to users, profile/social fields to settings, notifications table, connection request/user_connection tables, and linked_user_id to people. Phase 2 - Notifications: backend CRUD router + service + 90-day purge, frontend NotificationsPage with All/Unread filter, bell icon in sidebar with unread badge polling every 60s. Phase 3 - Settings: profile fields (phone, mobile, address, company, job_title), social card with accept_connections toggle and per-field sharing defaults, umbral name display with CopyableField. Phase 4 - Connections: timing-safe user search, send/accept/reject flow with atomic status updates, bidirectional UserConnection + Person records, in-app + ntfy notifications, per-receiver pending cap, nginx rate limiting. Phase 5 - People integration: batch-loaded shared profiles (N+1 prevention), Ghost icon for umbral contacts, Umbral filter pill, split Add Person button, shared field indicators (synced labels + Lock icons), disabled form inputs for synced fields on umbral contacts. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
58 lines
1.7 KiB
Python
58 lines
1.7 KiB
Python
"""Create notifications table for in-app notification centre.
|
|
|
|
Revision ID: 041
|
|
Revises: 040
|
|
"""
|
|
from alembic import op
|
|
import sqlalchemy as sa
|
|
from sqlalchemy.dialects.postgresql import JSONB
|
|
|
|
revision = "041"
|
|
down_revision = "040"
|
|
branch_labels = None
|
|
depends_on = None
|
|
|
|
|
|
def upgrade() -> None:
|
|
op.create_table(
|
|
"notifications",
|
|
sa.Column("id", sa.Integer, primary_key=True, index=True),
|
|
sa.Column(
|
|
"user_id",
|
|
sa.Integer,
|
|
sa.ForeignKey("users.id", ondelete="CASCADE"),
|
|
nullable=False,
|
|
),
|
|
sa.Column("type", sa.String(50), nullable=False),
|
|
sa.Column("title", sa.String(255), nullable=True),
|
|
sa.Column("message", sa.Text, nullable=True),
|
|
sa.Column("data", JSONB, nullable=True),
|
|
sa.Column("source_type", sa.String(50), nullable=True),
|
|
sa.Column("source_id", sa.Integer, nullable=True),
|
|
sa.Column("is_read", sa.Boolean, nullable=False, server_default="false"),
|
|
sa.Column(
|
|
"created_at",
|
|
sa.DateTime,
|
|
nullable=False,
|
|
server_default=sa.func.now(),
|
|
),
|
|
)
|
|
|
|
# Fast unread count query
|
|
op.execute(
|
|
'CREATE INDEX "ix_notifications_user_unread" ON notifications (user_id, is_read) '
|
|
"WHERE is_read = false"
|
|
)
|
|
# Paginated listing
|
|
op.create_index(
|
|
"ix_notifications_user_created",
|
|
"notifications",
|
|
["user_id", sa.text("created_at DESC")],
|
|
)
|
|
|
|
|
|
def downgrade() -> None:
|
|
op.drop_index("ix_notifications_user_created", table_name="notifications")
|
|
op.execute('DROP INDEX IF EXISTS "ix_notifications_user_unread"')
|
|
op.drop_table("notifications")
|