"""add activist_ownership_events table for SC 13D/13G filings Revision ID: m4e5f6g7h8i9 Revises: l3d4e5f6g7h8 Create Date: 2026-04-22 """ from alembic import op import sqlalchemy as sa from sqlalchemy.dialects import postgresql revision = "m4e5f6g7h8i9" down_revision = "l3d4e5f6g7h8" branch_labels = None depends_on = None def upgrade() -> None: conn = op.get_bind() if conn.dialect.has_table(conn, "activist_ownership_events"): return op.create_table( "activist_ownership_events", sa.Column("id", postgresql.UUID(as_uuid=True), primary_key=True), sa.Column("symbol", sa.String(10), nullable=False), sa.Column("issuer_cik", sa.String(20), nullable=False), sa.Column("filer_cik", sa.String(20), nullable=False), sa.Column("filer_name", sa.String(500), nullable=False), sa.Column("accession_number", sa.String(30), nullable=False), sa.Column("form_type", sa.String(20), nullable=False), sa.Column("filing_date", sa.TIMESTAMP(timezone=True), nullable=False), sa.Column("is_amendment", sa.Boolean(), nullable=False, server_default="false"), sa.Column("ownership_pct", sa.Float(), nullable=True), sa.Column("shares_owned", sa.Float(), nullable=True), sa.Column("change_pct", sa.Float(), nullable=True), sa.Column("parse_status", sa.String(20), nullable=False, server_default="index_only"), sa.Column("filing_url", sa.Text(), nullable=True), sa.Column("created_at", sa.TIMESTAMP(timezone=True), nullable=False, server_default=sa.text("NOW()")), sa.Column("updated_at", sa.TIMESTAMP(timezone=True), nullable=False, server_default=sa.text("NOW()")), sa.UniqueConstraint("accession_number", "filer_cik", name="uq_activist_event"), ) op.create_index("idx_activist_sym_date", "activist_ownership_events", ["symbol", "filing_date"]) op.create_index("idx_activist_filer_issuer", "activist_ownership_events", ["filer_cik", "issuer_cik", "filing_date"]) op.create_index("idx_activist_filing_date", "activist_ownership_events", ["filing_date"]) def downgrade() -> None: op.drop_index("idx_activist_filing_date", table_name="activist_ownership_events") op.drop_index("idx_activist_filer_issuer", table_name="activist_ownership_events") op.drop_index("idx_activist_sym_date", table_name="activist_ownership_events") op.drop_table("activist_ownership_events")