Skip to content

Avoid always triggering migration code on SqliteZip initialisation #6961

@GeigerJ2

Description

@GeigerJ2

Because of this code:

@classmethod
def initialise(cls, profile: 'Profile', reset: bool = False) -> bool:
"""Initialise an instance of the ``SqliteZipBackend`` storage backend.
:param reset: If ``true``, destroy the backend if it already exists including all of its data before recreating
and initialising it. This is useful for example for test profiles that need to be reset before or after
tests having run.
:returns: ``True`` if the storage was initialised by the function call, ``False`` if it was already initialised.
"""
validate_sqlite_version()
from archive_path import ZipPath
filepath_archive = Path(profile.storage_config['filepath'])
if filepath_archive.exists() and not reset:
from .migrator import migrate
# The archive exists but ``reset == False``, so we try to migrate to the latest schema version. If the
# migration works, we replace the original archive with the migrated one.
with tempfile.TemporaryDirectory() as dirpath:
filepath_migrated = Path(dirpath) / 'migrated.zip'
LOGGER.report(f'Migrating existing {cls.__name__}')
migrate(filepath_archive, filepath_migrated, cls.version_head())
shutil.move(filepath_migrated, filepath_archive) # type: ignore[arg-type]
return False

the migrate function is always called, even if the archive version is recent and wouldn't require migration.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions