"""Initial migration Revision ID: 6de8c25f6a9f Revises: Create Date: 2026-01-30 08:52:35.917077 """ from typing import Sequence, Union from alembic import op import sqlalchemy as sa from sqlalchemy.dialects import postgresql # revision identifiers, used by Alembic. revision: str = '6de8c25f6a9f' down_revision: Union[str, None] = None branch_labels: Union[str, Sequence[str], None] = None depends_on: Union[str, Sequence[str], None] = None def upgrade() -> None: # ### commands auto generated by Alembic - please adjust! ### op.create_table('assets', sa.Column('id', sa.UUID(), nullable=False), sa.Column('ticker', sa.String(length=20), nullable=False), sa.Column('name', sa.String(length=100), nullable=False), sa.Column('market', sa.String(length=20), nullable=True), sa.Column('market_cap', sa.BigInteger(), nullable=True), sa.Column('stock_type', sa.String(length=20), nullable=True), sa.Column('sector', sa.String(length=100), nullable=True), sa.Column('last_price', sa.Numeric(precision=15, scale=2), nullable=True), sa.Column('eps', sa.Numeric(precision=15, scale=2), nullable=True), sa.Column('bps', sa.Numeric(precision=15, scale=2), nullable=True), sa.Column('dividend_per_share', sa.Numeric(precision=15, scale=2), nullable=True), sa.Column('base_date', sa.Date(), nullable=True), sa.Column('is_active', sa.Boolean(), nullable=True), sa.PrimaryKeyConstraint('id') ) op.create_index(op.f('ix_assets_ticker'), 'assets', ['ticker'], unique=True) op.create_table('backtest_runs', sa.Column('id', sa.UUID(), nullable=False), sa.Column('name', sa.String(length=100), nullable=False), sa.Column('strategy_name', sa.String(length=50), nullable=False), sa.Column('start_date', sa.Date(), nullable=False), sa.Column('end_date', sa.Date(), nullable=False), sa.Column('initial_capital', sa.Numeric(precision=15, scale=2), nullable=False), sa.Column('status', sa.String(length=20), nullable=True), sa.Column('config', postgresql.JSONB(astext_type=sa.Text()), nullable=True), sa.Column('results', postgresql.JSONB(astext_type=sa.Text()), nullable=True), sa.Column('created_at', sa.DateTime(), nullable=True), sa.PrimaryKeyConstraint('id') ) op.create_table('financial_statements', sa.Column('id', sa.UUID(), nullable=False), sa.Column('ticker', sa.String(length=20), nullable=False), sa.Column('account', sa.String(length=100), nullable=False), sa.Column('base_date', sa.Date(), nullable=False), sa.Column('value', sa.Numeric(precision=20, scale=2), nullable=True), sa.Column('disclosure_type', sa.String(length=1), nullable=True), sa.PrimaryKeyConstraint('id') ) op.create_index(op.f('ix_financial_statements_base_date'), 'financial_statements', ['base_date'], unique=False) op.create_index(op.f('ix_financial_statements_ticker'), 'financial_statements', ['ticker'], unique=False) op.create_table('portfolios', sa.Column('id', sa.UUID(), nullable=False), sa.Column('name', sa.String(length=100), nullable=False), sa.Column('description', sa.Text(), nullable=True), sa.Column('user_id', sa.String(length=100), nullable=True), sa.Column('created_at', sa.DateTime(), nullable=True), sa.PrimaryKeyConstraint('id') ) op.create_table('price_data', sa.Column('ticker', sa.String(length=20), nullable=False), sa.Column('timestamp', sa.DateTime(), nullable=False), sa.Column('open', sa.Numeric(precision=15, scale=2), nullable=True), sa.Column('high', sa.Numeric(precision=15, scale=2), nullable=True), sa.Column('low', sa.Numeric(precision=15, scale=2), nullable=True), sa.Column('close', sa.Numeric(precision=15, scale=2), nullable=False), sa.Column('volume', sa.BigInteger(), nullable=True), sa.PrimaryKeyConstraint('ticker', 'timestamp') ) op.create_index(op.f('ix_price_data_ticker'), 'price_data', ['ticker'], unique=False) op.create_index(op.f('ix_price_data_timestamp'), 'price_data', ['timestamp'], unique=False) op.create_table('backtest_trades', sa.Column('id', sa.UUID(), nullable=False), sa.Column('backtest_run_id', sa.UUID(), nullable=False), sa.Column('ticker', sa.String(length=20), nullable=False), sa.Column('trade_date', sa.DateTime(), nullable=False), sa.Column('action', sa.String(length=10), nullable=False), sa.Column('quantity', sa.Numeric(precision=15, scale=4), nullable=False), sa.Column('price', sa.Numeric(precision=15, scale=2), nullable=False), sa.Column('commission', sa.Numeric(precision=10, scale=2), nullable=True), sa.Column('pnl', sa.Numeric(precision=15, scale=2), nullable=True), sa.ForeignKeyConstraint(['backtest_run_id'], ['backtest_runs.id'], ), sa.PrimaryKeyConstraint('id') ) op.create_table('portfolio_assets', sa.Column('id', sa.UUID(), nullable=False), sa.Column('portfolio_id', sa.UUID(), nullable=False), sa.Column('ticker', sa.String(length=20), nullable=False), sa.Column('target_ratio', sa.Numeric(precision=5, scale=2), nullable=False), sa.ForeignKeyConstraint(['portfolio_id'], ['portfolios.id'], ), sa.PrimaryKeyConstraint('id') ) # ### end Alembic commands ### def downgrade() -> None: # ### commands auto generated by Alembic - please adjust! ### op.drop_table('portfolio_assets') op.drop_table('backtest_trades') op.drop_index(op.f('ix_price_data_timestamp'), table_name='price_data') op.drop_index(op.f('ix_price_data_ticker'), table_name='price_data') op.drop_table('price_data') op.drop_table('portfolios') op.drop_index(op.f('ix_financial_statements_ticker'), table_name='financial_statements') op.drop_index(op.f('ix_financial_statements_base_date'), table_name='financial_statements') op.drop_table('financial_statements') op.drop_table('backtest_runs') op.drop_index(op.f('ix_assets_ticker'), table_name='assets') op.drop_table('assets') # ### end Alembic commands ###