Skip to content
Snippets Groups Projects

Migration from older profile version

Open Marcin Sobczyk requested to merge msobczyk/403-migration-better-storage into develop

closes #403

Merge request reports

Loading
Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
46 46 )
47 47
48 48
49 49 @profile.command(name="remove")
  • 16 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
      Suggested change
      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."
    • Please register or sign in to reply
    • 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?

  • Mateusz Żebrak
    Mateusz Żebrak @mzebrak started a thread on commit d30b3136
  • 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,
    • I wonder if it will be better to have this only as str and the default should be DEFAULT_THEME? like from textual.constants or we should have our own CLIVE_DEFAULT_THEME defined in settings.toml

    • Please register or sign in to reply
  • Mateusz Żebrak
    Mateusz Żebrak @mzebrak started a thread on commit d30b3136
  • 128 128 return
    129 129
    130 130 await self.app._switch_mode_into_unlocked()
    131 if self.profile.tui_theme is not None:
    132 self.app.theme = self.profile.tui_theme
  • Mateusz Żebrak
    Mateusz Żebrak @mzebrak started a thread on commit d30b3136
  • 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",
  • 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))
    • Please register or sign in to reply
  • 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):
  • 1 from __future__ import annotations
    2
    3 from enum import Enum
    4
    5 FIRST_REVISION = "c600278a"
  • 1 from __future__ import annotations
    2
    3 from enum import Enum
    4
    5 FIRST_REVISION = "c600278a"
    6
    7
    8 class Version(Enum):
    • Why do we need this Enum at all and additional V1, V2 etc while we have revision hash? To compare revisions? Looks like this can be done e.g. based on the list index like greater the index - the newer the revision

    • Please register or sign in to reply
  • 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
    • This does not include v3 but works fine and mypy is not complying. Maybe no need for that? Less places to edit while adding a new version. How many places now should be edited to add a new version? Maybe can you provide some instruction in docstring?

    • Please register or sign in to reply
  • 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:
    • So every migration (data conversion) will be placed there? This will become very overcomplicated pretty soon.. Maybe we should have methods like def upgrade defined at the ProfileStorageModel level? or something like upgrade_v1_to_v2 but not everything stored in a single function.

    • Please register or sign in to reply
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Please register or sign in to reply
    Loading