fix: 预览按 draft-{id} 命名且重建全量同构 + C1 空台账改判数据待补 + 立项经费结余结论 + CLI 拆分 import-*/list-* + docx 占位黄底
This commit is contained in:
@@ -36,6 +36,7 @@ CREATE TABLE IF NOT EXISTS closing_projects (
|
||||
program TEXT,
|
||||
start_date TEXT,
|
||||
end_date TEXT,
|
||||
approved_budget REAL,
|
||||
expected_json TEXT,
|
||||
annual_report_excerpt TEXT,
|
||||
status TEXT NOT NULL DEFAULT '待结题',
|
||||
@@ -118,6 +119,7 @@ _CLOSING_PROJECTS_COLUMNS: tuple[dict[str, object], ...] = (
|
||||
_col("program", "项目类型", "如 国家自然科学基金(青年/面上)。", searchable=1, editable=1),
|
||||
_col("start_date", "执行期开始", "YYYY-MM-DD。", searchable=1, editable=1),
|
||||
_col("end_date", "执行期结束", "YYYY-MM-DD。", searchable=1, editable=1),
|
||||
_col("approved_budget", "立项经费", "立项批准经费(元);用于决算结余与预算符合性结论。", editable=1, display_type="number"),
|
||||
_col("expected_json", "预期成果指标", "如 [{\"type\":\"论文\",\"target\":3,\"unit\":\"篇\"}]。", visible=0, display_type="textarea", editable=1),
|
||||
_col("annual_report_excerpt", "年度报告摘句", "年度/中期报告关键句(分号分隔),供叙事素材。", visible=0, display_type="textarea", editable=1),
|
||||
_col("status", "状态", "待结题 / 初稿已生成 / 已提交。", searchable=1, editable=1, options_json='[{"value":"待结题","label":"待结题"},{"value":"初稿已生成","label":"初稿已生成"},{"value":"已提交","label":"已提交"}]'),
|
||||
@@ -162,8 +164,18 @@ _REPORT_DRAFTS_COLUMNS: tuple[dict[str, object], ...] = (
|
||||
)
|
||||
|
||||
|
||||
def _ensure_columns(cursor, table_name: str, columns: tuple[tuple[str, str], ...]) -> None:
|
||||
"""幂等迁移:老库缺列时 ALTER TABLE 补列(CREATE TABLE IF NOT EXISTS 不会改已有表)。"""
|
||||
cursor.execute(f"PRAGMA table_info({table_name})")
|
||||
existing = {str(row[1]) for row in cursor.fetchall()}
|
||||
for column_name, column_ddl in columns:
|
||||
if column_name not in existing:
|
||||
cursor.execute(f"ALTER TABLE {table_name} ADD COLUMN {column_ddl}")
|
||||
|
||||
|
||||
def _init_closing_projects_metadata(cursor) -> None:
|
||||
cursor.execute(_CLOSING_PROJECTS_DDL)
|
||||
_ensure_columns(cursor, "closing_projects", (("approved_budget", "approved_budget REAL"),))
|
||||
init_updated_at_trigger(cursor, "closing_projects")
|
||||
upsert_table_metadata(
|
||||
cursor,
|
||||
|
||||
Reference in New Issue
Block a user