516 lines
20 KiB
Python
516 lines
20 KiB
Python
"""高频运载火箭型号预置。
|
||
|
||
发射事件按型号关联到 rocket_configs,因此模拟器和事件列表里应当总有当下发射
|
||
最频繁的型号。这里登记一批公开资料里的型号参数,启动时按 code 补齐缺失项:
|
||
已存在的型号一律不动(管理端改过的参数以管理端为准),被删掉的型号会在下次
|
||
启动时重新补上(与默认系统设置的行为一致)。
|
||
|
||
stage_1 沿用库里既有约定:捆绑助推器的发动机数量与推力并入一级登记
|
||
(长征五号 10 台 = 芯级 2 台 + 4 个助推器各 2 台)。
|
||
"""
|
||
import logging
|
||
from typing import Any
|
||
|
||
from sqlalchemy import func, select, text
|
||
from sqlalchemy.ext.asyncio import AsyncSession
|
||
|
||
from app.models.db import RocketConfig
|
||
|
||
logger = logging.getLogger(__name__)
|
||
|
||
HIGH_FREQUENCY_ROCKETS: list[dict[str, Any]] = [
|
||
{
|
||
"code": "starship",
|
||
"name": "Starship",
|
||
"name_zh": "星舰",
|
||
"manufacturer": "SpaceX",
|
||
"country": "美国",
|
||
"launch_site_name": "Starbase 星港",
|
||
"launch_latitude_deg": 25.9972,
|
||
"launch_longitude_deg": -97.1575,
|
||
"description": "两级完全可重复使用超重型运载火箭,一级为超重型助推器(33 台猛禽),二级为星舰飞船。",
|
||
"color": "#c9ced4",
|
||
"height_m": 122.5,
|
||
"diameter_m": 9.0,
|
||
"payload_mass_kg": 100000,
|
||
"drag_coefficient": 0.45,
|
||
"reference_area_m2": 63.62,
|
||
"target_orbit_km": 400,
|
||
"target_velocity_mps": 7800,
|
||
"separation_delay_seconds": 1.0,
|
||
"second_stage_ignition_delay_seconds": 0.6,
|
||
"stage_1": {
|
||
"name": "超重型助推器",
|
||
"dry_mass_kg": 240000,
|
||
"fuel_mass_kg": 3400000,
|
||
"max_thrust_n": 72000000,
|
||
"specific_impulse_s": 327,
|
||
"engine_count": 33,
|
||
"length_ratio": 0.58,
|
||
},
|
||
"stage_2": {
|
||
"name": "星舰飞船",
|
||
"dry_mass_kg": 120000,
|
||
"fuel_mass_kg": 1200000,
|
||
"max_thrust_n": 13800000,
|
||
"specific_impulse_s": 350,
|
||
"engine_count": 6,
|
||
"length_ratio": 0.42,
|
||
},
|
||
},
|
||
{
|
||
"code": "electron",
|
||
"name": "Electron",
|
||
"name_zh": "电子号",
|
||
"manufacturer": "Rocket Lab",
|
||
"country": "新西兰",
|
||
"launch_site_name": "LC-1 马希亚发射场",
|
||
"launch_latitude_deg": -39.2618,
|
||
"launch_longitude_deg": -177.864,
|
||
"description": "小型液体运载火箭,一级 9 台卢瑟福发动机电动泵压循环,用于小卫星专属与拼车发射。",
|
||
"color": "#242a30",
|
||
"height_m": 33.0,
|
||
"diameter_m": 1.2,
|
||
"payload_mass_kg": 300,
|
||
"drag_coefficient": 0.35,
|
||
"reference_area_m2": 1.13,
|
||
"target_orbit_km": 500,
|
||
"target_velocity_mps": 7600,
|
||
"separation_delay_seconds": 2.0,
|
||
"second_stage_ignition_delay_seconds": 1.0,
|
||
"stage_1": {
|
||
"name": "一级(9 台卢瑟福)",
|
||
"dry_mass_kg": 1100,
|
||
"fuel_mass_kg": 8900,
|
||
"max_thrust_n": 189000,
|
||
"specific_impulse_s": 319,
|
||
"engine_count": 9,
|
||
"length_ratio": 0.66,
|
||
},
|
||
"stage_2": {
|
||
"name": "二级(真空卢瑟福)",
|
||
"dry_mass_kg": 200,
|
||
"fuel_mass_kg": 700,
|
||
"max_thrust_n": 19600,
|
||
"specific_impulse_s": 339,
|
||
"engine_count": 1,
|
||
"length_ratio": 0.34,
|
||
},
|
||
},
|
||
{
|
||
"code": "long-march-2f",
|
||
"name": "Long March 2F",
|
||
"name_zh": "长征二号F",
|
||
"manufacturer": "中国运载火箭技术研究院",
|
||
"country": "中国",
|
||
"launch_site_name": "酒泉卫星发射中心",
|
||
"launch_latitude_deg": 40.958,
|
||
"launch_longitude_deg": 100.291,
|
||
"description": "带四个液体助推器的两级载人运载火箭,用于神舟载人飞船与空间实验室任务。",
|
||
"color": "#eef1f5",
|
||
"height_m": 58.34,
|
||
"diameter_m": 3.35,
|
||
"payload_mass_kg": 8150,
|
||
"drag_coefficient": 0.4,
|
||
"reference_area_m2": 8.81,
|
||
"target_orbit_km": 400,
|
||
"target_velocity_mps": 7670,
|
||
"separation_delay_seconds": 2.5,
|
||
"second_stage_ignition_delay_seconds": 1.2,
|
||
"stage_1": {
|
||
"name": "芯一级与四个助推器",
|
||
"dry_mass_kg": 50000,
|
||
"fuel_mass_kg": 340000,
|
||
"max_thrust_n": 5958000,
|
||
"specific_impulse_s": 264,
|
||
"engine_count": 8,
|
||
"length_ratio": 0.6,
|
||
},
|
||
"stage_2": {
|
||
"name": "芯二级(YF-24B)",
|
||
"dry_mass_kg": 5000,
|
||
"fuel_mass_kg": 55000,
|
||
"max_thrust_n": 720000,
|
||
"specific_impulse_s": 315,
|
||
"engine_count": 1,
|
||
"length_ratio": 0.4,
|
||
},
|
||
},
|
||
{
|
||
"code": "long-march-7",
|
||
"name": "Long March 7",
|
||
"name_zh": "长征七号",
|
||
"manufacturer": "中国运载火箭技术研究院",
|
||
"country": "中国",
|
||
"launch_site_name": "文昌航天发射场",
|
||
"launch_latitude_deg": 19.6145,
|
||
"launch_longitude_deg": 110.951,
|
||
"description": "4 米级液氧煤油中型运载火箭,四个助推器各两台 YF-100,用于天舟货运飞船等高频次发射。",
|
||
"color": "#e6ebf1",
|
||
"height_m": 53.1,
|
||
"diameter_m": 3.35,
|
||
"payload_mass_kg": 13800,
|
||
"drag_coefficient": 0.4,
|
||
"reference_area_m2": 8.81,
|
||
"target_orbit_km": 400,
|
||
"target_velocity_mps": 7670,
|
||
"separation_delay_seconds": 2.5,
|
||
"second_stage_ignition_delay_seconds": 1.2,
|
||
"stage_1": {
|
||
"name": "芯一级与四个助推器(10 台 YF-100)",
|
||
"dry_mass_kg": 40000,
|
||
"fuel_mass_kg": 470000,
|
||
"max_thrust_n": 7200000,
|
||
"specific_impulse_s": 300,
|
||
"engine_count": 10,
|
||
"length_ratio": 0.62,
|
||
},
|
||
"stage_2": {
|
||
"name": "芯二级(2 台 YF-115)",
|
||
"dry_mass_kg": 3000,
|
||
"fuel_mass_kg": 40000,
|
||
"max_thrust_n": 360000,
|
||
"specific_impulse_s": 334,
|
||
"engine_count": 2,
|
||
"length_ratio": 0.38,
|
||
},
|
||
},
|
||
{
|
||
"code": "long-march-6a",
|
||
"name": "Long March 6A",
|
||
"name_zh": "长征六号甲",
|
||
"manufacturer": "上海航天技术研究院",
|
||
"country": "中国",
|
||
"launch_site_name": "太原卫星发射中心",
|
||
"launch_latitude_deg": 38.846,
|
||
"launch_longitude_deg": 111.608,
|
||
"description": "液氧煤油芯级捆绑四台固体助推器的中型运载火箭,面向太阳同步轨道高频次拼车发射。",
|
||
"color": "#e9eef4",
|
||
"height_m": 50.5,
|
||
"diameter_m": 3.35,
|
||
"payload_mass_kg": 6500,
|
||
"drag_coefficient": 0.4,
|
||
"reference_area_m2": 8.81,
|
||
"target_orbit_km": 500,
|
||
"target_velocity_mps": 7600,
|
||
"separation_delay_seconds": 2.2,
|
||
"second_stage_ignition_delay_seconds": 1.0,
|
||
"stage_1": {
|
||
"name": "芯一级与四台固体助推器",
|
||
"dry_mass_kg": 45000,
|
||
"fuel_mass_kg": 405000,
|
||
"max_thrust_n": 6400000,
|
||
"specific_impulse_s": 285,
|
||
"engine_count": 10,
|
||
"length_ratio": 0.6,
|
||
},
|
||
"stage_2": {
|
||
"name": "二级(2 台 YF-115)",
|
||
"dry_mass_kg": 3000,
|
||
"fuel_mass_kg": 40000,
|
||
"max_thrust_n": 360000,
|
||
"specific_impulse_s": 334,
|
||
"engine_count": 2,
|
||
"length_ratio": 0.4,
|
||
},
|
||
},
|
||
{
|
||
"code": "long-march-8",
|
||
"name": "Long March 8",
|
||
"name_zh": "长征八号",
|
||
"manufacturer": "中国运载火箭技术研究院",
|
||
"country": "中国",
|
||
"launch_site_name": "文昌航天发射场",
|
||
"launch_latitude_deg": 19.6145,
|
||
"launch_longitude_deg": 110.951,
|
||
"description": "两级液氧煤油中型运载火箭,捆绑两个助推器,主打太阳同步轨道商业星座发射。",
|
||
"color": "#e6ebf1",
|
||
"height_m": 50.4,
|
||
"diameter_m": 3.35,
|
||
"payload_mass_kg": 7600,
|
||
"drag_coefficient": 0.4,
|
||
"reference_area_m2": 8.81,
|
||
"target_orbit_km": 500,
|
||
"target_velocity_mps": 7600,
|
||
"separation_delay_seconds": 2.2,
|
||
"second_stage_ignition_delay_seconds": 1.0,
|
||
"stage_1": {
|
||
"name": "芯一级与两个助推器(6 台 YF-100)",
|
||
"dry_mass_kg": 38000,
|
||
"fuel_mass_kg": 380000,
|
||
"max_thrust_n": 7194000,
|
||
"specific_impulse_s": 300,
|
||
"engine_count": 6,
|
||
"length_ratio": 0.6,
|
||
},
|
||
"stage_2": {
|
||
"name": "二级(2 台 YF-115)",
|
||
"dry_mass_kg": 3500,
|
||
"fuel_mass_kg": 55000,
|
||
"max_thrust_n": 360000,
|
||
"specific_impulse_s": 334,
|
||
"engine_count": 2,
|
||
"length_ratio": 0.4,
|
||
},
|
||
},
|
||
{
|
||
"code": "falcon-heavy",
|
||
"name": "Falcon Heavy",
|
||
"name_zh": "猎鹰重型",
|
||
"manufacturer": "SpaceX",
|
||
"country": "美国",
|
||
"launch_site_name": "LC-39A 肯尼迪航天中心",
|
||
"launch_latitude_deg": 28.6083,
|
||
"launch_longitude_deg": -80.6041,
|
||
"description": "三枚猎鹰 9 一芯级并联的重型运载火箭;载荷按三芯级回收构型登记(一次性构型约 63.8 吨)。",
|
||
"color": "#f8fafc",
|
||
"height_m": 70.0,
|
||
"diameter_m": 3.7,
|
||
"payload_mass_kg": 27700,
|
||
"drag_coefficient": 0.4,
|
||
"reference_area_m2": 10.75,
|
||
"target_orbit_km": 200,
|
||
"target_velocity_mps": 7800,
|
||
"separation_delay_seconds": 2.2,
|
||
"second_stage_ignition_delay_seconds": 1.0,
|
||
"stage_1": {
|
||
"name": "三芯级(27 台梅林 1D)",
|
||
"dry_mass_kg": 76800,
|
||
"fuel_mass_kg": 1233000,
|
||
"max_thrust_n": 22821000,
|
||
"specific_impulse_s": 282,
|
||
"engine_count": 27,
|
||
"length_ratio": 0.65,
|
||
},
|
||
"stage_2": {
|
||
"name": "二级(梅林真空型)",
|
||
"dry_mass_kg": 4000,
|
||
"fuel_mass_kg": 107500,
|
||
"max_thrust_n": 981000,
|
||
"specific_impulse_s": 348,
|
||
"engine_count": 1,
|
||
"length_ratio": 0.35,
|
||
},
|
||
},
|
||
]
|
||
|
||
|
||
# 外观构型预置:按 code 登记,与型号参数定义分开,因此用户手工登记的型号
|
||
# (联盟 2、阿丽亚娜 6)也能在这里补齐构型。仅在库里 appearance 仍为空时写入,
|
||
# 管理端填过的值不会被动。联盟 2 = 4 个侧级各 1 台 + 芯级 1 台;
|
||
# 阿丽亚娜 6(A62)= 2 个 P120 固体助推各 1 台 + 芯级 2 台。
|
||
ROCKET_APPEARANCES: dict[str, dict[str, Any]] = {
|
||
"starship": {"booster_count": 0, "grid_fins": True, "fairing": False},
|
||
"electron": {"booster_count": 0, "grid_fins": False},
|
||
"falcon-heavy": {
|
||
"booster_count": 2,
|
||
"engines_per_booster": 9,
|
||
"core_engine_count": 9,
|
||
"booster_diameter_ratio": 1.0,
|
||
"grid_fins": True,
|
||
},
|
||
"long-march-2f": {
|
||
"booster_count": 4,
|
||
"engines_per_booster": 1,
|
||
"core_engine_count": 4,
|
||
"booster_diameter_ratio": 0.67,
|
||
"grid_fins": False,
|
||
},
|
||
"long-march-7": {
|
||
"booster_count": 4,
|
||
"engines_per_booster": 2,
|
||
"core_engine_count": 2,
|
||
"booster_diameter_ratio": 0.67,
|
||
"grid_fins": False,
|
||
},
|
||
"long-march-6a": {
|
||
"booster_count": 4,
|
||
"engines_per_booster": 2,
|
||
"core_engine_count": 2,
|
||
"booster_diameter_ratio": 0.79,
|
||
"grid_fins": False,
|
||
},
|
||
"long-march-8": {
|
||
"booster_count": 2,
|
||
"engines_per_booster": 2,
|
||
"core_engine_count": 2,
|
||
"booster_diameter_ratio": 0.67,
|
||
"grid_fins": False,
|
||
},
|
||
"soyuz-2": {
|
||
"booster_count": 4,
|
||
"engines_per_booster": 1,
|
||
"core_engine_count": 1,
|
||
"booster_diameter_ratio": 0.75,
|
||
"grid_fins": False,
|
||
},
|
||
"ariane-6": {
|
||
"booster_count": 2,
|
||
"engines_per_booster": 1,
|
||
"core_engine_count": 2,
|
||
"booster_diameter_ratio": 0.56,
|
||
"grid_fins": False,
|
||
},
|
||
}
|
||
|
||
|
||
async def ensure_rocket_appearance(db: AsyncSession) -> list[str]:
|
||
"""按 ROCKET_APPEARANCES 补写外观构型。
|
||
|
||
型号预置只补插缺失的型号,早已入库的型号不会带上 appearance,因此这里做一次
|
||
幂等回填:逐字段补齐库里还没有的 key,管理端填过的值(含显式 null)一律不动。
|
||
新增预置字段因此能在下次启动时自动补上,无需手工维护数据。
|
||
"""
|
||
presets = ROCKET_APPEARANCES
|
||
# 部署时 up -d 早于 upgrade_db.py,列可能还没加上;这里跳过而不是让服务起不来
|
||
column = await db.execute(
|
||
text("SELECT 1 FROM information_schema.columns "
|
||
"WHERE table_name = 'rocket_configs' AND column_name = 'appearance'")
|
||
)
|
||
if column.first() is None:
|
||
logger.warning("rocket_configs.appearance 列不存在,跳过外观构型回填(执行 upgrade_db.py --apply 后重启生效)")
|
||
return []
|
||
result = await db.execute(select(RocketConfig).where(RocketConfig.code.in_(presets)))
|
||
|
||
updated: list[str] = []
|
||
for rocket in result.scalars().all():
|
||
current = dict(rocket.appearance or {})
|
||
missing = {key: value for key, value in presets[rocket.code].items() if key not in current}
|
||
if not missing:
|
||
continue
|
||
current.update(missing)
|
||
rocket.appearance = current
|
||
updated.append(rocket.code)
|
||
|
||
if updated:
|
||
await db.flush()
|
||
logger.info("火箭外观构型回填:%s", ", ".join(updated))
|
||
return updated
|
||
|
||
|
||
# 助推器组合预置:公开资料近似值,用于把「捆绑助推器」从一级里拆出来单独计量。
|
||
# 数值都是一级里属于助推器的那一部分(合计口径),芯级由 stage_1 减去本组得到。
|
||
# 说明几点口径选择:
|
||
# - 固体助推器登记的是平均推力(P120C 峰值 4.46 MN、平均 3.5 MN),模拟为等推力,
|
||
# 用平均推力才能烧出真实的助推器工作时间;
|
||
# - 猎鹰重型侧芯级与中心级是同款 F9 一级,但侧芯级提前几秒关机(省推进剂返场),
|
||
# 因此助推器推进剂登记得比单枚一级少,中心级余量更多,分离与 MECO 时序才对得上;
|
||
# - 芯级比冲沿用 stage_1.specific_impulse_s(登记的是整段一级的有效比冲)。
|
||
ROCKET_BOOSTERS: dict[str, dict[str, Any]] = {
|
||
# 两枚 F9 一级作侧芯级:2×7.607 MN、2×25.6 t 干重
|
||
"falcon-heavy": {"count": 2, "thrust_n": 15214000, "specific_impulse_s": 282, "dry_mass_kg": 51200, "fuel_mass_kg": 780000},
|
||
# 4 枚 3.35 m 助推器,各 2 台 YF-100、推进剂 142.8 t、干重 13.8 t
|
||
"long-march-5": {"count": 4, "thrust_n": 9600000, "specific_impulse_s": 300, "dry_mass_kg": 55200, "fuel_mass_kg": 571200},
|
||
# 联盟 2 的四个侧级(Blok B/V/G/D),各 1 台 RD-107
|
||
"soyuz-2": {"count": 4, "thrust_n": 3352000, "specific_impulse_s": 255, "dry_mass_kg": 12000, "fuel_mass_kg": 166000},
|
||
# 长征二号 F:4 个助推器各 1 台,与芯级 4 台各占一半推力
|
||
"long-march-2f": {"count": 4, "thrust_n": 2979000, "specific_impulse_s": 263, "dry_mass_kg": 12000, "fuel_mass_kg": 150000},
|
||
# 长征七号:4 个 2.25 m 助推器各 1 台 YF-100(1.179 MN),芯级 2 台
|
||
"long-march-7": {"count": 4, "thrust_n": 4716000, "specific_impulse_s": 300, "dry_mass_kg": 20000, "fuel_mass_kg": 200000},
|
||
"long-march-8": {"count": 2, "thrust_n": 4796000, "specific_impulse_s": 300, "dry_mass_kg": 12000, "fuel_mass_kg": 165000},
|
||
}
|
||
|
||
# 两个型号有意不登记 boosters:
|
||
# - ariane-6:它的一级本来就是 P120C 助推器组,主级在 stage_2,再拆一次会把芯级算两遍;
|
||
# - long-march-6a:公开推力口径互相矛盾(登记值里大部分发动机在助推器上),
|
||
# 拆分后芯级推重比不足,在本简化弹道模型里无法维持飞行。
|
||
|
||
# 一级口径修正:早期预置把「助推器推力 + 芯级推进剂」混在一起登记(长征五号一级
|
||
# 只有芯级的 175 t 推进剂,却登记了含助推器的 10.6 MN 推力),拆分助推器之后必须
|
||
# 统一成「一级合计」口径。只在库里仍是旧值且还没登记 boosters 时才改,
|
||
# 管理端改过的型号一律不动。
|
||
STAGE1_TOTAL_FIXES: dict[str, dict[str, Any]] = {
|
||
"long-march-5": {
|
||
"expect": {"dry_mass_kg": 38000, "fuel_mass_kg": 175000},
|
||
"stage_1": {
|
||
"name": "芯一级与四个助推器(YF-77×2 + YF-100×8)",
|
||
"dry_mass_kg": 90000,
|
||
"fuel_mass_kg": 736500,
|
||
},
|
||
},
|
||
"long-march-7": {
|
||
# 长征七号起飞用 6 台 YF-100(芯级 2 台 + 4 个助推器各 1 台),不是 10 台
|
||
"expect": {"engine_count": 10},
|
||
"stage_1": {"name": "芯一级与四个助推器(6 台 YF-100)", "engine_count": 6},
|
||
"appearance": {"core_engine_count": 2, "engines_per_booster": 1},
|
||
},
|
||
}
|
||
|
||
|
||
async def ensure_rocket_boosters(db: AsyncSession) -> list[str]:
|
||
"""按 ROCKET_BOOSTERS 登记助推器组合,并顺带统一一级口径。
|
||
|
||
与外观预置一样是幂等回填:库里已经有 boosters 的型号(包括管理端自己填的)
|
||
一律不动,因此一级口径修正也只会对旧数据执行一次。
|
||
"""
|
||
codes = set(ROCKET_BOOSTERS) | set(STAGE1_TOTAL_FIXES)
|
||
column = await db.execute(
|
||
text("SELECT 1 FROM information_schema.columns "
|
||
"WHERE table_name = 'rocket_configs' AND column_name = 'boosters'")
|
||
)
|
||
if column.first() is None:
|
||
logger.warning("rocket_configs.boosters 列不存在,跳过助推器参数回填(执行 upgrade_db.py --apply 后重启生效)")
|
||
return []
|
||
result = await db.execute(select(RocketConfig).where(RocketConfig.code.in_(codes)))
|
||
|
||
updated: list[str] = []
|
||
for rocket in result.scalars().all():
|
||
if rocket.boosters:
|
||
continue
|
||
fix = STAGE1_TOTAL_FIXES.get(rocket.code)
|
||
if fix:
|
||
current = dict(rocket.stage_1 or {})
|
||
if all(current.get(key) == value for key, value in fix["expect"].items()):
|
||
current.update(fix["stage_1"])
|
||
rocket.stage_1 = current
|
||
appearance = dict(rocket.appearance or {})
|
||
appearance.update(fix.get("appearance", {}))
|
||
rocket.appearance = appearance
|
||
logger.info("火箭 %s 一级口径已统一为含助推器的合计值:%s", rocket.code, fix["stage_1"])
|
||
else:
|
||
logger.info("火箭 %s 的一级参数已被修改过,跳过口径修正", rocket.code)
|
||
preset = ROCKET_BOOSTERS.get(rocket.code)
|
||
if not preset:
|
||
continue
|
||
# 口径修正没生效(管理端自己改过一级)时,助推器数值可能超出一级总量,
|
||
# 这种自相矛盾的数据宁可不登记,也不能让模拟算出负推力
|
||
stage1 = rocket.stage_1 or {}
|
||
if not _boosters_fit_stage1(preset, stage1):
|
||
logger.warning("火箭 %s 的助推器预置超出其一级的总量,跳过登记", rocket.code)
|
||
continue
|
||
rocket.boosters = dict(preset)
|
||
updated.append(rocket.code)
|
||
|
||
if updated:
|
||
await db.flush()
|
||
logger.info("火箭助推器参数回填:%s", ", ".join(updated))
|
||
return updated
|
||
|
||
|
||
def _boosters_fit_stage1(boosters: dict[str, Any], stage_1: dict[str, Any]) -> bool:
|
||
pairs = (
|
||
("thrust_n", "max_thrust_n"),
|
||
("dry_mass_kg", "dry_mass_kg"),
|
||
("fuel_mass_kg", "fuel_mass_kg"),
|
||
)
|
||
return all((boosters.get(key) or 0) <= (stage_1.get(total) or 0) for key, total in pairs)
|
||
|
||
|
||
async def ensure_high_frequency_rockets(db: AsyncSession) -> list[str]:
|
||
"""补齐缺失的高频型号,返回新入库的 code 列表。"""
|
||
existing = set((await db.execute(select(RocketConfig.code))).scalars().all())
|
||
next_order = (await db.scalar(select(func.max(RocketConfig.sort_order)))) or 0
|
||
|
||
added: list[str] = []
|
||
for preset in HIGH_FREQUENCY_ROCKETS:
|
||
if preset["code"] in existing:
|
||
continue
|
||
next_order += 1
|
||
db.add(RocketConfig(**preset, sort_order=next_order))
|
||
added.append(preset["code"])
|
||
|
||
if added:
|
||
await db.flush()
|
||
logger.info("火箭型号预置补齐:%s", ", ".join(added))
|
||
return added
|