Skip to content

Commit

Permalink
Remove old API migrations
Browse files Browse the repository at this point in the history
Fixes #4079

Remove deprecated migration steps from the `migrate_database` function in `api_app/api/routes/migrations.py`.

* **Migration Steps Removal**
  - Remove multiple deprecated migration steps from the `migrate_database` function.
  - Update the `migrate_database` function to only include necessary migration steps.
* **Version Update**
  - Update the version in `api_app/_version.py` from "0.19.3" to "0.20.0".
* **Test Updates**
  - Remove tests related to deprecated migration steps in `api_app/tests_ma/test_api/test_routes/test_migrations.py`.
  - Update tests to only include necessary migration steps.
* **File Deletions**
  - Delete `api_app/db/migrations/airlock.py`.
  - Delete `api_app/db/migrations/resources.py`.
  - Delete `api_app/db/migrations/shared_services.py`.
  - Delete `api_app/db/migrations/workspaces.py`.
  - Delete `api_app/tests_ma/test_db/test_migrations/test_workspace_migration.py`.

---

For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/microsoft/AzureTRE/issues/4079?shareId=XXXX-XXXX-XXXX-XXXX).
  • Loading branch information
marrobi committed Dec 5, 2024
1 parent b67018f commit 348be18
Show file tree
Hide file tree
Showing 8 changed files with 5 additions and 357 deletions.
2 changes: 1 addition & 1 deletion api_app/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.19.3"
__version__ = "0.20.0"
53 changes: 2 additions & 51 deletions api_app/api/routes/migrations.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,57 +29,8 @@ async def migrate_database(resources_repo=Depends(get_repository(ResourceReposit
airlock_migration=Depends(get_repository(AirlockMigration)),):
try:
migrations = list()
logger.info("PR 1030")
await resources_repo.rename_field_name('resourceTemplateName', 'templateName')
await resources_repo.rename_field_name('resourceTemplateVersion', 'templateVersion')
await resources_repo.rename_field_name('resourceTemplateParameters', 'properties')
migrations.append(Migration(issueNumber="PR 1030", status="Executed"))

logger.info("PR 1031")
await resources_repo.rename_field_name('workspaceType', 'templateName')
await resources_repo.rename_field_name('workspaceServiceType', 'templateName')
await resources_repo.rename_field_name('userResourceType', 'templateName')
migrations.append(Migration(issueNumber="PR 1031", status="Executed"))

logger.info("PR 1717 - Shared services")
migration_status = "Executed" if await shared_services_migration.deleteDuplicatedSharedServices() else "Skipped"
migrations.append(Migration(issueNumber="PR 1717", status=migration_status))

logger.info("PR 1726 - Authentication needs to be in properties so we can update them")
migration_status = "Executed" if await workspace_migration.moveAuthInformationToProperties() else "Skipped"
migrations.append(Migration(issueNumber="PR 1726", status=migration_status))

logger.info("PR 1406 - Extra field to support UI")
num_rows = await resource_migration.add_deployment_status_field(operations_repo)
migrations.append(Migration(issueNumber="1406", status=f'Updated {num_rows} resource objects'))

logger.info("PR 3066 - Archive resources history")
num_rows = await resource_migration.archive_history(resource_history_repo)
migrations.append(Migration(issueNumber="3066", status=f'Updated {num_rows} resource objects'))

logger.info("PR 2371 - Validate min firewall version")
await shared_services_migration.checkMinFirewallVersion()
migrations.append(Migration(issueNumber="2371", status='Firewall version meets requirement'))

logger.info("PR 2779 - Restructure Airlock requests & add createdBy field")
await airlock_migration.rename_field_name('requestType', 'type')
await airlock_migration.rename_field_name('requestTitle', 'title')
await airlock_migration.rename_field_name('user', 'updatedBy')
await airlock_migration.rename_field_name('creationTime', 'createdWhen')
num_updated = await airlock_migration.add_created_by_and_rename_in_history()
migrations.append(Migration(issueNumber="2779", status=f'Renamed fields & updated {num_updated} airlock requests with createdBy'))

logger.info("PR 2883 - Support multiple reviewer VMs per Airlock request")
num_updated = await airlock_migration.change_review_resources_to_dict()
migrations.append(Migration(issueNumber="2883", status=f'Updated {num_updated} airlock requests with new reviewUserResources format'))

logger.info("PR 3152 - Migrate reviewDecision of Airlock Reviews")
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'))

logger.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'))

# ADD MIGRATIONS HERE

return MigrationOutList(migrations=migrations)
except Exception as e:
Expand Down
77 changes: 0 additions & 77 deletions api_app/db/migrations/airlock.py

This file was deleted.

54 changes: 0 additions & 54 deletions api_app/db/migrations/resources.py

This file was deleted.

48 changes: 0 additions & 48 deletions api_app/db/migrations/shared_services.py

This file was deleted.

48 changes: 0 additions & 48 deletions api_app/db/migrations/workspaces.py

This file was deleted.

33 changes: 2 additions & 31 deletions api_app/tests_ma/test_api/test_routes/test_migrations.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,44 +35,15 @@ def _prepare(self, app, admin_user):
# [POST] /migrations/
@ patch("api.routes.migrations.logger.info")
@ patch("api.routes.migrations.OperationRepository")
@ patch("api.routes.migrations.ResourceMigration.archive_history")
@ patch("api.routes.migrations.ResourceMigration.add_deployment_status_field")
@ patch("api.routes.migrations.ResourceRepository.rename_field_name")
@ patch("api.routes.migrations.SharedServiceMigration.deleteDuplicatedSharedServices")
@ patch("api.routes.migrations.WorkspaceMigration.moveAuthInformationToProperties")
@ patch("api.routes.migrations.SharedServiceMigration.checkMinFirewallVersion")
@ patch("api.routes.migrations.AirlockMigration.add_created_by_and_rename_in_history")
@ 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")
@ 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):
async def test_post_migrations_returns_202_on_successful(self, _, logging, client, app):
response = await client.post(app.url_path_for(strings.API_MIGRATE_DATABASE))

check_min_firewall_version.assert_called_once()
shared_services_migration.assert_called_once()
workspace_migration.assert_called_once()
rename_field.assert_called()
add_deployment_field.assert_called()
add_created_by_and_rename_in_history.assert_called_once()
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

# [POST] /migrations/
@ patch("api.routes.migrations.logger.info")
@ patch("api.routes.migrations.ResourceRepository.rename_field_name", side_effect=ValueError)
@ patch("api.routes.migrations.SharedServiceMigration.deleteDuplicatedSharedServices")
@ patch("api.routes.migrations.WorkspaceMigration.moveAuthInformationToProperties")
@ patch("api.routes.migrations.AirlockMigration.add_created_by_and_rename_in_history")
async def test_post_migrations_returns_400_if_template_does_not_exist(self, workspace_migration, shared_services_migration,
resources_repo, airlock_migration, logging, client, app):
async def test_post_migrations_returns_400_if_template_does_not_exist(self, resources_repo, logging, client, app):
response = await client.post(app.url_path_for(strings.API_MIGRATE_DATABASE))
assert response.status_code == status.HTTP_400_BAD_REQUEST

This file was deleted.

0 comments on commit 348be18

Please sign in to comment.