feat(db_store): decouple migration from store construction
lint / lint (push) Failing after 2m4s
test / unit (pull_request) Successful in 1m2s
test / integration (pull_request) Successful in 18s
test / coverage (pull_request) Failing after 1m9s

Remove auto-migration from DbStore.__init__; add explicit check_migrations()
and migrate() methods. The CLI now checks both stores on every startup and
prompts the user to confirm before migrating. supervise.prepare() calls
.migrate() directly now that __init__ no longer does it implicitly.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-07-06 17:16:18 +00:00
parent a4d82e5ff2
commit 5fcca2060f
8 changed files with 88 additions and 19 deletions
+18
View File
@@ -7,8 +7,11 @@ from __future__ import annotations
import sys
from ..audit_store import AuditStore
from ..db_store import DbVersionError
from ..log import Die, die, error
from ..manifest import ManifestError
from ..queue_store import QueueStore
from ._common import PROG
from . import list as _list_mod
from .cleanup import cmd_cleanup
@@ -74,6 +77,21 @@ def main(argv: list[str] | None = None) -> int:
if handler is None:
usage()
die(f"unknown command: {command}")
queue_store = QueueStore("")
audit_store = AuditStore()
if not queue_store.check_migrations() or not audit_store.check_migrations():
sys.stderr.write("bot-bottle: database schema is out of date\n")
sys.stderr.write("Migrate now? [y/N] ")
sys.stderr.flush()
try:
answer = sys.stdin.readline().strip().lower()
except EOFError:
answer = ""
if answer != "y":
error("migration required — re-run and confirm to migrate")
return 1
queue_store.migrate()
audit_store.migrate()
try:
return handler(rest) or 0
except ManifestError as e: