Skip to content

Commit

Permalink
persistence directory migrations v4 for new deck configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
CaseyBatten committed Mar 21, 2024
1 parent 28fd16e commit 4ebcade
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
24 changes: 24 additions & 0 deletions robot-server/robot_server/persistence/_migrations/v3_to_v4.py
Original file line number Diff line number Diff line change
@@ -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)
Original file line number Diff line number Diff line change
Expand Up @@ -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-"
Expand Down Expand Up @@ -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-",
)

Expand Down

0 comments on commit 4ebcade

Please sign in to comment.