-
Notifications
You must be signed in to change notification settings - Fork 178
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(robot-server): maintain correct order of protocol analyses (#14762)
Closes AUTH-229 # Overview Updates the `/protocols` endpoints to always maintain the order of list of analyses as most-recently-started-analysis last, making sure to verify if a new analysis needs to be triggered because of new run-time-parameter values for a previously uploaded protocol. # Risk assessment Medium. Does database update and fixes the analysis order that was broken by #14688 --------- Co-authored-by: Max Marrone <[email protected]>
- Loading branch information
1 parent
c264cd3
commit 1537e73
Showing
19 changed files
with
1,331 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
robot-server/robot_server/persistence/_migrations/v3_to_v4.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
"""Migrate the persistence directory from schema 3 to 4. | ||
Summary of changes from schema 3: | ||
- Adds a new "run_time_parameter_values_and_defaults" column to analysis table | ||
""" | ||
|
||
from pathlib import Path | ||
from contextlib import ExitStack | ||
import shutil | ||
from typing import Any | ||
|
||
import sqlalchemy | ||
|
||
from ..database import sql_engine_ctx | ||
from ..tables import schema_4 | ||
from .._folder_migrator import Migration | ||
|
||
_DB_FILE = "robot_server.db" | ||
|
||
|
||
class Migration3to4(Migration): # noqa: D101 | ||
def migrate(self, source_dir: Path, dest_dir: Path) -> None: | ||
"""Migrate the persistence directory from schema 3 to 4.""" | ||
# Copy over all existing directories and files to new version | ||
for item in source_dir.iterdir(): | ||
if item.is_dir(): | ||
shutil.copytree(src=item, dst=dest_dir / item.name) | ||
else: | ||
shutil.copy(src=item, dst=dest_dir / item.name) | ||
dest_db_file = dest_dir / _DB_FILE | ||
|
||
# Append the new column to existing analyses in v4 database | ||
with ExitStack() as exit_stack: | ||
dest_engine = exit_stack.enter_context(sql_engine_ctx(dest_db_file)) | ||
schema_4.metadata.create_all(dest_engine) | ||
|
||
def add_column( | ||
engine: sqlalchemy.engine.Engine, | ||
table_name: str, | ||
column: Any, | ||
) -> None: | ||
column_type = column.type.compile(engine.dialect) | ||
engine.execute( | ||
f"ALTER TABLE {table_name} ADD COLUMN {column.key} {column_type}" | ||
) | ||
|
||
add_column( | ||
dest_engine, | ||
schema_4.analysis_table.name, | ||
schema_4.analysis_table.c.run_time_parameter_values_and_defaults, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
130 changes: 130 additions & 0 deletions
130
robot-server/robot_server/persistence/tables/schema_4.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
"""v4 of our SQLite schema.""" | ||
|
||
import sqlalchemy | ||
|
||
from robot_server.persistence._utc_datetime import UTCDateTime | ||
|
||
metadata = sqlalchemy.MetaData() | ||
|
||
protocol_table = sqlalchemy.Table( | ||
"protocol", | ||
metadata, | ||
sqlalchemy.Column( | ||
"id", | ||
sqlalchemy.String, | ||
primary_key=True, | ||
), | ||
sqlalchemy.Column( | ||
"created_at", | ||
UTCDateTime, | ||
nullable=False, | ||
), | ||
sqlalchemy.Column("protocol_key", sqlalchemy.String, nullable=True), | ||
) | ||
|
||
analysis_table = sqlalchemy.Table( | ||
"analysis", | ||
metadata, | ||
sqlalchemy.Column( | ||
"id", | ||
sqlalchemy.String, | ||
primary_key=True, | ||
), | ||
sqlalchemy.Column( | ||
"protocol_id", | ||
sqlalchemy.String, | ||
sqlalchemy.ForeignKey("protocol.id"), | ||
index=True, | ||
nullable=False, | ||
), | ||
sqlalchemy.Column( | ||
"analyzer_version", | ||
sqlalchemy.String, | ||
nullable=False, | ||
), | ||
sqlalchemy.Column( | ||
"completed_analysis", | ||
# Stores a JSON string. See CompletedAnalysisStore. | ||
sqlalchemy.String, | ||
nullable=False, | ||
), | ||
# column added in schema v4 | ||
sqlalchemy.Column( | ||
"run_time_parameter_values_and_defaults", | ||
sqlalchemy.String, | ||
nullable=True, | ||
), | ||
) | ||
|
||
run_table = sqlalchemy.Table( | ||
"run", | ||
metadata, | ||
sqlalchemy.Column( | ||
"id", | ||
sqlalchemy.String, | ||
primary_key=True, | ||
), | ||
sqlalchemy.Column( | ||
"created_at", | ||
UTCDateTime, | ||
nullable=False, | ||
), | ||
sqlalchemy.Column( | ||
"protocol_id", | ||
sqlalchemy.String, | ||
sqlalchemy.ForeignKey("protocol.id"), | ||
nullable=True, | ||
), | ||
# column added in schema v1 | ||
sqlalchemy.Column( | ||
"state_summary", | ||
sqlalchemy.String, | ||
nullable=True, | ||
), | ||
# column added in schema v1 | ||
sqlalchemy.Column("engine_status", sqlalchemy.String, nullable=True), | ||
# column added in schema v1 | ||
sqlalchemy.Column("_updated_at", UTCDateTime, nullable=True), | ||
) | ||
|
||
action_table = sqlalchemy.Table( | ||
"action", | ||
metadata, | ||
sqlalchemy.Column( | ||
"id", | ||
sqlalchemy.String, | ||
primary_key=True, | ||
), | ||
sqlalchemy.Column("created_at", UTCDateTime, nullable=False), | ||
sqlalchemy.Column("action_type", sqlalchemy.String, nullable=False), | ||
sqlalchemy.Column( | ||
"run_id", | ||
sqlalchemy.String, | ||
sqlalchemy.ForeignKey("run.id"), | ||
nullable=False, | ||
), | ||
) | ||
|
||
run_command_table = sqlalchemy.Table( | ||
"run_command", | ||
metadata, | ||
sqlalchemy.Column("row_id", sqlalchemy.Integer, primary_key=True), | ||
sqlalchemy.Column( | ||
"run_id", sqlalchemy.String, sqlalchemy.ForeignKey("run.id"), nullable=False | ||
), | ||
sqlalchemy.Column("index_in_run", sqlalchemy.Integer, nullable=False), | ||
sqlalchemy.Column("command_id", sqlalchemy.String, nullable=False), | ||
sqlalchemy.Column("command", sqlalchemy.String, nullable=False), | ||
sqlalchemy.Index( | ||
"ix_run_run_id_command_id", # An arbitrary name for the index. | ||
"run_id", | ||
"command_id", | ||
unique=True, | ||
), | ||
sqlalchemy.Index( | ||
"ix_run_run_id_index_in_run", # An arbitrary name for the index. | ||
"run_id", | ||
"index_in_run", | ||
unique=True, | ||
), | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.