From 83fcf1bb60ac33f40b670cce09dca886cbcb3944 Mon Sep 17 00:00:00 2001 From: Andy Bayer Roswell Date: Sun, 8 Dec 2024 16:07:49 +0100 Subject: [PATCH] added some handy scripts to export cells from psql pod in legacy db schema [used in tinydb] --- .../commands/export-from-psql-pod-in-legacy-db-schema.ps1 | 8 +++++++- .../management/commands/export_in_legacy_db_schema.py | 3 +++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/vreapis/catalog/management/commands/export-from-psql-pod-in-legacy-db-schema.ps1 b/vreapis/catalog/management/commands/export-from-psql-pod-in-legacy-db-schema.ps1 index 5898b2f..c73bff4 100644 --- a/vreapis/catalog/management/commands/export-from-psql-pod-in-legacy-db-schema.ps1 +++ b/vreapis/catalog/management/commands/export-from-psql-pod-in-legacy-db-schema.ps1 @@ -1,3 +1,5 @@ +$cwd = $PWD + $project_root = Resolve-Path "$PSScriptRoot/../../.." $vreapi_pod_inf = kubectl get pod | sls '^vrepaas-vreapi-\w+-\w+' @@ -19,6 +21,10 @@ $var[$off_DB_PASSWORD] = "export DB_PASSWORD=vrepaas" $var > /tmp/export_VARS kubectl cp /tmp/export_VARS "${vreapi_pod_name}:/tmp" kubectl cp "$PSScriptRoot/export-from-psql-pod-in-legacy-db-schema.sh" "${vreapi_pod_name}:/tmp" + +kubectl cp ~/NaaVRE/NaaVRE_db.json "${vreapi_pod_name}:/app" kubectl exec -it $vreapi_pod_name -- bash "/tmp/export-from-psql-pod-in-legacy-db-schema.sh" -kubectl cp "${vreapi_pod_name}:/app/NaaVRE_db.json" $project_root/NaaVRE_db.json +kubectl cp "${vreapi_pod_name}:/app/NaaVRE_db.json" ~/NaaVRE/NaaVRE_db.json + +cd $cwd diff --git a/vreapis/catalog/management/commands/export_in_legacy_db_schema.py b/vreapis/catalog/management/commands/export_in_legacy_db_schema.py index 63b7b52..baa98ec 100644 --- a/vreapis/catalog/management/commands/export_in_legacy_db_schema.py +++ b/vreapis/catalog/management/commands/export_in_legacy_db_schema.py @@ -21,11 +21,14 @@ def handle(self, *args, **options): match table: case 'Cell': queryset: QuerySet = Cell.objects.all() + print(f'Cell count: {queryset.count()}') no: int = 1 cells: dict[str, dict] = {} for cell in queryset: serializer = CellSerializer(cell) + print(f'task_name: {cell.task_name}') cells[str(no)] = serializer.data + no += 1 db_file: str = f'{common.project_root}/NaaVRE_db.json' with open(db_file) as f: db = json.load(f)