Skip to content
Merged
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
17 changes: 17 additions & 0 deletions api-rework/client/src/activities/detail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,17 @@ const ActivitiesDetail: React.FC = () => {
});
}, [id, serial]);

const rerunImport = () => {
fetch(`${API_URL}/activities/${id}/migrate`, {
method: 'POST',
headers: {
Authorization: `Bearer ${auth.token}`
}
}).then(() => {
setSerial(serial + 1);
});
};

if (loading) {
return <Spinner />;
}
Expand Down Expand Up @@ -169,6 +180,12 @@ const ActivitiesDetail: React.FC = () => {
/>
</div>
<div className={`${tab === 'migration' ? 'active' : 'inactive'} tab`}>
<button
onClick={() => {
rerunImport();
}}>
Rerun Import
</button>
<JSONViewer
data={migrationStatus}
diffCandidates={[]}
Expand Down
3 changes: 2 additions & 1 deletion api-rework/client/src/client.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ const Client: React.FC = () => {
draft.user_details = {
identity_provider: keycloakInstance.idTokenParsed.identity_provider,
family_name: keycloakInstance.idTokenParsed.family_name,
given_name: keycloakInstance.idTokenParsed.given_name
given_name: keycloakInstance.idTokenParsed.given_name,
sub: keycloakInstance.idTokenParsed.sub || 'unknown'
};
}
});
Expand Down
2 changes: 1 addition & 1 deletion api-rework/invasives/api/legacy_db/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ def migrate_codes(dry_run=False):
def migrate_activities(
dry_run=False,
clobber=False,
source: Literal["all", "previously-failed", "random-sample", "list"] = "all",
source: Literal["all", "previously-failed", "random-sample", "single"] = "all",
restrict_to_subtype: str | None = None,
pk=None,
):
Expand Down
13 changes: 13 additions & 0 deletions api-rework/invasives/api/viewsets/activity.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import json
import logging

from django.http.response import HttpResponse
import psycopg
Expand All @@ -9,6 +10,7 @@
from rest_framework.status import HTTP_200_OK
from rest_framework.viewsets import ReadOnlyModelViewSet

from api.legacy_db.db import LegacyDB
from api.legacy_db.model_serializer import LegacyActivity
from api.models.activity.activity import Activity
from api.models.migrator.activity_migration_status import ActivityMigrationStatus
Expand All @@ -35,6 +37,17 @@ def migration_status(self, request, *args, **kwargs):
except:
return Response(status=404)

@action(detail=True, methods=["post"])
def migrate(self, request, *args, **kwargs):
try:
LegacyDB.migrate_activities(
source="single", dry_run=False, clobber=True, pk=self.kwargs["pk"]
)
return Response(status=HTTP_200_OK)
except Exception as e:
logging.error("error migrating activity", exc_info=True)
return Response(status=500)

@action(detail=True, methods=["get"])
def legacy(self, request, *args, **kwargs):
with psycopg.connect(LEGACY_DB_CONNECTION_STRING, row_factory=dict_row) as conn:
Expand Down
Loading