Files
market_sync/tests/test_schema_models.py
T
gao 8f016f25df chore: baseline — ORM migration + systemd deploy + MCP server + daily check
- ORM migration: models/ops 重构
- deploy: 标准化 systemd timer/service 部署体系
- MCP server: 5 个只读工具(任务/状态/数据集)
- daily check: 数据一致性巡检
- watch: task_watch 后台监控
- kline_daily: 麦蕊优先,时间门禁15:00
- 删除: task_industry_sector, task_sector_features
2026-07-21 16:37:00 +08:00

43 lines
2.1 KiB
Python
Raw 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.
"""ORM 模型 metadata 一致性测试(PostgreSQL only2026-06-16 重构后)。
历史背景:原 test_schema_models.py 还测了 schema.py vs models.py 的 DDL 漂移。
schema.py 在这次重构中已删除(MySQL DDL 不再需要),所以只保留 ORM metadata 完整性测试。
"""
from __future__ import annotations
def test_orm_metadata_registers_all_tables():
"""ORMBase.metadata 应该注册 25 张 PG 表(项目主业务表)。"""
from app.core.db import models # 触发全部模型 import
from app.core.db.orm import ORMBase
# 注意:SA 2.x 的 MetaData.tables 既能按 bare name 也能按 schema-qualified name 索引
# keyed 容器),所以用 values() 拿 Table 对象再用 .name 拿 bare 名
bare_names = {t.name for t in ORMBase.metadata.tables.values()}
assert len(bare_names) == 21, f"期望 21 张 ORM 表,实际 {len(bare_names)}: {bare_names}"
expected = {
"config", "dataset_registry", "stocks", "indices",
"kline_stock", "kline_index", "kline_5min", "moneyflow", "share",
"market_regime_daily",
"tick_trade",
"longhubang_daily", "longhubang_seat", # 2026-07-01 龙虎榜
"kline_stock_ma_daily", # 2026-07-04 mairui_ma_daily
"node_categories", "nodes", "stock_node_map", # 2026-07-02 股票-节点映射
"sync_history", # 2026-07-07 同步历史表
# 2026-07-08 mairui 技术指标 MACD/KDJ/BOLL
"kline_stock_macd_daily", "kline_stock_kdj_daily", "kline_stock_boll_daily",
}
assert bare_names == expected, f"ORM 表名集合与期望不符: {bare_names ^ expected}"
def test_orm_tables_in_market_data_schema():
"""所有 ORM 表应该在 market_data PG schema 下(不是 public,不是 None)。"""
from app.core.db import models # 触发全部模型 import
from app.core.db.orm import ORMBase
bad = []
for table in ORMBase.metadata.tables.values():
if table.schema != "market_data":
bad.append((table.name, table.schema))
assert not bad, f"以下表 schema 不是 market_data: {bad}"