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

93 lines
4.4 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_financial / stock_dividend / stock_sync_state个股财务与分红懒加载管道
Revision ID: 20260907_01
Revises: 20260906_01
Create Date: 2026-09-07
"""
from typing import Sequence, Union
import sqlalchemy as sa
from alembic import op
revision: str = "20260907_01"
down_revision: Union[str, Sequence[str], None] = "20260906_01"
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None
def upgrade() -> None:
op.create_table(
"stock_financial",
sa.Column("id", sa.Integer(), autoincrement=True, nullable=False),
sa.Column("ts_code", sa.String(length=12), nullable=False),
sa.Column("end_date", sa.String(length=8), nullable=False),
sa.Column("ann_date", sa.String(length=8), nullable=True),
sa.Column("eps", sa.Float(), nullable=True),
sa.Column("bps", sa.Float(), nullable=True),
sa.Column("ocfps", sa.Float(), nullable=True),
sa.Column("roe", sa.Float(), nullable=True),
sa.Column("roe_dt", sa.Float(), nullable=True),
sa.Column("grossprofit_margin", sa.Float(), nullable=True),
sa.Column("netprofit_margin", sa.Float(), nullable=True),
sa.Column("debt_to_assets", sa.Float(), nullable=True),
sa.Column("or_yoy", sa.Float(), nullable=True),
sa.Column("netprofit_yoy", sa.Float(), nullable=True),
sa.Column("dt_netprofit_yoy", sa.Float(), nullable=True),
sa.Column("profit_dedt", sa.Float(), nullable=True),
sa.Column("rd_exp", sa.Float(), nullable=True),
sa.Column("total_revenue", sa.Float(), nullable=True),
sa.Column("operate_profit", sa.Float(), nullable=True),
sa.Column("n_income_attr_p", sa.Float(), nullable=True),
sa.Column("total_assets", sa.Float(), nullable=True),
sa.Column("total_hldr_eqy", sa.Float(), nullable=True),
sa.Column("n_cashflow_act", sa.Float(), nullable=True),
sa.Column("updated_at", sa.DateTime(), nullable=True),
sa.PrimaryKeyConstraint("id"),
sa.UniqueConstraint("ts_code", "end_date", name="uq_stock_financial_code_end"),
)
op.create_index("ix_stock_financial_ts_code", "stock_financial", ["ts_code"])
op.create_table(
"stock_dividend",
sa.Column("id", sa.Integer(), autoincrement=True, nullable=False),
sa.Column("ts_code", sa.String(length=12), nullable=False),
sa.Column("end_date", sa.String(length=8), nullable=True),
sa.Column("ann_date", sa.String(length=8), nullable=True),
sa.Column("div_proc", sa.String(length=16), nullable=True),
sa.Column("stk_div", sa.Float(), nullable=True),
sa.Column("stk_bo_rate", sa.Float(), nullable=True),
sa.Column("stk_co_rate", sa.Float(), nullable=True),
sa.Column("cash_div", sa.Float(), nullable=True),
sa.Column("cash_div_tax", sa.Float(), nullable=True),
sa.Column("base_share", sa.Float(), nullable=True),
sa.Column("record_date", sa.String(length=8), nullable=True),
sa.Column("ex_date", sa.String(length=8), nullable=True),
sa.Column("pay_date", sa.String(length=8), nullable=True),
sa.Column("div_listdate", sa.String(length=8), nullable=True),
sa.Column("imp_ann_date", sa.String(length=8), nullable=True),
sa.Column("updated_at", sa.DateTime(), nullable=True),
sa.PrimaryKeyConstraint("id"),
)
op.create_index("ix_stock_dividend_ts_code", "stock_dividend", ["ts_code"])
op.create_table(
"stock_sync_state",
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=16), nullable=False),
sa.Column("last_synced_at", sa.DateTime(), nullable=True),
sa.Column("has_data", sa.Boolean(), nullable=True),
sa.PrimaryKeyConstraint("id"),
sa.UniqueConstraint("ts_code", "kind", name="uq_stock_sync_code_kind"),
)
op.create_index("ix_stock_sync_state_ts_code", "stock_sync_state", ["ts_code"])
def downgrade() -> None:
op.drop_index("ix_stock_sync_state_ts_code", table_name="stock_sync_state")
op.drop_table("stock_sync_state")
op.drop_index("ix_stock_dividend_ts_code", table_name="stock_dividend")
op.drop_table("stock_dividend")
op.drop_index("ix_stock_financial_ts_code", table_name="stock_financial")
op.drop_table("stock_financial")