refactor: rename check_migrations → is_migrated
test / unit (pull_request) Successful in 58s
test / integration (pull_request) Successful in 18s
test / coverage (pull_request) Successful in 1m6s
lint / lint (push) Successful in 1m55s
prd-number / assign-numbers (push) Successful in 16s
test / unit (push) Successful in 54s
test / integration (push) Successful in 19s
test / coverage (push) Successful in 1m6s
Update Quality Badges / update-badges (push) Successful in 1m2s
test / unit (pull_request) Successful in 58s
test / integration (pull_request) Successful in 18s
test / coverage (pull_request) Successful in 1m6s
lint / lint (push) Successful in 1m55s
prd-number / assign-numbers (push) Successful in 16s
test / unit (push) Successful in 54s
test / integration (push) Successful in 19s
test / coverage (push) Successful in 1m6s
Update Quality Badges / update-badges (push) Successful in 1m2s
Boolean-returning methods should read as predicates. Renames DbStore.check_migrations, StoreManager.check_migrations, and the test patch accordingly.
This commit was merged in pull request #320.
This commit is contained in:
@@ -76,7 +76,7 @@ def main(argv: list[str] | None = None) -> int:
|
|||||||
usage()
|
usage()
|
||||||
die(f"unknown command: {command}")
|
die(f"unknown command: {command}")
|
||||||
mgr = StoreManager.instance()
|
mgr = StoreManager.instance()
|
||||||
if not mgr.check_migrations():
|
if not mgr.is_migrated():
|
||||||
sys.stderr.write("bot-bottle: database schema is out of date\n")
|
sys.stderr.write("bot-bottle: database schema is out of date\n")
|
||||||
sys.stderr.write("Migrate now? [y/N] ")
|
sys.stderr.write("Migrate now? [y/N] ")
|
||||||
sys.stderr.flush()
|
sys.stderr.flush()
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ class DbStore:
|
|||||||
conn.row_factory = sqlite3.Row
|
conn.row_factory = sqlite3.Row
|
||||||
return conn
|
return conn
|
||||||
|
|
||||||
def check_migrations(self) -> bool:
|
def is_migrated(self) -> bool:
|
||||||
"""Return True if the DB is fully up-to-date, False if migration is needed."""
|
"""Return True if the DB is fully up-to-date, False if migration is needed."""
|
||||||
if not self.db_path.exists():
|
if not self.db_path.exists():
|
||||||
return False
|
return False
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ _instance: StoreManager | None = None
|
|||||||
|
|
||||||
|
|
||||||
class StoreManager:
|
class StoreManager:
|
||||||
"""Owns db_path and delegates migrate/check_migrations across all stores.
|
"""Owns db_path and delegates migrate/is_migrated across all stores.
|
||||||
|
|
||||||
Use instance() for normal access. Call reset(db_path) in tests to swap
|
Use instance() for normal access. Call reset(db_path) in tests to swap
|
||||||
the singleton to a temp path, then reset() with no args to restore the
|
the singleton to a temp path, then reset() with no args to restore the
|
||||||
@@ -46,10 +46,10 @@ class StoreManager:
|
|||||||
global _instance
|
global _instance
|
||||||
_instance = cls(db_path)
|
_instance = cls(db_path)
|
||||||
|
|
||||||
def check_migrations(self) -> bool:
|
def is_migrated(self) -> bool:
|
||||||
return (
|
return (
|
||||||
QueueStore("", self.db_path).check_migrations()
|
QueueStore("", self.db_path).is_migrated()
|
||||||
and AuditStore(self.db_path).check_migrations()
|
and AuditStore(self.db_path).is_migrated()
|
||||||
)
|
)
|
||||||
|
|
||||||
def migrate(self) -> None:
|
def migrate(self) -> None:
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ from bot_bottle.store_manager import StoreManager
|
|||||||
|
|
||||||
class TestMainDispatch(unittest.TestCase):
|
class TestMainDispatch(unittest.TestCase):
|
||||||
def setUp(self) -> None:
|
def setUp(self) -> None:
|
||||||
patcher = patch.object(DbStore, "check_migrations", return_value=True)
|
patcher = patch.object(DbStore, "is_migrated", return_value=True)
|
||||||
self._mock_check = patcher.start()
|
self._mock_check = patcher.start()
|
||||||
self.addCleanup(patcher.stop)
|
self.addCleanup(patcher.stop)
|
||||||
self.addCleanup(StoreManager.reset)
|
self.addCleanup(StoreManager.reset)
|
||||||
|
|||||||
Reference in New Issue
Block a user