Skip to content

Commit be74781

Browse files
committed
🐛 fix(alembic): revision default args
- `head` should be "base" if `branch-label` is provided but dose not exist
1 parent a813bbd commit be74781

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

nonebot_plugin_orm/migrate.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -445,18 +445,17 @@ def revision(
445445
script = ScriptDirectory.from_config(config)
446446

447447
if not head:
448+
scripts = script.get_revisions(script.get_heads())
448449
if branch_label:
449-
head = f"{branch_label}@head"
450-
elif len(heads := script.get_heads()) <= 1:
450+
if any(branch_label in sc.branch_labels for sc in scripts):
451+
head = f"{branch_label}@head"
452+
else:
453+
head = "base"
454+
elif len(scripts) <= 1:
451455
head = "head"
452456
else:
453457
try:
454-
head = next(
455-
filterfalse(
456-
attrgetter("branch_labels"),
457-
script.get_revisions(heads),
458-
)
459-
).revision
458+
head = next(filterfalse(attrgetter("branch_labels"), scripts)).revision
460459
except StopIteration:
461460
head = "base"
462461

0 commit comments

Comments
 (0)