feat(wizard): add Postgres backend question to setup wizard

setup_wizard.py 在 Step 3 (Execution) 之后新增一个 Database 问答:
"Use Postgres? (y = postgres, n = sqlite)",默认 y(Stage 0+ 推荐 PG)。
选 y 时引导填 DATABASE_URL(可留空稍后写 .env);DATABASE_URL 进 .env,
config.yaml 写入 database.backend=postgres + postgres_url=\$DATABASE_URL。

writer.py build_minimal_config 加 database_backend 参数,postgres 时
覆盖 base_config 的 database 段;默认 sqlite 时沿用 base_config 行为
(继承 config.example.yaml 的 sqlite_dir 等)。

minimal pattern:不新建 wizard/steps/database.py,inline 在 main 里加 1
问答 + writer 加 1 参数。后续如果需要更复杂数据库选项再升为完整 step 模块。

Stage 0 PR1 T1.8.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
1445043649
2026-05-10 22:55:19 +08:00
parent e6f5ba53bd
commit eae0190184
2 changed files with 46 additions and 1 deletions
+16 -1
View File
@@ -172,8 +172,14 @@ def build_minimal_config(
include_write_tools: bool = True,
config_version: int = 5,
base_config: dict[str, Any] | None = None,
database_backend: str = "sqlite",
) -> str:
"""Build the content of a minimal config.yaml."""
"""Build the content of a minimal config.yaml.
``database_backend``: ``"sqlite"`` (default; reuses base_config's sqlite_dir)
or ``"postgres"`` (writes ``backend: postgres`` + ``postgres_url: $DATABASE_URL``;
``DATABASE_URL`` must be set in ``.env``).
"""
from datetime import date
today = date.today().isoformat()
@@ -220,6 +226,13 @@ def build_minimal_config(
sandbox_config.pop("allow_host_bash", None)
data["sandbox"] = sandbox_config
# Override database backend if user chose postgres in the wizard.
if database_backend == "postgres":
data["database"] = {
"backend": "postgres",
"postgres_url": "$DATABASE_URL",
}
header = (
f"# DeerFlow Configuration\n"
f"# Generated by 'make setup' on {today}\n"
@@ -250,6 +263,7 @@ def write_config_yaml(
allow_host_bash: bool = False,
include_bash_tool: bool = False,
include_write_tools: bool = True,
database_backend: str = "sqlite",
) -> None:
"""Write (or overwrite) config.yaml with a minimal working configuration."""
# Read config_version from config.example.yaml if present
@@ -286,5 +300,6 @@ def write_config_yaml(
include_write_tools=include_write_tools,
config_version=config_version,
base_config=example_defaults,
database_backend=database_backend,
)
config_path.write_text(content, encoding="utf-8")