Skip to content

Commit

Permalink
adding support for export in legacy db schema [for the old tinydb]
Browse files Browse the repository at this point in the history
  • Loading branch information
AndyBRoswell committed Dec 5, 2024
1 parent b373e4a commit 4ab0e59
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions vreapis/catalog/management/commands/export_in_legacy_db_schema.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
import json
import os.path

from django.core.management import CommandParser
from django.core.management.base import BaseCommand, CommandError
from django.db.models import QuerySet

from catalog.models import Cell
from catalog.serializers import CellSerializer


class Command(BaseCommand):
help = 'Export designated tables in legacy db schema'
help: str = 'Export designated tables in legacy db schema'


def add_arguments(self, parser: CommandParser):
Expand All @@ -15,9 +20,17 @@ def handle(self, *args, **options):
for table in options['tables']:
match table:
case 'Cell':
queryset = Cell.objects.all()
queryset: QuerySet = Cell.objects.all()
no: int = 1
cells: dict[str, dict] = {}
for cell in queryset:
serializer = CellSerializer(cell)
print(serializer.data)
cells[str(no)] = serializer.data
db_file: str = os.path.expanduser('~/NaaVRE/NaaVRE_db.json')
with open(db_file) as f:
db = json.load(f)
db['cells'] = cells
with open(db_file, 'w') as f:
json.dump(db, f)
case _:
raise CommandError(f"Table {table} is not supported")

0 comments on commit 4ab0e59

Please sign in to comment.