From 4ebcade9baca079ff9c1b8368320e9b727762756 Mon Sep 17 00:00:00 2001 From: CaseyBatten Date: Thu, 21 Mar 2024 16:34:13 -0400 Subject: [PATCH] persistence directory migrations v4 for new deck configuration --- .../persistence/_migrations/v3_to_v4.py | 24 +++++++++++++++++++ .../persistence/persistence_directory.py | 7 ++++-- 2 files changed, 29 insertions(+), 2 deletions(-) create mode 100644 robot-server/robot_server/persistence/_migrations/v3_to_v4.py diff --git a/robot-server/robot_server/persistence/_migrations/v3_to_v4.py b/robot-server/robot_server/persistence/_migrations/v3_to_v4.py new file mode 100644 index 00000000000..0f5cc0004cb --- /dev/null +++ b/robot-server/robot_server/persistence/_migrations/v3_to_v4.py @@ -0,0 +1,24 @@ +"""Migrate the persistence directory from schema 3 to 4. + +Summary of changes from schema 3: + +- Deck Configuration now Supports the addition of Modules as Fixtures +- Fixture items within the configuration have an optional Serial Number field +- NOTE: Database has not changed, maintains form from v3 of SQLite schema +- NOTE: Schema 3 is forward compatible with schema 4, so migration is a simple directory copy action + +""" + +from pathlib import Path +import shutil +from .._folder_migrator import Migration + + +class Migration3To4(Migration): # noqa: D101 + def migrate(self, source_dir: Path, dest_dir: Path) -> None: + """Migrate the persistence directory from schema 3 to 4.""" + for item in source_dir.iterdir(): + if item.is_dir(): + shutil.copytree(src=item, dst=dest_dir) + else: + shutil.copy(src=item, dst=dest_dir) diff --git a/robot-server/robot_server/persistence/persistence_directory.py b/robot-server/robot_server/persistence/persistence_directory.py index 666d5c7998f..9dd167f5752 100644 --- a/robot-server/robot_server/persistence/persistence_directory.py +++ b/robot-server/robot_server/persistence/persistence_directory.py @@ -11,7 +11,7 @@ from anyio import Path as AsyncPath, to_thread from ._folder_migrator import MigrationOrchestrator -from ._migrations import up_to_3 +from ._migrations import up_to_3, v3_to_v4 _TEMP_PERSISTENCE_DIR_PREFIX: Final = "opentrons-robot-server-" @@ -48,7 +48,10 @@ async def prepare_active_subdirectory(prepared_root: Path) -> Path: """Return the active persistence subdirectory after preparing it, if necessary.""" migration_orchestrator = MigrationOrchestrator( root=prepared_root, - migrations=[up_to_3.MigrationUpTo3(subdirectory="3")], + migrations=[ + up_to_3.MigrationUpTo3(subdirectory="3"), + v3_to_v4.Migration3To4(subdirectory="4"), + ], temp_file_prefix="temp-", )