GameServerSupervisor/webpanel/migrations/0013_migrate_port_to_dict.py
Pratyush Desai 87feb8fda6
Improves handling port mapping
switched port field to a JSONField
adds a helper function to display server port mapping in admin
launching a container will map the ports appropriately
Instead of typing json to map ports we have a widget
replaced by such text fields. where one can + button to add or
- to remove
i.e.
 [container_port/proto]:[host_port]
At first port was an IntegerField.
Hence i added a manual migration which is the latest one
to get them  to be default:port(old value)

Signed-off-by: Pratyush Desai <pratyush.desai@liberta.casa>
2025-04-23 03:08:36 +05:30

33 lines
918 B
Python

# Generated by Django 5.1.5 on 2025-04-22 19:57
from django.db import migrations
import json
def migrate_port_to_dict(apps, schema_editor):
Server = apps.get_model("webpanel", "Server")
for gs in Server.objects.all():
port = gs.port
if isinstance(port, int):
gs.port = {"default": port}
gs.save()
elif isinstance(port, str):
try:
parsed = json.loads(port)
if isinstance(parsed, dict):
gs.port = parsed
gs.save()
except json.JSONDecodeError:
# Fallback: store as a default port string
gs.port = {"default": port}
gs.save()
class Migration(migrations.Migration):
dependencies = [
("webpanel", "0012_alter_server_port"),
]
operations = [
migrations.RunPython(migrate_port_to_dict),
]