初始化测试通过

This commit is contained in:
2026-09-10 13:04:13 +08:00
parent ccb12dad7c
commit 9c7b27c675
40 changed files with 141 additions and 1790 deletions

View File

@@ -16,6 +16,9 @@ from db.display_metadata import (
upsert_table_metadata,
)
from util.runtime_paths import get_db_path
from db.timestamp_columns import init_updated_at_trigger
ALL_BUSINESS_TABLES:tuple[str, ...] = ("todos")
# ---- 业务表 DDL(待办事项)----
# 字段顺序 = 数据管理列展示顺序;状态/优先级用 options_json 给宿主做下拉筛选
@@ -26,8 +29,8 @@ CREATE TABLE IF NOT EXISTS todos (
status TEXT NOT NULL DEFAULT 'pending',
priority TEXT NOT NULL DEFAULT 'normal',
due_at INTEGER,
created_at INTEGER NOT NULL,
updated_at INTEGER NOT NULL
created_at INTEGER NOT NULL DEFAULT (unixepoch()),
updated_at INTEGER NOT NULL DEFAULT (unixepoch())
)
"""
@@ -40,6 +43,12 @@ def get_conn() -> sqlite3.Connection:
return sqlite3.connect(get_db_path())
def _init_business_timestamp_triggers(cursor) -> None:
""" for table_name in ALL_BUSINESS_TABLES:
init_updated_at_trigger(cursor, table_name) """
init_updated_at_trigger(cursor, "todos")
def _seed_todos_display_metadata(cursor) -> None:
"""写 ``todos`` 表与字段的中文展示元数据。"""
upsert_table_metadata(
@@ -70,11 +79,11 @@ def _seed_todos_display_metadata(cursor) -> None:
"visible": 1, "searchable": 1, "editable": 0, "display_type": "enum",
"options_json": '[{"value":"high","label":"高"},{"value":"normal","label":"中"},{"value":"low","label":"低"}]'},
{"column_name": "due_at", "display_name": "截止时间", "description": "Unix 秒;可空",
"visible": 1, "searchable": 1, "editable": 0, "display_type": "datetime_unix_seconds"},
"visible": 1, "searchable": 1, "editable": 0, "display_type": "datetime_unix_seconds","default":"(unixepoch())"},
{"column_name": "created_at", "display_name": "创建时间", "description": "Unix 秒",
"visible": 1, "searchable": 0, "editable": 0, "display_type": "datetime_unix_seconds"},
"visible": 1, "searchable": 0, "editable": 0, "display_type": "datetime_unix_seconds","default":"(unixepoch())"},
{"column_name": "updated_at", "display_name": "更新时间", "description": "Unix 秒",
"visible": 0, "searchable": 0, "editable": 0, "display_type": "datetime_unix_seconds"},
"visible": 0, "searchable": 0, "editable": 0, "display_type": "datetime_unix_seconds","default":"(unixepoch())"},
],
)
@@ -89,8 +98,11 @@ def init_db() -> None:
# 2. 业务表
cur.execute(_TODOS_DDL)
cur.execute(_TODOS_INDEX)
_init_business_timestamp_triggers(cur)
# 3. 业务表展示元数据
_seed_todos_display_metadata(cur)
conn.commit()
finally:
conn.close()