- Complete MVP for tracking Fidelity brokerage account performance - Transaction import from CSV with deduplication - Automatic FIFO position tracking with options support - Real-time P&L calculations with market data caching - Dashboard with timeframe filtering (30/90/180 days, 1 year, YTD, all time) - Docker-based deployment with PostgreSQL backend - React/TypeScript frontend with TailwindCSS - FastAPI backend with SQLAlchemy ORM Features: - Multi-account support - Import via CSV upload or filesystem - Open and closed position tracking - Balance history charting - Performance analytics and metrics - Top trades analysis - Responsive UI design Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
84 lines
4.5 KiB
Python
84 lines
4.5 KiB
Python
"""Initial schema
|
|
|
|
Revision ID: 001_initial_schema
|
|
Revises:
|
|
Create Date: 2026-01-20 10:00:00.000000
|
|
|
|
"""
|
|
from alembic import op
|
|
import sqlalchemy as sa
|
|
from sqlalchemy.dialects import postgresql
|
|
|
|
# revision identifiers, used by Alembic.
|
|
revision = '001_initial_schema'
|
|
down_revision = None
|
|
branch_labels = None
|
|
depends_on = None
|
|
|
|
|
|
def upgrade() -> None:
|
|
# Create accounts table
|
|
op.create_table(
|
|
'accounts',
|
|
sa.Column('id', sa.Integer(), nullable=False),
|
|
sa.Column('account_number', sa.String(length=50), nullable=False),
|
|
sa.Column('account_name', sa.String(length=200), nullable=False),
|
|
sa.Column('account_type', sa.Enum('CASH', 'MARGIN', name='accounttype'), nullable=False),
|
|
sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=False),
|
|
sa.Column('updated_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=False),
|
|
sa.PrimaryKeyConstraint('id')
|
|
)
|
|
op.create_index(op.f('ix_accounts_id'), 'accounts', ['id'], unique=False)
|
|
op.create_index(op.f('ix_accounts_account_number'), 'accounts', ['account_number'], unique=True)
|
|
|
|
# Create transactions table
|
|
op.create_table(
|
|
'transactions',
|
|
sa.Column('id', sa.Integer(), nullable=False),
|
|
sa.Column('account_id', sa.Integer(), nullable=False),
|
|
sa.Column('run_date', sa.Date(), nullable=False),
|
|
sa.Column('action', sa.String(length=500), nullable=False),
|
|
sa.Column('symbol', sa.String(length=50), nullable=True),
|
|
sa.Column('description', sa.String(length=500), nullable=True),
|
|
sa.Column('transaction_type', sa.String(length=20), nullable=True),
|
|
sa.Column('exchange_quantity', sa.Numeric(precision=20, scale=8), nullable=True),
|
|
sa.Column('exchange_currency', sa.String(length=10), nullable=True),
|
|
sa.Column('currency', sa.String(length=10), nullable=True),
|
|
sa.Column('price', sa.Numeric(precision=20, scale=8), nullable=True),
|
|
sa.Column('quantity', sa.Numeric(precision=20, scale=8), nullable=True),
|
|
sa.Column('exchange_rate', sa.Numeric(precision=20, scale=8), nullable=True),
|
|
sa.Column('commission', sa.Numeric(precision=20, scale=2), nullable=True),
|
|
sa.Column('fees', sa.Numeric(precision=20, scale=2), nullable=True),
|
|
sa.Column('accrued_interest', sa.Numeric(precision=20, scale=2), nullable=True),
|
|
sa.Column('amount', sa.Numeric(precision=20, scale=2), nullable=True),
|
|
sa.Column('cash_balance', sa.Numeric(precision=20, scale=2), nullable=True),
|
|
sa.Column('settlement_date', sa.Date(), nullable=True),
|
|
sa.Column('unique_hash', sa.String(length=64), nullable=False),
|
|
sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=False),
|
|
sa.Column('updated_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=False),
|
|
sa.ForeignKeyConstraint(['account_id'], ['accounts.id'], ondelete='CASCADE'),
|
|
sa.PrimaryKeyConstraint('id')
|
|
)
|
|
op.create_index(op.f('ix_transactions_id'), 'transactions', ['id'], unique=False)
|
|
op.create_index(op.f('ix_transactions_account_id'), 'transactions', ['account_id'], unique=False)
|
|
op.create_index(op.f('ix_transactions_run_date'), 'transactions', ['run_date'], unique=False)
|
|
op.create_index(op.f('ix_transactions_symbol'), 'transactions', ['symbol'], unique=False)
|
|
op.create_index(op.f('ix_transactions_unique_hash'), 'transactions', ['unique_hash'], unique=True)
|
|
op.create_index('idx_account_date', 'transactions', ['account_id', 'run_date'], unique=False)
|
|
op.create_index('idx_account_symbol', 'transactions', ['account_id', 'symbol'], unique=False)
|
|
|
|
|
|
def downgrade() -> None:
|
|
op.drop_index('idx_account_symbol', table_name='transactions')
|
|
op.drop_index('idx_account_date', table_name='transactions')
|
|
op.drop_index(op.f('ix_transactions_unique_hash'), table_name='transactions')
|
|
op.drop_index(op.f('ix_transactions_symbol'), table_name='transactions')
|
|
op.drop_index(op.f('ix_transactions_run_date'), table_name='transactions')
|
|
op.drop_index(op.f('ix_transactions_account_id'), table_name='transactions')
|
|
op.drop_index(op.f('ix_transactions_id'), table_name='transactions')
|
|
op.drop_table('transactions')
|
|
op.drop_index(op.f('ix_accounts_account_number'), table_name='accounts')
|
|
op.drop_index(op.f('ix_accounts_id'), table_name='accounts')
|
|
op.drop_table('accounts')
|
|
op.execute('DROP TYPE accounttype')
|