56 lines
1.5 KiB
Python
56 lines
1.5 KiB
Python
from __future__ import annotations
|
|
|
|
import os
|
|
|
|
from acupedia_ops.bootstrap.api_cli import resolve_api_root
|
|
from acupedia_ops.common.process import run_command
|
|
from acupedia_ops.common.workspace_paths import (
|
|
resolve_workspace_path,
|
|
workspace_base_path,
|
|
)
|
|
from acupedia_ops.local.workspace import LocalWorkspace
|
|
|
|
|
|
def reset_local_database(
|
|
workspace: LocalWorkspace,
|
|
*,
|
|
execute: bool,
|
|
extra_args: tuple[str, ...] = (),
|
|
) -> None:
|
|
"""Invoke the backend-owned reset CLI.
|
|
|
|
Dry-run is the backend default. `execute=True` adds --execute.
|
|
|
|
The reset implementation intentionally remains in acupedia-api because it
|
|
owns the ORM/schema semantics and reset safety checks.
|
|
"""
|
|
api_root = resolve_api_root(workspace.path("api"))
|
|
|
|
configured_python = os.environ.get("ACUPEDIA_API_PYTHON", "").strip()
|
|
if configured_python:
|
|
python = str(
|
|
resolve_workspace_path(
|
|
configured_python,
|
|
base_path=workspace.base_path,
|
|
)
|
|
)
|
|
else:
|
|
python = str(api_root / ".venv" / "bin" / "python")
|
|
|
|
if not workspace.database_reset_command:
|
|
command = [
|
|
python,
|
|
"-m",
|
|
"app.cli.reset",
|
|
"--scope",
|
|
"all",
|
|
]
|
|
else:
|
|
command = list(workspace.database_reset_command)
|
|
|
|
if execute and "--execute" not in command:
|
|
command.append("--execute")
|
|
|
|
command.extend(extra_args)
|
|
run_command(command, cwd=api_root)
|