Files
stock/backend/alembic/versions/20260907_02_stock_reference.py
2026-09-07 18:07:31 +08:00

35 lines
1.2 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""stock_reference个股参考数据tushare 参考数据版块,按股按分类存 JSON 快照懒加载)
Revision ID: 20260907_02
Revises: 20260907_01
Create Date: 2026-09-07
"""
from typing import Sequence, Union
import sqlalchemy as sa
from alembic import op
revision: str = "20260907_02"
down_revision: Union[str, Sequence[str], None] = "20260907_01"
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None
def upgrade() -> None:
op.create_table(
"stock_reference",
sa.Column("id", sa.Integer(), autoincrement=True, nullable=False),
sa.Column("ts_code", sa.String(length=12), nullable=False),
sa.Column("kind", sa.String(length=24), nullable=False),
sa.Column("rows_json", sa.Text(), nullable=True),
sa.Column("updated_at", sa.DateTime(), nullable=True),
sa.PrimaryKeyConstraint("id"),
sa.UniqueConstraint("ts_code", "kind", name="uq_stock_reference_code_kind"),
)
op.create_index("ix_stock_reference_ts_code", "stock_reference", ["ts_code"])
def downgrade() -> None:
op.drop_index("ix_stock_reference_ts_code", table_name="stock_reference")
op.drop_table("stock_reference")