Skip to content

Commit

Permalink
feat(tests): local version merge
Browse files Browse the repository at this point in the history
  • Loading branch information
MorvanZhou committed Apr 20, 2024
1 parent c301ed1 commit 76a7d64
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/retk/models/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ async def local_try_create_or_restore(self): # noqa: C901

async def _local_restore(self):
# restore user
version_manager.migrate.to_latest_version(config.get_settings().RETHINK_LOCAL_STORAGE_PATH)
_v = version_manager.recover.load_dot_rethink(
path=config.get_settings().RETHINK_LOCAL_STORAGE_PATH / ".data" / ".rethink.json"
)
Expand Down
13 changes: 12 additions & 1 deletion src/retk/version_manager/migrate.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from pathlib import Path
from typing import Union, Dict, Optional

from retk import const
from retk._version import __version__
from retk.logger import logger

Expand All @@ -17,7 +18,7 @@ def __version_less_than(dot_rethink: Dict, version) -> bool:
dot_version = dot_rethink.get("version")
if dot_version is None:
return True
return __current_version < version_tuple(version)
return version_tuple(dot_version) < version_tuple(version)


def __migrate_older_to_0_2_7(dot_rethink: Dict, data_path: Path):
Expand All @@ -28,6 +29,16 @@ def __migrate_older_to_0_2_7(dot_rethink: Dict, data_path: Path):
"""
v = "0.2.7"
dot_rethink["version"] = v
if "settings" not in dot_rethink:
dot_rethink["settings"] = {
"language": const.Language.EN.value,
"theme": const.AppTheme.LIGHT.value,
"editorMode": const.EditorMode.WYSIWYG.value,
"editorFontSize": 15,
"editorCodeTheme": const.EditorCodeTheme.GITHUB.value,
"editorSepRightWidth": 200,
"editorSideCurrentToolId": "",
}
__renew_dot_rethink(dot_rethink, data_path)
logger.debug(f"Migrate the database to version {v}")

Expand Down
3 changes: 2 additions & 1 deletion tests/test_version_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def tearDown(self) -> None:
# remove all files and dirs
shutil.rmtree(self.tmp_dir, ignore_errors=True)

def test_less_than_0_2_4(self):
def test_merge_to_0_2_7(self):
dot_rethink = {
"_id": "65658d61dc7f58455d9b38b6",
"id": "a" * 22,
Expand All @@ -69,3 +69,4 @@ def test_less_than_0_2_4(self):
v = version_manager.recover.load_dot_rethink(self.tmp_dir / ".data" / ".rethink.json")
# self.assertEqual(__version__, v["version"])
self.assertGreater(len(v["version"]), 0)
self.assertIn("settings", v)

0 comments on commit 76a7d64

Please sign in to comment.