Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove old API migrations #4168

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion api_app/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.20.2"
__version__ = "0.20.4"
53 changes: 2 additions & 51 deletions api_app/api/routes/migrations.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from db.migrations.shared_services import SharedServiceMigration
from db.migrations.workspaces import WorkspaceMigration
from db.repositories.resources import ResourceRepository
from models.schemas.migrations import MigrationOutList, Migration
from models.schemas.migrations import MigrationOutList
from services.logging import logger

migrations_core_router = APIRouter(dependencies=[Depends(get_current_admin_user)])
Expand All @@ -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.

Loading