Migration from older profile version
closes #403
Merge request reports
Activity
added Review Topic::CLI Topic::TUI labels
assigned to @msobczyk
added 12 commits
- 75ed4d45...7b992ff8 - 2 earlier commits
- 03a71155 - Get rid of clive.__private.core.date_utils dependency in storage
- 269c7aed - Include alarms model in calculating storage revision
- 82ebe211 - Use transaction from schemas as model to store transaction in profile
- f11c278c - Reimport and use new models instead of old storage models
- 1769c219 - Detect multiple storage versions in PersistentStorageService
- ce0aa581 - Fix unit tests after storage revision change
- 450342a2 - New unit tests for detecting multiple storage versions
- f1b64287 - Introduce enum for storage version
- 14cb090d - New cli tests with loading old profile and migration
- bacab5f9 - Additional unit tests for profile with alarms or operations stored
Toggle commit listadded 15 commits
- bacab5f9...885fbabc - 5 earlier commits
- 8f470313 - Reimport and use new models instead of old storage models
- 8e872d3a - Show also storage model version number in cli command clive --version
- 01b9d8e8 - Detect multiple storage versions in PersistentStorageService
- 5ed5a650 - Add --force flag to configure profile remove required to delete multiple storage versions
- c6da9503 - Fix unit test for storage revision change
- 8775f931 - New unit tests for migration, listing and deleting multiple storage versions
- c1001a81 - New cli tests for handling older storage versions
- 9fb4de51 - Introduce new storage version with additional tui_theme field in profile
- 8ced1542 - Fix unit tests for storage revision
- 08eac5a9 - Save and load tui theme from storage in profile
Toggle commit list16 16 from clive.__private.core.commands.save_profile import SaveProfile 17 17 from clive.__private.core.formatters.humanize import humanize_validation_result 18 18 from clive.__private.core.profile import Profile 19 from clive.__private.storage.service import MultipleProfileVersionsError 19 20 from clive.__private.validators.profile_name_validator import ProfileNameValidator 20 21 from clive.__private.validators.set_password_validator import SetPasswordValidator 21 22 from clive.dev import is_in_dev_mode 22 23 23 24 25 class CLIMultipleProfileVersionsError(CLIPrettyError): 26 def __init__(self, profile_name: str) -> None: 27 message = ( 28 f"Multiple versions or backups of profile `{profile_name}` exist." 29 " If you want to remove all version and backups, use '--force' option." - Comment on lines +28 to +29
28 f"Multiple versions or backups of profile `{profile_name}` exist." 29 " If you want to remove all version and backups, use '--force' option." 28 f"Multiple versions or backups of the `{profile_name}` profile exist." 29 " If you want to remove all the versions and backups, please use the '--force' option."
I think saving theme doesn't work correctly when it's not changed for the first time after unlock:
- change theme on unlock to eg textual-light
- unlock (the same theme textual-light will be set)
- lock
- change theme to e.g gruvbox
- unlock (the same theme gruvbox will be set)
This means if someone won't set theme after unlock - he can see different theme if someone else changes it on the Unlock screen
Looks like there is a missing
_update_theme_in_profile
after unlock?
64 64 transaction_file_path: Path | None = None, 65 65 chain_id: str | None = None, 66 66 node_address: str | HttpUrl | None = None, 67 tui_theme: str | None = None, 515 516 for worker in self.workers: 516 517 if worker != current_worker: 517 518 worker.cancel() 519 520 def _update_theme_in_profile(self) -> None: 6 TrackedAccountStorageModel, 7 ) 8 from clive.__private.storage.migrations.v2 import TransactionStorageModel 9 from clive.__private.storage.migrations.v3 import ( 10 ProfileStorageModel, 11 ProfileStorageModelSchema, 12 calculate_storage_model_revision, 13 get_storage_model_schema_json, 14 ) 15 from clive.__private.storage.migrations.version import Version 16 17 __all__ = [ 18 "AlarmStorageModel", 19 "KeyAliasStorageModel", 20 "ProfileStorageModel", 21 "ProfileStorageModelSchema", I think it would be much easier to maintain the storage if we'll have something simialr to https://docs.pydantic.dev/latest/api/json_schema/#pydantic.json_schema.SkipJsonSchema instead of defining new class structure for calculating the storage revision
- clive/__private/storage/migrations/v2.py 0 → 100644
1 from __future__ import annotations Maybe it would be cleaner to define additional schemas under main namespace like: (But wait with that for later, we'll see what it looks like if other threads are resolved)
from __future__ import annotations from pathlib import Path from typing import Any from pydantic import BaseModel class ProfileStorageModel(BaseModel): class TransactionStorageModel(BaseModel): transaction: Any transaction_file_path: Path name: str transaction: ProfileStorageModel.TransactionStorageModel class NewerProfileStorageModel(ProfileStorageModel): name: int class NewestProfileStorageModel(NewerProfileStorageModel): class TransactionStorageModel(NewerProfileStorageModel.TransactionStorageModel): additional: str name: str transaction: NewestProfileStorageModel.TransactionStorageModel | None = None print(ProfileStorageModel.schema_json(indent=4)) print("newer:") print(NewerProfileStorageModel.schema_json(indent=4)) print("newest:") print(NewestProfileStorageModel.schema_json(indent=4))
- clive/__private/storage/migrations/v2.py 0 → 100644
19 20 21 class TransactionStorageModelSchema(TransactionStorageModel): 22 schemas_transaction: Any 23 24 25 class ProfileStorageModelSchema(ProfileStorageModel): 26 transaction: TransactionStorageModelSchema 27 28 29 def get_storage_model_schema_json() -> str: 30 return ProfileStorageModelSchema.schema_json(indent=4) 31 32 33 def calculate_storage_model_revision() -> str: 34 return sha256(get_storage_model_schema_json().encode()).hexdigest()[:8] 1 from __future__ import annotations 2 3 from enum import Enum 4 5 FIRST_REVISION = "c600278a" 6 7 8 class Version(Enum): 5 6 from clive.__private.models.schemas import Transaction 7 from clive.__private.storage.migrations import current, v1, v2, v3 8 from clive.__private.storage.migrations.version import Version 9 from clive.exceptions import CliveError 10 11 12 class CannotUpgradeStorageModelVersionError(CliveError): 13 """Raise when trying to upgrade unknown storage model version to current version.""" 14 15 16 class CannotParseStorageModelVersionError(CliveError): 17 """Raise when trying to parse unknown storage model version.""" 18 19 20 AllProfileStorageModels: TypeAlias = v1.ProfileStorageModel | v2.ProfileStorageModel 8 from clive.__private.storage.migrations.version import Version 9 from clive.exceptions import CliveError 10 11 12 class CannotUpgradeStorageModelVersionError(CliveError): 13 """Raise when trying to upgrade unknown storage model version to current version.""" 14 15 16 class CannotParseStorageModelVersionError(CliveError): 17 """Raise when trying to parse unknown storage model version.""" 18 19 20 AllProfileStorageModels: TypeAlias = v1.ProfileStorageModel | v2.ProfileStorageModel 21 22 23 def upgrade_storage_model(model: AllProfileStorageModels) -> current.ProfileStorageModel: