Extends the pipeline with infosec classification, sender profile tracking, and configurable purge rules. Adds a web dashboard for managing rules and monitoring email processing. Includes new migrations and seed script. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
54 lines
1.9 KiB
Python
54 lines
1.9 KiB
Python
"""Add sender_profiles table
|
|
|
|
Revision ID: 0004
|
|
Revises: 0003
|
|
Create Date: 2026-04-02
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
from typing import Sequence, Union
|
|
|
|
import sqlalchemy as sa
|
|
from alembic import op
|
|
from sqlalchemy.dialects import postgresql
|
|
|
|
revision: str = "0004"
|
|
down_revision: Union[str, None] = "0003"
|
|
branch_labels: Union[str, Sequence[str], None] = None
|
|
depends_on: Union[str, Sequence[str], None] = None
|
|
|
|
|
|
def upgrade() -> None:
|
|
op.create_table(
|
|
"sender_profiles",
|
|
sa.Column("id", postgresql.UUID(as_uuid=True), primary_key=True, server_default=sa.text("gen_random_uuid()")),
|
|
sa.Column("email_address", sa.Text, nullable=False, unique=True),
|
|
sa.Column("display_name", sa.Text),
|
|
sa.Column(
|
|
"sender_type",
|
|
postgresql.ENUM("customer", "vendor", "whitelist", "unknown", name="sender_type", create_type=False),
|
|
nullable=False,
|
|
server_default="unknown",
|
|
),
|
|
sa.Column("email_types", postgresql.JSONB, nullable=False, server_default=sa.text("'[]'")),
|
|
sa.Column("processing_instructions", sa.Text),
|
|
sa.Column("notes", sa.Text),
|
|
sa.Column("is_active", sa.Boolean, nullable=False, server_default="TRUE"),
|
|
sa.Column("created_at", sa.DateTime(timezone=True), server_default=sa.text("NOW()")),
|
|
sa.Column("updated_at", sa.DateTime(timezone=True), server_default=sa.text("NOW()")),
|
|
)
|
|
op.create_index(
|
|
"idx_sender_profiles_address",
|
|
"sender_profiles",
|
|
[sa.text("LOWER(email_address)")],
|
|
)
|
|
op.execute("""
|
|
CREATE TRIGGER trg_sender_profiles_updated_at
|
|
BEFORE UPDATE ON sender_profiles
|
|
FOR EACH ROW EXECUTE FUNCTION set_updated_at();
|
|
""")
|
|
|
|
|
|
def downgrade() -> None:
|
|
op.execute("DROP TRIGGER IF EXISTS trg_sender_profiles_updated_at ON sender_profiles")
|
|
op.drop_table("sender_profiles")
|