fix(zed): make the db up/down [N] tasks work under fish (#15925)

This commit is contained in:
Raunak Bhagat authored and GitHub committed 2026-10-12 23:01:20 +00:00
1 parent 2489736c9f
commit 0bdd04cc8e
2 files changed
+55 -4

No files matched your search

+53
View File
@@ -0,0 +1,53 @@
"""Prompt for N, then move the schema up or down by N alembic revisions.
An empty answer goes all the way: `head` for up, `base` for down.
Zed joins task `args` into one command line for the user's shell without
quoting, so the prompt lives here rather than in shell syntax that only some
shells (sh, bash) accept.
Usage:
alembic_step.py (up | down)
"""
from __future__ import annotations
import runpy
import sys
from pathlib import Path
ZED_DIR = Path(__file__).resolve().parent
DIRECTIONS = {
"up": ("upgrade", "head", "+"),
"down": ("downgrade", "base", "-"),
}
def main() -> None:
if len(sys.argv) != 2 or sys.argv[1] not in DIRECTIONS:
raise SystemExit(f"usage: {Path(sys.argv[0]).name} (up | down)")
command, default, sign = DIRECTIONS[sys.argv[1]]
answer = input(f"Revisions to {command} (empty = {default}): ").strip()
if not answer:
revision = default
elif answer.isdigit() and int(answer) > 0:
revision = f"{sign}{int(answer)}"
else:
raise SystemExit(f"expected a positive whole number, got {answer!r}")
launcher = ZED_DIR / "dotenv_launch.py"
sys.argv = [
str(launcher),
".vscode/.env",
"--module",
"alembic",
command,
revision,
]
runpy.run_path(str(launcher), run_name="__main__")
if __name__ == "__main__":
main()
+2 -4
View File
@@ -113,15 +113,13 @@
// --- 5. Database ---
{
"label": "db: up [N]",
"command": "sh",
"args": ["-c", "printf 'Revisions to upgrade (empty = head): '; read n; if [ -z \"$n\" ]; then rev=head; else rev=\"+$n\"; fi; exec \"$ZED_WORKTREE_ROOT/.venv/bin/python\" -m dotenv -f \"$ZED_WORKTREE_ROOT/.vscode/.env\" run -- \"$ZED_WORKTREE_ROOT/.venv/bin/python\" -m alembic upgrade \"$rev\""],
"command": "\"$ZED_WORKTREE_ROOT/.venv/bin/python\" \"$ZED_WORKTREE_ROOT/.zed/alembic_step.py\" up",
"cwd": "$ZED_WORKTREE_ROOT/backend",
"use_new_terminal": true,
},
{
"label": "db: down [N]",
"command": "sh",
"args": ["-c", "printf 'Revisions to downgrade (empty = base): '; read n; if [ -z \"$n\" ]; then rev=base; else rev=\"-$n\"; fi; exec \"$ZED_WORKTREE_ROOT/.venv/bin/python\" -m dotenv -f \"$ZED_WORKTREE_ROOT/.vscode/.env\" run -- \"$ZED_WORKTREE_ROOT/.venv/bin/python\" -m alembic downgrade \"$rev\""],
"command": "\"$ZED_WORKTREE_ROOT/.venv/bin/python\" \"$ZED_WORKTREE_ROOT/.zed/alembic_step.py\" down",
"cwd": "$ZED_WORKTREE_ROOT/backend",
"use_new_terminal": true,
},