feat: add portal app config sync commands

This commit is contained in:
Md Bayazid Bostame
2026-03-29 01:33:50 +01:00
parent 48afccbca3
commit 5697f42306
5 changed files with 340 additions and 0 deletions

View File

@@ -0,0 +1,22 @@
from django.core.management.base import BaseCommand
from workflows.app_registry_sync import export_portal_app_config_payload, write_portal_app_config_export
class Command(BaseCommand):
help = 'Export PortalAppConfig to JSON for environment sync.'
def add_arguments(self, parser):
parser.add_argument('--output', help='Write the export to a file instead of stdout.')
def handle(self, *args, **options):
output = options.get('output')
if output:
path = write_portal_app_config_export(output)
self.stdout.write(self.style.SUCCESS(f'Exported PortalAppConfig to {path}'))
return
payload = export_portal_app_config_payload()
import json
self.stdout.write(json.dumps(payload, indent=2, default=str))

View File

@@ -0,0 +1,25 @@
from django.core.management.base import BaseCommand, CommandError
from workflows.app_registry_sync import import_portal_app_config_payload, load_portal_app_config_payload
class Command(BaseCommand):
help = 'Import PortalAppConfig JSON for environment sync.'
def add_arguments(self, parser):
parser.add_argument('input', help='Path to a previously exported PortalAppConfig JSON file.')
parser.add_argument('--dry-run', action='store_true', help='Validate and report changes without saving.')
def handle(self, *args, **options):
try:
payload = load_portal_app_config_payload(options['input'])
summary = import_portal_app_config_payload(payload, dry_run=options['dry_run'])
except (OSError, ValueError) as exc:
raise CommandError(str(exc)) from exc
mode = 'Dry run' if options['dry_run'] else 'Import'
self.stdout.write(
self.style.SUCCESS(
f"{mode} complete. total={summary['total']} updated={summary['updated']} created={summary['created']}"
)
)