37 lines
1.3 KiB
Python
37 lines
1.3 KiB
Python
"""holding_items:持仓股(手动标记进「持仓」分类)
|
||
|
||
Revision ID: 20260909_01
|
||
Revises: 20260907_02
|
||
Create Date: 2026-09-09
|
||
"""
|
||
from typing import Sequence, Union
|
||
|
||
import sqlalchemy as sa
|
||
from alembic import op
|
||
|
||
revision: str = "20260909_01"
|
||
down_revision: Union[str, Sequence[str], None] = "20260907_02"
|
||
branch_labels: Union[str, Sequence[str], None] = None
|
||
depends_on: Union[str, Sequence[str], None] = None
|
||
|
||
|
||
def upgrade() -> None:
|
||
op.create_table(
|
||
"holding_items",
|
||
sa.Column("id", sa.Integer(), autoincrement=True, nullable=False),
|
||
sa.Column("user_id", sa.BigInteger(), nullable=False),
|
||
sa.Column("ts_code", sa.String(length=12), nullable=False),
|
||
sa.Column("created_at", sa.DateTime(), nullable=False),
|
||
sa.ForeignKeyConstraint(["user_id"], ["users.id"], ondelete="CASCADE"),
|
||
sa.PrimaryKeyConstraint("id"),
|
||
sa.UniqueConstraint("user_id", "ts_code", name="uq_holding_user_code"),
|
||
)
|
||
op.create_index("ix_holding_items_user_id", "holding_items", ["user_id"])
|
||
op.create_index("ix_holding_items_ts_code", "holding_items", ["ts_code"])
|
||
|
||
|
||
def downgrade() -> None:
|
||
op.drop_index("ix_holding_items_ts_code", table_name="holding_items")
|
||
op.drop_index("ix_holding_items_user_id", table_name="holding_items")
|
||
op.drop_table("holding_items")
|