You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
59 lines
2.7 KiB
Python
59 lines
2.7 KiB
Python
"""add insider_transactions table
|
|
|
|
Revision ID: c4d5e6f7a8b9
|
|
Revises: b3c4d5e6f7a8
|
|
Create Date: 2026-03-24
|
|
"""
|
|
from typing import Sequence, Union
|
|
|
|
from alembic import op
|
|
import sqlalchemy as sa
|
|
from sqlalchemy.dialects import postgresql
|
|
|
|
revision: str = "c4d5e6f7a8b9"
|
|
down_revision: Union[str, Sequence[str], None] = "b3c4d5e6f7a8"
|
|
branch_labels: Union[str, Sequence[str], None] = None
|
|
depends_on: Union[str, Sequence[str], None] = None
|
|
|
|
|
|
def upgrade() -> None:
|
|
conn = op.get_bind()
|
|
if not conn.dialect.has_table(conn, "insider_transactions"):
|
|
op.create_table(
|
|
"insider_transactions",
|
|
sa.Column("id", postgresql.UUID(as_uuid=True), primary_key=True),
|
|
sa.Column("ticker", sa.String(10), nullable=False),
|
|
sa.Column("cik", sa.String(20), nullable=False),
|
|
sa.Column("accession_number", sa.String(30), nullable=False),
|
|
sa.Column("filing_date", postgresql.TIMESTAMP(timezone=True), nullable=False),
|
|
sa.Column("owner_name", sa.String(255), nullable=False),
|
|
sa.Column("owner_cik", sa.String(20), nullable=True),
|
|
sa.Column("is_officer", sa.Boolean(), default=False),
|
|
sa.Column("is_director", sa.Boolean(), default=False),
|
|
sa.Column("is_ten_percent_owner", sa.Boolean(), default=False),
|
|
sa.Column("officer_title", sa.String(255), nullable=True),
|
|
sa.Column("security_title", sa.String(255), nullable=True),
|
|
sa.Column("transaction_date", postgresql.TIMESTAMP(timezone=True), nullable=False),
|
|
sa.Column("transaction_code", sa.String(5), nullable=False),
|
|
sa.Column("shares", sa.Float(), nullable=False),
|
|
sa.Column("price_per_share", sa.Float(), nullable=True),
|
|
sa.Column("total_value", sa.Float(), nullable=True),
|
|
sa.Column("shares_owned_after", sa.Float(), nullable=True),
|
|
sa.Column("is_derivative", sa.Boolean(), default=False),
|
|
sa.Column("created_at", postgresql.TIMESTAMP(timezone=True)),
|
|
sa.Column("updated_at", postgresql.TIMESTAMP(timezone=True)),
|
|
sa.UniqueConstraint(
|
|
"accession_number", "owner_cik", "transaction_date",
|
|
"transaction_code", "shares",
|
|
name="uq_insider_transaction",
|
|
),
|
|
)
|
|
op.create_index("ix_insider_transactions_ticker", "insider_transactions", ["ticker"])
|
|
op.create_index("idx_insider_ticker_date", "insider_transactions", ["ticker", "transaction_date"])
|
|
op.create_index("idx_insider_ticker_code", "insider_transactions", ["ticker", "transaction_code"])
|
|
op.create_index("idx_insider_filing_date", "insider_transactions", ["filing_date"])
|
|
|
|
|
|
def downgrade() -> None:
|
|
op.drop_table("insider_transactions")
|