Skip to content

Commit

Permalink
Migration for stepId in OperationSteps (#3358)
Browse files Browse the repository at this point in the history
* add migration for operationStep

* update PR name
  • Loading branch information
yuvalyaron authored Mar 27, 2023
1 parent 8b8ca36 commit 068d620
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<!-- markdownlint-disable MD041 -->
## 0.10.0 (Unreleased)
**BREAKING CHANGES & MIGRATIONS**:
A migration for OperationSteps in Operation objects was added ([#3358](https://github.com/microsoft/AzureTRE/pull/3358)).

FEATURES:

Expand Down
2 changes: 1 addition & 1 deletion api_app/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.13.3"
__version__ = "0.13.4"
4 changes: 4 additions & 0 deletions api_app/api/routes/migrations.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ async def migrate_database(resources_repo=Depends(get_repository(ResourceReposit
num_updated = await airlock_migration.update_review_decision_values()
migrations.append(Migration(issueNumber="3152", status=f'Updated {num_updated} airlock requests with new reviewDecision value'))

logging.info("PR 3358 - Migrate OperationSteps of Operations")
num_updated = await resource_migration.migrate_step_id_of_operation_steps(operations_repo)
migrations.append(Migration(issueNumber="3358", status=f'Updated {num_updated} operations'))

return MigrationOutList(migrations=migrations)
except Exception as e:
logging.exception("Failed to migrate database")
Expand Down
13 changes: 13 additions & 0 deletions api_app/db/migrations/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,16 @@ async def archive_history(self, resource_history_repository: ResourceHistoryRepo
num_updated = num_updated + 1

return num_updated

async def migrate_step_id_of_operation_steps(self, operations_repository: OperationRepository) -> int:
num_updated = 0
for operation in await operations_repository.query("SELECT * from c WHERE ARRAY_LENGTH(c.steps) > 0 AND IS_DEFINED(c.steps[0].stepId)"):
for operation_step in operation['steps']:
operation_step['templateStepId'] = operation_step['stepId']
operation_step['id'] = str(uuid.uuid4())
del operation_step['stepId']

await operations_repository.update_item_dict(operation)
num_updated = num_updated + 1

return num_updated
5 changes: 4 additions & 1 deletion api_app/tests_ma/test_api/test_routes/test_migrations.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ def _prepare(self, app, admin_user):
@ patch("api.routes.migrations.AirlockMigration.rename_field_name")
@ patch("api.routes.migrations.AirlockMigration.change_review_resources_to_dict")
@ patch("api.routes.migrations.AirlockMigration.update_review_decision_values")
async def test_post_migrations_returns_202_on_successful(self, update_review_decision_values, change_review_resources_to_dict, airlock_rename_field, add_created_by_and_rename_in_history,
@ patch("api.routes.migrations.ResourceMigration.migrate_step_id_of_operation_steps")
async def test_post_migrations_returns_202_on_successful(self, migrate_step_id_of_operation_steps, update_review_decision_values,
change_review_resources_to_dict, airlock_rename_field, add_created_by_and_rename_in_history,
check_min_firewall_version, workspace_migration, shared_services_migration,
rename_field, add_deployment_field, archive_history, _, logging, client, app):
response = await client.post(app.url_path_for(strings.API_MIGRATE_DATABASE))
Expand All @@ -59,6 +61,7 @@ async def test_post_migrations_returns_202_on_successful(self, update_review_dec
airlock_rename_field.assert_called()
change_review_resources_to_dict.assert_called_once()
update_review_decision_values.assert_called_once()
migrate_step_id_of_operation_steps.assert_called_once()
archive_history.assert_called_once()
logging.assert_called()
assert response.status_code == status.HTTP_202_ACCEPTED
Expand Down

0 comments on commit 068d620

Please sign in to comment.