Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed database version can_upgrade detection #8253

Merged
merged 1 commit into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/tribler/core/versioning/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,9 @@ def can_upgrade(self) -> str | bool:
if FROM not in self.get_versions():
return False # We can't upgrade from this version.

return FROM if (self.get_current_version() in [None, TO]) else False # Always allow upgrades to git (None).
# Always allow upgrades to git (None).
current_version = self.get_current_version()
return FROM if (current_version is None or Version(TO) <= Version(current_version)) else False

def perform_upgrade(self) -> None:
"""
Expand Down
16 changes: 16 additions & 0 deletions src/tribler/test_unit/core/versioning/test_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

from ipv8.taskmanager import TaskManager
from ipv8.test.base import TestBase
from packaging.version import Version

import tribler
from tribler.core.versioning.manager import VersioningManager
Expand Down Expand Up @@ -173,6 +174,21 @@ def test_can_upgrade_to_current(self) -> None:
with patch("os.path.isfile", lambda _: False):
self.assertEqual(FROM, self.manager.can_upgrade())

def test_can_upgrade_to_current_soft(self) -> None:
"""
Check if we can upgrade to the currently supported soft version.

For example, the database directory may be (hard) version ``8.0`` and the actual (soft) version ``8.0.3``.
"""
self.manager.get_versions = Mock(return_value=[FROM])
db_version = Version(TO)
self.manager.get_current_version = Mock(
return_value=f"{db_version.major}.{db_version.minor}.{db_version.micro + 1}"
)

with patch("os.path.isfile", lambda _: False):
self.assertEqual(FROM, self.manager.can_upgrade())

def test_can_upgrade_to_git(self) -> None:
"""
Check if we can upgrade to the git version.
Expand Down